diff options
-rw-r--r-- | pandoc.cabal | 2 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/HTML.hs | 53 | ||||
-rw-r--r-- | stack.yaml | 1 |
3 files changed, 43 insertions, 13 deletions
diff --git a/pandoc.cabal b/pandoc.cabal index 5620182f8..496600ac7 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -260,7 +260,7 @@ Library text >= 0.11 && < 1.3, zip-archive >= 0.2.3.4 && < 0.4, HTTP >= 4000.0.5 && < 4000.4, - texmath >= 0.8.6.2 && < 0.9, + texmath >= 0.8.6.4 && < 0.9, xml >= 1.3.12 && < 1.4, random >= 1 && < 1.2, extensible-exceptions >= 0.1 && < 0.2, diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index d8b8384e7..433e28bf2 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -483,11 +483,9 @@ blockToHtml opts (Div attr@(ident, classes, kvs) bs) = do else addAttrs opts (ident, classes', kvs) $ divtag $ contents' blockToHtml opts (RawBlock f str) | f == Format "html" = return $ preEscapedString str - | f == Format "latex" = - case writerHTMLMathMethod opts of - MathJax _ -> do modify (\st -> st{ stMath = True }) - return $ toHtml str - _ -> return mempty + | (f == Format "latex" || f == Format "tex") && + allowsMathEnvironments (writerHTMLMathMethod opts) && + isMathEnvironment str = blockToHtml opts $ Plain [Math DisplayMath str] | otherwise = return mempty blockToHtml opts (HorizontalRule) = return $ if writerHtml5 opts then H5.hr else H.hr blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do @@ -811,13 +809,6 @@ inlineToHtml opts inline = InlineMath -> m DisplayMath -> brtag >> m >> brtag (RawInline f str) - | f == Format "latex" -> - case writerHTMLMathMethod opts of - LaTeXMathML _ -> do modify (\st -> st {stMath = True}) - return $ toHtml str - MathJax _ -> do modify (\st -> st {stMath = True}) - return $ toHtml str - _ -> return mempty | f == Format "html" -> return $ preEscapedString str | otherwise -> return mempty (Link attr txt (s,_)) | "mailto:" `isPrefixOf` s -> do @@ -915,3 +906,41 @@ renderKaTeX = unlines [ , " katex.render(texText.data, mathElements[i])" , "}}" ] + +isMathEnvironment :: String -> Bool +isMathEnvironment s = "\\begin{" `isPrefixOf` s && + envName `elem` mathmlenvs + where envName = takeWhile (/= '}') (drop 7 s) + mathmlenvs = [ "align" + , "align*" + , "alignat" + , "alignat*" + , "aligned" + , "alignedat" + , "array" + , "Bmatrix" + , "bmatrix" + , "cases" + , "CD" + , "eqnarray" + , "eqnarray*" + , "equation" + , "equation*" + , "gather" + , "gather*" + , "gathered" + , "matrix" + , "multline" + , "multline*" + , "pmatrix" + , "smallmatrix" + , "split" + , "subarray" + , "Vmatrix" + , "vmatrix" ] + +allowsMathEnvironments :: HTMLMathMethod -> Bool +allowsMathEnvironments (MathJax _) = True +allowsMathEnvironments (MathML _) = True +allowsMathEnvironments (WebTeX _) = True +allowsMathEnvironments _ = False diff --git a/stack.yaml b/stack.yaml index a8a71f47e..37b361d44 100644 --- a/stack.yaml +++ b/stack.yaml @@ -10,4 +10,5 @@ packages: extra-deps: - data-default-0.6.0 - data-default-instances-base-0.1.0 +- texmath-0.8.6.4 resolver: lts-6.1 |