marko icon indicating copy to clipboard operation
marko copied to clipboard

Losing double backslashes, used with mathjax

Open sradc opened this issue 1 year ago • 0 comments

Hey, thanks for this library!

I've come accross an issue where double backslashes are lost. Losing the \\ is causing newlines to be lost in MathJax rendering.

Minimal example to recreate:

example.md

Example markdown

$$
y_k = [x_0, x_1,... x_{N-1}]
\begin{bmatrix}
    \exp(0)\\
    \exp(-i\frac{2 \pi k}{N})\\
    \exp(-i\frac{2 \pi k}{N}2)\\
    \exp(-i\frac{2 \pi k}{N}3)\\
    \exp(-i\frac{2 \pi k}{N}4)\\
    \vdots \\
    \exp(-i\frac{2 \pi k}{N}(N-1))
\end{bmatrix}
$$

convert.py

import marko
from pathlib import Path

infile = Path("example.md")
out = Path("example.html")
out.write_text(marko.convert(infile.read_text()))

example.html

<p>$$
y_k = [x_0, x_1,... x_{N-1}]
\begin{bmatrix}
\exp(0)\
\exp(-i\frac{2 \pi k}{N})\
\exp(-i\frac{2 \pi k}{N}2)\
\exp(-i\frac{2 \pi k}{N}3)\
\exp(-i\frac{2 \pi k}{N}4)\
\vdots \
\exp(-i\frac{2 \pi k}{N}(N-1))
\end{bmatrix}
$$</p>

^- notice that there's now only single backslashes at the end of the lines.


Edit: Hmm, cmark does the same thing..

But I think the \\ notation works with GH pages. Not sure what I'm missing.


Edit: found pandoc preserves the double backslashes.

sradc avatar Jul 29 '22 18:07 sradc