aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-10-04 10:04:49 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-10-04 10:33:46 -0700
commitf766348fd8ca2d619d9d4081d744a331eacdce02 (patch)
treedebe1324b96d191b4ab8161785a86e8ad50a99d8
parent2caf198b46a4afbe97086136c57228e13fc71a45 (diff)
downloadpandoc-f766348fd8ca2d619d9d4081d744a331eacdce02.tar.gz
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.
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs10
-rw-r--r--src/Text/Pandoc/Writers/Math.hs2
2 files changed, 6 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index 19ec4692e..46f754226 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -277,10 +277,10 @@ pandocToHtml opts (Pandoc meta blocks) = do
KaTeX url -> do
H.script !
A.src (toValue $ url ++ "katex.min.js") $ mempty
- H.script !
- A.src (toValue $ url ++ "contrib/auto-render.min.js") $ mempty
+ nl opts
H.script
- "document.addEventListener(\"DOMContentLoaded\", function() {\n renderMathInElement(document.body);\n});"
+ "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 }}});"
+ nl opts
H.link ! A.rel "stylesheet" !
A.href (toValue $ url ++ "katex.min.css")
@@ -1065,8 +1065,8 @@ inlineToHtml opts inline = do
DisplayMath -> "\\[" ++ str ++ "\\]"
KaTeX _ -> return $ H.span ! A.class_ mathClass $ toHtml $
case t of
- InlineMath -> "\\(" ++ str ++ "\\)"
- DisplayMath -> "\\[" ++ str ++ "\\]"
+ InlineMath -> str
+ DisplayMath -> str
PlainMath -> do
x <- lift (texMathToInlines t str) >>= inlineListToHtml opts
let m = H.span ! A.class_ mathClass $ x
diff --git a/src/Text/Pandoc/Writers/Math.hs b/src/Text/Pandoc/Writers/Math.hs
index 99d17d594..61decf2df 100644
--- a/src/Text/Pandoc/Writers/Math.hs
+++ b/src/Text/Pandoc/Writers/Math.hs
@@ -55,4 +55,4 @@ defaultMathJaxURL :: String
defaultMathJaxURL = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/"
defaultKaTeXURL :: String
-defaultKaTeXURL = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.8.3/"
+defaultKaTeXURL = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.9.0/"