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

there is a rendering bug when using brackets #9

Closed
shi-yan opened this issue Oct 2, 2018 · 3 comments
Closed

there is a rendering bug when using brackets #9

shi-yan opened this issue Oct 2, 2018 · 3 comments
Labels

Comments

@shi-yan
Copy link

shi-yan commented Oct 2, 2018

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.

@shi-yan
Copy link
Author

shi-yan commented Nov 11, 2018

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

shi-yan added a commit to shi-yan/markdown-it-texmath that referenced this issue Nov 11, 2018
When using brackets, the current markdown-it-texmath can't render
properly. This change fixes the incorrect regexp.

fix goessner#9
@goessner
Copy link
Owner

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

@goessner goessner added the bug label Nov 12, 2018
shi-yan added a commit to shi-yan/markdown-it-texmath that referenced this issue Dec 31, 2018
There are 2 regexps to match equations contained in brackets,

one is math_block_eqno, the other is math_block,

the first regexp matches equations with an index at the end,

aaaa (1)

the second regexp matches equations without an index

bbbb

the program prioritize the first regexp over the second,

but when multiple equations present with only some of them having

an index. Javascript regexp will greedly match the longest string

that fulfill the first regexp.

For example

bbbb
aaaa (1)

becomes one single equation, instead of 2.

The fix adds a negative lookahead to exclude \\\[ \\\] patterns
from a match.

fix goessner#9
@goessner
Copy link
Owner

goessner commented Feb 7, 2019

@shi-yan

Verified your fix and implemented with version 0.5.5.

Great work, thanks.

@goessner goessner closed this as completed Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants