beautifulhugo
beautifulhugo copied to clipboard
LaTeX does not render when selfHosted
When I use \(\LaTeX\)
, it does not render and instead gives an error in the browser console inspector when we use the selfHosted option.
[Params]
selfHosted = true
However everything works well when I use
[Params]
selfHosted = false
The error is
KaTeX auto-render: Failed to parse ` \LaTeX` with ParseError: KaTeX parse error: Expected 'EOF', got '\LaTeX' at position 2: \̲L̲a̲T̲e̲X̲
a http://localhost:1313/js/katex.min.js:1
expect http://localhost:1313/js/katex.min.js:1
parseInput http://localhost:1313/js/katex.min.js:1
parse http://localhost:1313/js/katex.min.js:1
i http://localhost:1313/js/katex.min.js:4
o http://localhost:1313/js/katex.min.js:1
i http://localhost:1313/js/auto-render.min.js:1
o http://localhost:1313/js/auto-render.min.js:1
o http://localhost:1313/js/auto-render.min.js:1
o http://localhost:1313/js/auto-render.min.js:1
o http://localhost:1313/js/auto-render.min.js:1
o http://localhost:1313/js/auto-render.min.js:1
o http://localhost:1313/js/auto-render.min.js:1
d http://localhost:1313/js/auto-render.min.js:1
<anonymous> http://localhost:1313/post/adding-notes/:386
auto-render.min.js:1:1334
i http://localhost:1313/js/auto-render.min.js:1
o http://localhost:1313/js/auto-render.min.js:1
o http://localhost:1313/js/auto-render.min.js:1
o http://localhost:1313/js/auto-render.min.js:1
o http://localhost:1313/js/auto-render.min.js:1
o http://localhost:1313/js/auto-render.min.js:1
o http://localhost:1313/js/auto-render.min.js:1
d http://localhost:1313/js/auto-render.min.js:1
<anonymous> http://localhost:1313/post/adding-notes/:386
Additionally, I found that other latex environments also don't work (like the below sample doesn't work):
\begin{align}
x &= y
\end{align}
I found the problem is related to the old version of KaTeX. The version available in layouts/partials/footer.html
is referring to 0.10.0 which was released in 2018. The current KaTeX version is 0.13.11.
While upgrading to the latest version of KaTeX may be a solution, please try to move from KaTeX to MathJax. MathJax 2.x is superior to KaTeX, though slower. When MathJax 3 is completely released, we expect it to be faster than KaTeX. source.
So summarizing the issue:
- KaTeX from CDN needs to be upgraded.
- KaTeX on
selfHosted
needs to be upgraded. - Consider moving from KaTeX to MathJax.
I tested this with Firefox on Xubuntu but KaTeX was a bit faster.
Yes KaTeX is faster. MathJax is more complete. Perhaps one way out is to provide both and let users to choose KaTeX or MathJax