Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jiewuza opened this issue Mar 10, 2018 · 10 comments · May be fixed by #3926
Closed

Comments

@jiewuza
Copy link

jiewuza commented Mar 10, 2018

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"

@jiewuza jiewuza changed the title Is it possible to config delimiters when the right $ is followed immediately by digits, it will not be treated as a closing delimiter? Is it possible to config $ as delimiters only when it is not followed immediately by a word of digits? Mar 10, 2018
@edemaine
Copy link
Member

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 $.

@ronkok
Copy link
Collaborator

ronkok commented Mar 10, 2018

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.

@jiewuza
Copy link
Author

jiewuza commented Mar 11, 2018

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

@jiewuza
Copy link
Author

jiewuza commented Mar 15, 2018

@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.

@ylemkimon
Copy link
Member

ylemkimon commented Mar 16, 2018

Related: #437

@jiewuza
Copy link
Author

jiewuza commented Mar 19, 2018

@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.

@kevinbarabash
Copy link
Member

@jiewuza I would try:

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

and see if that helps.

@jiewuza
Copy link
Author

jiewuza commented Apr 6, 2018

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

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

@kevinbarabash
Copy link
Member

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.

@kevinbarabash
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants