remark icon indicating copy to clipboard operation
remark copied to clipboard

skip Markdown parsing in math formulae

Open anaderi opened this issue 8 years ago • 10 comments

Hi,

I have a couple of formulae that I render with Katex:

$\dfrac{ F_s }{ F_b }$

$\dfrac{ F_s ( x_{event} ) }{ F_b }$

results are quite different:

obviously in the second case underscores are parsed by MD, and it can be fixed by manual escape of underscores by , but it's a bit ugly.

Is it possible to skip Markdown parsing within math formulae?

anaderi avatar May 29 '16 10:05 anaderi

up?

anaderi avatar Nov 04 '16 15:11 anaderi

Seems like this is supported in marked since v0.3.6 UPD: ah, no, it is still unmerged/open (https://github.com/chjj/marked/issues/722)

anaderi avatar Nov 06 '16 09:11 anaderi

i have the same problem. i don't understand the comment

it can be fixed by manual escape of underscores by , but it's a bit ugly.

perhaps @anaderi can explain?

jovo avatar Aug 17 '17 02:08 jovo

It means you can replace every usage of _ with \_. SO UGLLLYYYYYYYYYYYY

wookayin avatar Aug 17 '17 02:08 wookayin

i see. that worked, though is a bit tedious....

On Wed, Aug 16, 2017 at 8:35 PM, Jongwook Choi [email protected] wrote:

It means you can replace every usage of _ with _.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/gnab/remark/issues/336#issuecomment-322952816, or mute the thread https://github.com/notifications/unsubscribe-auth/AACjch7OydA9NkdgovyFHSduQhZR8ifaks5sY6cCgaJpZM4IpQmo .

-- the glass is all full: half water, half air. neurodata.io ps - i am committed to responding to every email i receive, it often takes about a week. thank you for understanding.

jovo avatar Aug 23 '17 05:08 jovo

up, it's mandatory to reuse existing LaTeX code

liuq avatar Nov 09 '17 10:11 liuq

Perhaps try switching to kramed, a fork of marked with some changes, including proper math support. It uses kramdown math syntax — $$ delimeters for both inline and display math (https://github.com/GitbookIO/kramed/blob/master/test/tests/math.text).

Or, consider using a literal-based math syntax such as Gitlab. (see https://github.com/cben/mathdown/wiki/math-in-markdown#Gitlab for that and various other syntaxes). Literals can pass through any parser, keeping you free to use any markdown parser that fits your goals and simply handle math as post-processing, without bugs like this.

cben avatar May 22 '18 09:05 cben

I recently encountered this issue and decided to fix it. It's a bit of a hack because this is not really an issue with remark; it's an issue with marked, the markdown parser that remark depends on. The issue is further complicated by the fact that remark uses an old release of marked, and there have been many breaking changes (to marked) since the old release that remark depends on.

I forked an old release of marked and made the necessary changes to allow math passthrough. I also updated my fork of remark to use my fork of marked. I know this is a bit hacky, but this is the best solution I could come up with for now. Hope this helps.

yuekai avatar Aug 28 '19 18:08 yuekai

Is there any progress with this? This is perhaps the turning point for me to use remark fulltime. With lots of copying of latex equations, escaping underscores is not 2 way compatible with standard latex

isentropic avatar Sep 08 '20 04:09 isentropic

Here's another imperfect workaround:

I'm using remark with KaTeX and Jekyll (via github pages).

In the Jekyll template, instead of using {{page.content}}, I use {{page.content | replace: "_", "\_" }}

This means that the original equations are preserved in the markdown source, and Jekyll does the replacement while building the html files.

The downside is that all underscores are replaced with this method.

RMWinslow avatar May 09 '23 20:05 RMWinslow