Katex: Is it possible to config $ as delimiters only when it is not followed immediately by a word of digits?

Created on 10 Mar 2018  路  10Comments  路  Source: KaTeX/KaTeX

Usually we use $ as dollar sign as $20, it is followed immediately by digits.
So if we can config both the left and the right $ as delimiter only when it is not followed immediately by a word of digits, we are freely to mix Katex math with dollar sign in most cases,
i.e. "Here is the math $2x^3$, .... $30 is enough"

Most helpful comment

Pandoc's tex_math_dollars extension treats $...$ with just a bit more nuance. Reference. If we change the autorender contrib plug in, maybe we should follow its lead.

All 10 comments

It would be easy to tweak the autorender contrib plug in to do this, but I don't think most users would want it to work this way.

Personally I'd rather have \$ ignored by autorender.

The simplest thing would be to modify the delimiters supplied to autorender to use something other than a single $.

Pandoc's tex_math_dollars extension treats $...$ with just a bit more nuance. Reference. If we change the autorender contrib plug in, maybe we should follow its lead.

@ronkok I brought up the issue after I read Pandoc's tex_math_dollars.

@edemaine I read the code of the autorender contrib plug.
It seems that the delimiters are located by string comparison (not by regexp) when splitting the text.

The point I brought up the issue is that it is obscure for users to input a dollar sign when using $ as delimiters. For instance, instead of
Here is the math $2x^3$, .... $30 is enough
users have to input
Here is the math $2x^3$, .... $\$$30 is enough
or
Here is the math $2x^3$, .... $\$30$ is enough

Using something other than a single $ is a fair option, but I'd rather keep it compatible with LaTex.

Related: #437

@ylemkimon That is exactly what I ask for.
Now I came up with a config:

delimiters: [
    {left: '$$\n', right: '\n$$', display: true},
    {left: '$$', right: '$$', display: false}
  ]

The idea behind is that $$ is seldom seen in regular text, and
$$
math stuff
$$
as display math is visually easy to memorize/use.

But it does not work. For example

test $$ax^2$$
and then $$
ax^2
$$

The inline math on the first line is not recognized as math, because the right delimiter which is followed by a \n is treated as the left delimiter of display math.
If you append some text on the first line, it renders perfectly.

I think it may be a bug, for the right delimiter should be paired first before it be recognized as a left one.

@jiewuza I would try:

delimiters: [
    {left: '$$', right: '$$', display: false},
    {left: '$$\n', right: '\n$$', display: true}
  ]

and see if that helps.

@kevinbarabash
I tried. Both are treated as inline math in this case.

test $$ax^2$$
and then $$
ax^2
$$

I see. Yeah, that's a tough problem. I don't think there's a clean way to solve the problem by simply defining different delimiters. You'll probably want to write your auto-render code. I would probably just use \(/\) and \[/\] or something like that.

I'm going to close this since it's going to be very difficult to implement something that handles the different behaviors people want. Also, there is a workaround by using different delimiters.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pyramation picture pyramation  路  4Comments

shaunc picture shaunc  路  4Comments

OisinMoran picture OisinMoran  路  4Comments

msridhar picture msridhar  路  3Comments

yawnoc picture yawnoc  路  3Comments