@@ -483,11 +483,9 @@ blockToHtml opts (Div attr@(ident, classes, kvs) bs) = do
483 else addAttrs opts (ident, classes', kvs) $ divtag $ contents'
483 else addAttrs opts (ident, classes', kvs) $ divtag $ contents'
484blockToHtml opts (RawBlock f str)
484blockToHtml opts (RawBlock f str)
485 | f == Format "html" = return $ preEscapedString str
485 | f == Format "html" = return $ preEscapedString str
486− | f == Format "latex" =
486+ | (f == Format "latex" || f == Format "tex") &&
487− case writerHTMLMathMethod opts of
487+ allowsMathEnvironments (writerHTMLMathMethod opts) &&
488− MathJax _ -> do modify (\st -> st{ stMath = True })
488+ isMathEnvironment str = blockToHtml opts $ Plain [Math DisplayMath str]
491 | otherwise = return mempty
489 | otherwise = return mempty
492blockToHtml opts (HorizontalRule) = return $ if writerHtml5 opts then H5.hr else H.hr
490blockToHtml opts (HorizontalRule) = return $ if writerHtml5 opts then H5.hr else H.hr
493blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
491blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
@@ -811,13 +809,6 @@ inlineToHtml opts inline =
811 InlineMath -> m
809 InlineMath -> m
812 DisplayMath -> brtag >> m >> brtag
810 DisplayMath -> brtag >> m >> brtag
813 (RawInline f str)
811 (RawInline f str)
814− | f == Format "latex" ->
815− case writerHTMLMathMethod opts of
816− LaTeXMathML _ -> do modify (\st -> st {stMath = True})
818− MathJax _ -> do modify (\st -> st {stMath = True})
821 | f == Format "html" -> return $ preEscapedString str
812 | f == Format "html" -> return $ preEscapedString str
822 | otherwise -> return mempty
813 | otherwise -> return mempty
823 (Link attr txt (s,_)) | "mailto:" `isPrefixOf` s -> do
814 (Link attr txt (s,_)) | "mailto:" `isPrefixOf` s -> do
@@ -915,3 +906,41 @@ renderKaTeX = unlines [
915 , " katex.render(texText.data, mathElements[i])"
906 , " katex.render(texText.data, mathElements[i])"
910+isMathEnvironment :: String -> Bool
911+isMathEnvironment s = "\\begin{" `isPrefixOf` s &&
912+ envName `elem` mathmlenvs
913+ where envName = takeWhile (/= '}') (drop 7 s)
914+ mathmlenvs = [ "align"
942+allowsMathEnvironments :: HTMLMathMethod -> Bool
943+allowsMathEnvironments (MathJax _) = True
944+allowsMathEnvironments (MathML _) = True
945+allowsMathEnvironments (WebTeX _) = True
946+allowsMathEnvironments _ = False