beautifulhugo icon indicating copy to clipboard operation
beautifulhugo copied to clipboard

LaTeX does not render when selfHosted

Open pmeckoni opened this issue 3 years ago • 3 comments

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

pmeckoni avatar Jun 01 '21 17:06 pmeckoni

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:

  1. KaTeX from CDN needs to be upgraded.
  2. KaTeX on selfHosted needs to be upgraded.
  3. Consider moving from KaTeX to MathJax.

pmeckoni avatar Jun 02 '21 04:06 pmeckoni

rendered by MathJax 3 rendered by KaTeX I tested this with Firefox on Xubuntu but KaTeX was a bit faster.

VincentTam avatar Jun 05 '22 14:06 VincentTam

Yes KaTeX is faster. MathJax is more complete. Perhaps one way out is to provide both and let users to choose KaTeX or MathJax

pmeckoni avatar Jun 05 '22 17:06 pmeckoni