-
Notifications
You must be signed in to change notification settings - Fork 30
Cannot include escaped dollar when using dollars delimiters #32
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
Comments
Unfortunately, regexes won't cut it to fix this problem in full generality, e.g. to support $$ x = \text{what is $x$?} $$ Would you be willing to review a PR that rewrites the parsing engine to count |
hmm ... interesting. Usually I am very reluctant with extending the regexes used in texmath. They are performance critical, as they are evaluated once with each user key stroke. In fact escaped dollar sign Dollar delimiters are special beasts. While having a short look into the
I reidentified the final After testing it in https://regex101.com/ successfully for several relevant cases, I considered it worth for also use it as a guard in the Surprisingly a drastic simplification is helping here ... from
to
Expect it available in the next version. thanks ... |
Erik, thanks for your potential help. If there are some problems with my bug fix attempt, I would like to come back to your PR offer. |
Changing from
But none of this fixes use of One potential fix would be to use the regex as above, and then check whether the closing Alternatively (and what I originally had in mind), the regex could match the opening |
In fact I had temporarily forgotten that '
... as you can see with this example code (https://github.com/goessner/markdown-it-texmath/blob/master/test/bug-dollars.html) const str = `
# Simple Dollar tests
## Inline
here "$a+\\$ = b$" we "$\\$$" go "$\\text{\\$some...\\$}$"
## Inline block (single line only)
$$a+\\$ = \\text{\\$more...\\$} \\$$$ or ...
## Block (multiline)
$$
a+\\$ = \\text{\\$text...\\$} \\$
$$
` To also handle unescaped dollars inside of I hope I have not overlooked anything ... thanks. |
Minor points:
These new rules seem to deal with Nested So it's not possible to escape these instances of Unmatched braces generate errors in KaTeX, though. (I see either |
Sorry for the delay. Thanks for your valuable input.
math_inline should be written on a single line, but I added it to be more forgiving here.
This is definitely better ... taken.
Yes ... thanks for catching.
sure ... done.
yes ... again a significant improvement.
Now I understand that reentering math mode effect. Escaping makes no sense indeed. I still consider it a not so relevant edge case in practise. I don't want to invest that significant implementation effort at current. A PR is always welcome though. thanks again ... |
The regex for dollar delimiters breaks if the content includes an escaped dollar (
\$
), making it impossible to type dollar literals inside math blocks:will all fail to be parsed as a latex block.
Workarounds include using a different delimiter style or use
\text{\textdollar}
, but getting it to work without these would be nice.I've been to update the
math_block
regex from:/\${2}([^$]+?)\${2}/gmy
to/\${2}((?:\\\$|[^$])+?)\${2}/gmy
but it doesn't cover all cases, and I haven't been able to figure out where to start with the
math_inline
regex.The text was updated successfully, but these errors were encountered: