paolobrasolin / jekyll-antex

Use arbitrary LaTeX in your Jekyll website!
https://paolobrasolin.github.io/jekyll-antex/
MIT License
2 stars 0 forks source link

Environments need double \\ to compile #11

Closed tetrapharmakon closed 5 years ago

tetrapharmakon commented 6 years ago
\begin{tikzcd}
A & B \\
C & D
\end{tikzcd}

does not work. You need to write

\begin{tikzcd}
A & B \\\\
C & D
\end{tikzcd}
paolobrasolin commented 5 years ago

Ok, so after scouring the code of both Jekyll, Liquid and Kramdown I found the culprit: me. https://github.com/paolobrasolin/jekyll-antex/blob/974d68b2afdb36383fa0e60f9a99dfaaf8577721/lib/jekyll/antex/dealiaser.rb#L51

Concretely, what happens is

'x'.sub('x', "\\\\")
# => "\\"

WAT

Why? Because https://stackoverflow.com/a/4149087

The problem is that when using sub (and gsub), without a block, ruby interprets special character sequences in the replacement parameter. Unfortunately, sub uses the backslash as the escape character for these:

\& (the entire regex)
\+ (the last group)
\` (pre-match string)
\' (post-match string)
\0 (same as \&)
\1 (first captured group)
\2 (second captured group)
\\ (a backslash)

In fact,

'x'.sub('x') { "\\\\" }
# => "\\\\"

Will fix soon.