git.iko.soy/typeable/pandoc
on master help sign in
KaTeX: don't use autorenderer.

We no longer surround formulas with `\(..\)` or `\[..\]` and rely on the autorenderer. Instead, we tell katex to convert the contents of span elements with class "math". Since math has already been identified, this avoids wasted time parsing for LaTeX delimiters. Note, however, that this may yield unexpected results if you have span elements with class "math" that don't contain LaTeX math. Also, use latest version of KaTeX by default (0.9.0). Closes #4946.

commitf766348fd8ca2d619d9d4081d744a331eacdce02 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 4 Oct 2018, 10:04 (8 years ago) parent2caf198
2 files changed+6−6
src/Text/Pandoc/Writers/HTML.hs+5−5 src/Text/Pandoc/Writers/Math.hs+1−1
src/Text/Pandoc/Writers/HTML.hs+5−5
@@ -277,10 +277,10 @@ pandocToHtml opts (Pandoc meta blocks) = do
277277 KaTeX url -> do
278278 H.script !
279279 A.src (toValue $ url ++ "katex.min.js") $ mempty
280− H.script !
281− A.src (toValue $ url ++ "contrib/auto-render.min.js") $ mempty
280+ nl opts
282281 H.script
283− "document.addEventListener(\"DOMContentLoaded\", function() {\n renderMathInElement(document.body);\n});"
282+ "document.addEventListener(\"DOMContentLoaded\", function () {\n var mathElements = document.getElementsByClassName(\"math\");\n for (var i = 0; i < mathElements.length; i++) {\n var texText = mathElements[i].firstChild;\n if (mathElements[i].tagName == \"SPAN\") { katex.render(texText.data, mathElements[i], { displayMode: mathElements[i].classList.contains(\"display\"), throwOnError: false } );\n }}});"
283+ nl opts
284284 H.link ! A.rel "stylesheet" !
285285 A.href (toValue $ url ++ "katex.min.css")
286286
@@ -1065,8 +1065,8 @@ inlineToHtml opts inline = do
10651065 DisplayMath -> "\\[" ++ str ++ "\\]"
10661066 KaTeX _ -> return $ H.span ! A.class_ mathClass $ toHtml $
10671067 case t of
1068− InlineMath -> "\\(" ++ str ++ "\\)"
1069− DisplayMath -> "\\[" ++ str ++ "\\]"
1068+ InlineMath -> str
1069+ DisplayMath -> str
10701070 PlainMath -> do
10711071 x <- lift (texMathToInlines t str) >>= inlineListToHtml opts
10721072 let m = H.span ! A.class_ mathClass $ x
src/Text/Pandoc/Writers/Math.hs+1−1
@@ -55,4 +55,4 @@ defaultMathJaxURL :: String
5555defaultMathJaxURL = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/"
5656
5757defaultKaTeXURL :: String
58−defaultKaTeXURL = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.8.3/"
58+defaultKaTeXURL = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.9.0/"