remarkjs/remark-math

How to customize the delimiters?

zwz opened this issue · 7 comments

zwz commented

In README, it says

Some TeX packages and Markdown processors use double dollars, $$, as a inline token. Remark Math will parse it also properly.

That is what I want. And I want more as follows:

$300 is just regular text, just how many $ in my pocket, no math here.
And $$ax^2+bx+c=0$$ shouble be parsed into inline math, while $$
ax^2+bx+c=0
$$
parsed into display math.

I really do not want $ as inline math delimiter. And $$...$$ for inline math and $$\n...\n$$ for display math is good enough.
The benefit is that there is no need to escape $ in regular text for a dollar sign in most cases.

I agree with this completely, for exactly the reason you specified. It's too easy for someone to accidentally trigger LaTeX with single dollar signs, especially if it's in the larger context of Markdown formatting where a much greater portion of users are completely unaware of LaTeX while a small number need to use it. A user who doesn't even know about LaTeX isn't going to know about escaping dollar signs.

I do think that the current behavior is fine as a default, but it would be great if we had an option to disable single dollar signs from the parser. I'll actually look into making this change since I don't really want to push this out to my users as is.

zwz commented

Nice!
But what to denote inline math and display math respectively, after disabling single dollar sign?

And $$...$$ for inline math and $$\n...\n$$ for display math is good enough.

That should be sufficient, no? It already works like that without any changes.

zwz commented

Great!

skyl commented

I struggled a bit with this same problem.

I have $80 and I want $100!

$$
  \rho \left( \frac{\partial \vec{u}}{\partial t} + (\vec{u} \cdot \nabla) \vec{u} \right) = -\nabla p + \mu \nabla^2 \vec{u} + \rho \vec{g}
$$

But, sometimes I want to do inline like $$\infty$$.

If someone else comes across this issue trying to figure it out, I discovered that remark-math has an option, singleDollarTextMath so something like:

import remarkMath, { Options } from "remark-math"
import rehypeMathjaxSvg from "rehype-mathjax/svg"

const remarkMathOptions: Options = {
    singleDollarTextMath: false,
}

// ...
            remarkPlugins={[
                [remarkMath, remarkMathOptions],
            ]}
            rehypePlugins={[
                rehypeMathjaxSvg,
            ]}

@skyl I noticed when I disable singleDollarTextMath then the block math doesn't work and I get

Error: [next-mdx-remote] error compiling MDX:
Cannot read properties of undefined (reading 'mathFlowInside')

the mkdown is

`
  $$
  \\frac{r_{test}^3}{T_{test}^2}
  $$
  `

If I enable it and remove the extra $ then block math works again.
Did someone figure out how to fix this?

Raise a new question. Your question is different. Our question forms guide you through providing more info. Which is needed to answer it.

Locking because this is solved and more comments don’t solve it more.