# Issues with the rendering of numbered latex equations

#### cjsg

18 Nov, 2020 01:56 PM

Hello,

I am encountering issues with the rendering of numbered latex equations, such as:

$$x$$

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,

1. 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.
2. 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 $$
$$x$$
$$  3. If moreover I add a label to my equation, as in $$\label{eq:0} x$$  , (with or without the $$ 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

1. Support Staff 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. 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?

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.

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.

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 $$...$$ (with or without the enclosing $$ signs). As a sanity check, I did however verify that Katex correctly renders the following formula. $$
x
$$  Please let me know if I can provide any other information. Thanks a lot for looking into this. Best, CJ 3. Support Staff 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

if it doesn't break your normal workflow, you'll have better results over all if you use it [$$]. Ok. I am fine with that. 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? 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

5. Support Staff Posted by Brett on 18 Nov, 2020 07:49 PM

Happy to help :)

- Brett

Comments are currently closed for this discussion. You can start a new one.

# Keyboard shortcuts

### Generic

? Show this help Blurs the current field

### Comment Form

r Focus the comment reply box Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

## Recent Discussions

 26 Nov, 2020 05:14 PM Marked 2 Scrivener Preview stoped working after Big Sur update 21 Nov, 2020 10:12 PM Big Sur Citeproc: error running Preprocessor 18 Nov, 2020 07:49 PM Issues with the rendering of numbered latex equations 15 Nov, 2020 08:22 PM Markdown from Ulysses Rendered Improperly 13 Nov, 2020 05:51 PM Bear - marked 2 preview is disabled

## Recent Articles

 Using Ulysses with Marked Fenced code blocks inside indented code blocks Using JavaScript in Marked Custom CSS: Writing custom CSS for Marked License code has already been utilized