gnab/remark

skip Markdown parsing in math formulae

Opened this issue · 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?

up?

Seems like this is supported in marked since v0.3.6
UPD: ah, no, it is still unmerged/open (markedjs/marked#722)

jovo commented

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?

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

jovo commented
liuq commented

up, it's mandatory to reuse existing LaTeX code

cben commented

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.

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.

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

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.