Issues with the rendering of numbered latex equations
Hello,
I am encountering issues with the rendering of numbered latex equations, such as:
\begin{equation}
x
\end{equation}
I typically simultaneously open my .md file with Marked 2 and with vim. A nice feature of Marked 2 is that, whenever I save anything in the vim file, its Marked 2 preview automatically updates. This works perfectly for me, except for numbered equations like the one above. Here are three issues that I am encountering.
Everything is fine when I open the document with Marked 2: the equation above is displayed with number (1). However,
- every time I make a "save" in vim, with either no change to the document or a change outside of the equation, then the equation is still rendered correctly, but its number increases by 1, i.e. (1) becomes (2), and next time (3), etc.
- If I save any change inside the equation, then the equation is not even rendered anymore: it gets printed in literals instead. Interestingly, this does not happen if I enclose the equation with
$$
signs, as in
$$ \begin{equation} x \end{equation} $$
- If moreover I add a label to my equation, as in
\begin{equation} \label{eq:0} x \end{equation}
$$
signs,) then any new "save" (even without any actual change to the file) will break the equation's rendering.
I would be very happy for any help on these matters!
Thanks in advance and best regards,
CJ
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Brett on 18 Nov, 2020 03:04 PM
Before I start debugging, explain how equation rendering ever works without $$? If there's no delimiter, it shouldn't render as an equation at all. Are you using a custom processor?
Also, have you tested this with both Mathjax and Katex (switch under Style preferences)? Just so I can focus on one or the other, if possible.
- Brett
2 Posted by cjsg on 18 Nov, 2020 03:36 PM
Hello Brett,
thanks for your quick reply.
No idea. It surprised me too. I am not using any custom processor. I am attaching my style and processor preferences and my advanced configuration file for MathJax.
I always use Mathjax. But I just tested with Katex: the equation is never rendered. Katex doesn't seem to be able to parse the environment
Please let me know if I can provide any other information.\begin{equation} ... \end{equation}
(with or without the enclosing$$
signs). As a sanity check, I did however verify that Katex correctly renders the following formula.Thanks a lot for looking into this.
Best,
CJ
Support Staff 3 Posted by Brett on 18 Nov, 2020 03:52 PM
Ok, I still can't explain why it works without `$$`, but I can confirm
it does. However, Marked can't do any of it's normal processing without
the delimiter, so if it doesn't break your normal workflow, you'll have
better results over all if you use it.
As far as the equation numbering goes: since version 2.6 Marked has been
doing dynamic updates of the preview, replacing the content in the DOM
without refreshing the view. When there are equations involved, this
means re-parsing the math blocks live every time the new content is
injected. MathJax apparently stores its counter in a persistent way, so
with every render it's assuming it's the equations on the page are new,
and in addition to the ones it's already processed. A hard refresh
(⌘R) will reset the numbering, but there's not much I can do about the
incrementing during dynamic refreshes. Is it something you can put up
with, just doing a hard refresh prior to creating output?
Thanks,
Brett
4 Posted by cjsg on 18 Nov, 2020 07:45 PM
Ok. I am fine with that.
That's good enough for me. Thanks for your help!
For the record: the hard refresh solves all problems listed above, but only when enclosing the equation with
$$
.Conclusion: always enclose latex equations with the usual mathjax delimiters (
$
,$$
, ...), and hard refresh (⌘R) if something isn't rendered properly.Thanks a lot for your help!
Best regards,
CJ
Support Staff 5 Posted by Brett on 18 Nov, 2020 07:49 PM
Happy to help :)
- Brett