goessner/markdown-it-texmath

there is a rendering bug when using brackets

shi-yan opened this issue · 3 comments

the following markdown can't be rendered correctly:

        md.markdown = '# Triangle \n\
\n\
Let the right triangle hypothenuse be aligned with the coordinate system *x-axis*. \n\
The vector loop closure equation then reads\n\
\n\
\\[a{\\bold e}_\\alpha + b\\tilde{\\bold e}_\\alpha + c{\\bold e}_x = \\bold 0\\] (1)\n\
\n\
with\n\
\n\
\\[{\\bold e}_\\alpha = \\begin{pmatrix}\\cos\\alpha\\\\ \\sin\\alpha\\end{pmatrix} \\quad and \\quad {\\tilde\\bold e}_\\alpha = \\begin{pmatrix}-\\sin\\alpha\\\\ \\cos\\alpha\\end{pmatrix}\\]\n\
\n\
Resolving for the hypothenuse part \\(c{\\bold e}_x\\) in the loop closure equation (1) \n\
\n\
\\[-c{\\bold e}_x = a{\\bold e}_\\alpha + b\\tilde{\\bold e}_\\alpha\\] (2)\n\
\n\
and squaring \n\
\n\
finally results in the Pythagorean theorem (2)\n\
\n\
\\[ c^2 = a^2 + b^2 \\] (3)'

but using the $ $$ syntax would work.

test.zip

attach an example that reproduces the issue. I don't understand what you meant by the following regexp in your texmath.js

[\s\S]+?

changing the above to

.+? solved my problem

Surprise ... after having added TeX macros to texmath I wanted to verify your issue.

  • I could reproduce it.
  • I also detected the block rule regex as the root of the evil.

The I suddenly saw, that you were also working on a solution for that issue at the same time.

To your question first:
.+? detects any character on a single line only. [\s\S]+? does the same for multiple lines, which in fact we need here. See.

Now bad news is: I even tried your suggested fix, but had no success with it.
The regular expressions are working formally very well, which you can verify here. But they simply refuse to work inside of texmath. I am quite clueless now.

I added a bug test file bug-brackets.html for your issue in the test folder, for coming back to it in future.

Sorry & thanks

@shi-yan

Verified your fix and implemented with version 0.5.5.

Great work, thanks.