git.iko.soy/typeable/pandoc
on master help sign in
KaTeX fixes:

* In Options.HTMLMathMethod, the KaTeX contsructor now takes only one string (for the KaTeX base URL), rather than two [API change]. * The default URL has been updated to the latest version. * The autoload script is now loaded by default.

commit23eaf2a74f686f0af95544047020bff5fcb6ab4f authorJohn MacFarlane <jgm@berkeley.edu> dateThu 5 Oct 2017, 10:08 (9 years ago) parent12f8efe
5 files changed+22−44
MANUAL.txt+1−1 src/Text/Pandoc/App.hs+4−22 src/Text/Pandoc/Options.hs+1−1 src/Text/Pandoc/Writers/HTML.hs+15−19 src/Text/Pandoc/Writers/Math.hs+1−1
MANUAL.txt+1−1
@@ -1116,7 +1116,7 @@ Math rendering in HTML
11161116`--katex`[`=`*URL*]
11171117
11181118: Use [KaTeX] to display embedded TeX math in HTML output.
1119− The *URL* should point to the `katex.js` load script. If a *URL* is
1119+ The *URL* is the base URL for the KaTeX library. If a *URL* is
11201120 not provided, a link to the KaTeX CDN will be inserted.
11211121 Note: [KaTeX] seems to work best with `html5` output.
11221122
src/Text/Pandoc/App.hs+4−22
@@ -183,13 +183,6 @@ convertWithOpts opts = do
183183 Nothing -> return Nothing
184184 Just fp -> Just <$> UTF8.readFile fp
185185
186− let mathMethod =
187− case (optKaTeXJS opts, optKaTeXStylesheet opts) of
188− (Nothing, _) -> optHTMLMathMethod opts
189− (Just js, ss) -> KaTeX js (fromMaybe
190− (defaultKaTeXURL ++ "katex.min.css") ss)
191−
192−
193186 -- --bibliography implies -F pandoc-citeproc for backwards compatibility:
194187 let needsCiteproc = isJust (lookup "bibliography" (optMetadata opts)) &&
195188 optCiteMethod opts `notElem` [Natbib, Biblatex] &&
@@ -368,7 +361,7 @@ convertWithOpts opts = do
368361 maybe return (addStringAsVariable "epub-cover-image")
369362 (optEpubCoverImage opts)
370363 >>=
371− (\vars -> case mathMethod of
364+ (\vars -> case optHTMLMathMethod opts of
372365 LaTeXMathML Nothing -> do
373366 s <- UTF8.toString <$> readDataFile "LaTeXMathML.js"
374367 return $ ("mathml-script", s) : vars
@@ -428,7 +421,7 @@ convertWithOpts opts = do
428421 , writerVariables = variables
429422 , writerTabStop = optTabStop opts
430423 , writerTableOfContents = optTableOfContents opts
431− , writerHTMLMathMethod = mathMethod
424+ , writerHTMLMathMethod = optHTMLMathMethod opts
432425 , writerIncremental = optIncremental opts
433426 , writerCiteMethod = optCiteMethod opts
434427 , writerNumberSections = optNumberSections opts
@@ -642,8 +635,6 @@ data Opt = Opt
642635 , optExtractMedia :: Maybe FilePath -- ^ Path to extract embedded media
643636 , optTrackChanges :: TrackChanges -- ^ Accept or reject MS Word track-changes.
644637 , optFileScope :: Bool -- ^ Parse input files before combining
645− , optKaTeXStylesheet :: Maybe String -- ^ Path to stylesheet for KaTeX
646− , optKaTeXJS :: Maybe String -- ^ Path to js file for KaTeX
647638 , optTitlePrefix :: Maybe String -- ^ Prefix for title
648639 , optCss :: [FilePath] -- ^ CSS files to link to
649640 , optIncludeBeforeBody :: [FilePath] -- ^ Files to include before
@@ -719,8 +710,6 @@ defaultOpts = Opt
719710 , optExtractMedia = Nothing
720711 , optTrackChanges = AcceptChanges
721712 , optFileScope = False
722− , optKaTeXStylesheet = Nothing
723− , optKaTeXJS = Nothing
724713 , optTitlePrefix = Nothing
725714 , optCss = []
726715 , optIncludeBeforeBody = []
@@ -1455,18 +1444,11 @@ options =
14551444 (OptArg
14561445 (\arg opt ->
14571446 return opt
1458− { optKaTeXJS =
1459− arg <|> Just (defaultKaTeXURL ++ "katex.min.js")})
1447+ { optHTMLMathMethod = KaTeX $
1448+ fromMaybe defaultKaTeXURL arg })
14601449 "URL")
14611450 "" -- Use KaTeX for HTML Math
14621451
1463− , Option "" ["katex-stylesheet"]
1464− (ReqArg
1465− (\arg opt ->
1466− return opt { optKaTeXStylesheet = Just arg })
1467− "URL")
1468− "" -- Set the KaTeX Stylesheet location
1469−
14701452 , Option "" ["gladtex"]
14711453 (NoArg
14721454 (\opt -> return opt { optHTMLMathMethod = GladTeX }))
src/Text/Pandoc/Options.hs+1−1
@@ -107,7 +107,7 @@ data HTMLMathMethod = PlainMath
107107 | WebTeX String -- url of TeX->image script.
108108 | MathML
109109 | MathJax String -- url of MathJax.js
110− | KaTeX String String -- url of stylesheet and katex.js
110+ | KaTeX String -- url of KaTeX files
111111 deriving (Show, Read, Eq, Data, Typeable, Generic)
112112
113113instance ToJSON HTMLMathMethod where
src/Text/Pandoc/Writers/HTML.hs+15−19
@@ -268,10 +268,17 @@ pandocToHtml opts (Pandoc meta blocks) = do
268268 H.script ! A.src (toValue url)
269269 ! A.type_ "text/javascript"
270270 $ mempty
271− KaTeX js css ->
272− (H.script ! A.src (toValue js) $ mempty) <>
273− (H.link ! A.rel "stylesheet" ! A.href (toValue css)) <>
274− (H.script ! A.type_ "text/javascript" $ toHtml renderKaTeX)
271+ KaTeX url ->
272+ (H.script !
273+ A.src (toValue $ url ++ "katex.min.js") $ mempty) <>
274+ (H.script !
275+ A.src (toValue $ url ++ "contrib/auto-render.min.js")
276+ $ mempty) <>
277+ (H.script $
278+ "document.addEventListener(\"DOMContentLoaded\", function() {\n renderMathInElement(document.body);\n});") <>
279+ (H.link ! A.rel "stylesheet" !
280+ A.href (toValue $ url ++ "katex.min.css"))
281+
275282 _ -> case lookup "mathml-script" (writerVariables opts) of
276283 Just s | not (stHtml5 st) ->
277284 H.script ! A.type_ "text/javascript"
@@ -1009,10 +1016,10 @@ inlineToHtml opts inline = do
10091016 case t of
10101017 InlineMath -> "\\(" ++ str ++ "\\)"
10111018 DisplayMath -> "\\[" ++ str ++ "\\]"
1012− KaTeX _ _ -> return $ H.span ! A.class_ mathClass $
1013− toHtml (case t of
1014− InlineMath -> str
1015− DisplayMath -> "\\displaystyle " ++ str)
1019+ KaTeX _ -> return $ H.span ! A.class_ mathClass $ toHtml $
1020+ case t of
1021+ InlineMath -> "\\(" ++ str ++ "\\)"
1022+ DisplayMath -> "\\[" ++ str ++ "\\]"
10161023 PlainMath -> do
10171024 x <- lift (texMathToInlines t str) >>= inlineListToHtml opts
10181025 let m = H.span ! A.class_ mathClass $ x
@@ -1133,17 +1140,6 @@ blockListToNote opts ref blocks =
11331140 _ -> noteItem
11341141 return $ nl opts >> noteItem'
11351142
1136−-- Javascript snippet to render all KaTeX elements
1137−renderKaTeX :: String
1138−renderKaTeX = unlines [
1139− "window.onload = function(){var mathElements = document.getElementsByClassName(\"math\");"
1140− , "for (var i=0; i < mathElements.length; i++)"
1141− , "{"
1142− , " var texText = mathElements[i].firstChild"
1143− , " katex.render(texText.data, mathElements[i])"
1144− , "}}"
1145− ]
1146−
11471143isMathEnvironment :: String -> Bool
11481144isMathEnvironment s = "\\begin{" `isPrefixOf` s &&
11491145 envName `elem` mathmlenvs
src/Text/Pandoc/Writers/Math.hs+1−1
@@ -53,4 +53,4 @@ defaultMathJaxURL :: String
5353defaultMathJaxURL = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/"
5454
5555defaultKaTeXURL :: String
56−defaultKaTeXURL = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/"
56+defaultKaTeXURL = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.8.3/"