@@ -483,11 +483,9 @@ blockToHtml opts (Div attr@(ident, classes, kvs) bs) = do
483483 else addAttrs opts (ident, classes', kvs) $ divtag $ contents'
484484blockToHtml opts (RawBlock f str)
485485 | f == Format "html" = return $ preEscapedString str
486− | f == Format "latex" =
487− case writerHTMLMathMethod opts of
488− MathJax _ -> do modify (\st -> st{ stMath = True })
489− return $ toHtml str
490− _ -> return mempty
486+ | (f == Format "latex" || f == Format "tex") &&
487+ allowsMathEnvironments (writerHTMLMathMethod opts) &&
488+ isMathEnvironment str = blockToHtml opts $ Plain [Math DisplayMath str]
491489 | otherwise = return mempty
492490blockToHtml opts (HorizontalRule) = return $ if writerHtml5 opts then H5.hr else H.hr
493491blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
@@ -811,13 +809,6 @@ inlineToHtml opts inline =
811809 InlineMath -> m
812810 DisplayMath -> brtag >> m >> brtag
813811 (RawInline f str)
814− | f == Format "latex" ->
815− case writerHTMLMathMethod opts of
816− LaTeXMathML _ -> do modify (\st -> st {stMath = True})
817− return $ toHtml str
818− MathJax _ -> do modify (\st -> st {stMath = True})
819− return $ toHtml str
820− _ -> return mempty
821812 | f == Format "html" -> return $ preEscapedString str
822813 | otherwise -> return mempty
823814 (Link attr txt (s,_)) | "mailto:" `isPrefixOf` s -> do
@@ -915,3 +906,41 @@ renderKaTeX = unlines [
915906 , " katex.render(texText.data, mathElements[i])"
916907 , "}}"
917908 ]
909+
910+isMathEnvironment :: String -> Bool
911+isMathEnvironment s = "\\begin{" `isPrefixOf` s &&
912+ envName `elem` mathmlenvs
913+ where envName = takeWhile (/= '}') (drop 7 s)
914+ mathmlenvs = [ "align"
915+ , "align*"
916+ , "alignat"
917+ , "alignat*"
918+ , "aligned"
919+ , "alignedat"
920+ , "array"
921+ , "Bmatrix"
922+ , "bmatrix"
923+ , "cases"
924+ , "CD"
925+ , "eqnarray"
926+ , "eqnarray*"
927+ , "equation"
928+ , "equation*"
929+ , "gather"
930+ , "gather*"
931+ , "gathered"
932+ , "matrix"
933+ , "multline"
934+ , "multline*"
935+ , "pmatrix"
936+ , "smallmatrix"
937+ , "split"
938+ , "subarray"
939+ , "Vmatrix"
940+ , "vmatrix" ]
941+
942+allowsMathEnvironments :: HTMLMathMethod -> Bool
943+allowsMathEnvironments (MathJax _) = True
944+allowsMathEnvironments (MathML _) = True
945+allowsMathEnvironments (WebTeX _) = True
946+allowsMathEnvironments _ = False