From f4185fcef0aa5c00e37a1bf8bbc8b8c6459fffe7 Mon Sep 17 00:00:00 2001 From: Lila Date: Tue, 19 May 2020 07:45:44 +0200 Subject: Use CSS in favor of
for display math (#6372) Some CSS to ensure that display math is displayed centered and on a new line is now included in the default HTML-based templates; this may be overridden if the user wants a different behavior. --- data/templates/styles.html | 3 +++ src/Text/Pandoc/Writers/HTML.hs | 23 ++++++++++------------- test/command/5655.md | 4 ++-- test/lhs-test.html | 1 + test/lhs-test.html+lhs | 1 + test/s5-basic.html | 1 + test/s5-inserts.html | 1 + test/writer.html4 | 3 ++- test/writer.html5 | 3 ++- 9 files changed, 23 insertions(+), 17 deletions(-) diff --git a/data/templates/styles.html b/data/templates/styles.html index 34cd4de89..ea92c39ec 100644 --- a/data/templates/styles.html +++ b/data/templates/styles.html @@ -10,3 +10,6 @@ $endif$ $if(highlighting-css)$ $highlighting-css$ $endif$ +$if(displaymath-css)$ +.display.math{display: block; text-align: center; margin: 0.5rem auto;} +$endif$ diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 1f0ee5410..dbda5067f 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -318,6 +318,10 @@ pandocToHtml opts (Pandoc meta blocks) = do defField "mathjaxurl" (T.takeWhile (/='?') u) _ -> defField "mathjax" False) $ + (case writerHTMLMathMethod opts of + PlainMath -> defField "displaymath-css" True + WebTeX _ -> defField "displaymath-css" True + _ -> id) $ defField "quotes" (stQuotes st) $ -- for backwards compatibility we populate toc -- with the contents of the toc, rather than a @@ -1108,14 +1112,11 @@ inlineToHtml opts inline = do let s = case t of InlineMath -> "\\textstyle " DisplayMath -> "\\displaystyle " - let m = imtag ! A.style "vertical-align:middle" - ! A.src (toValue $ url <> T.pack (urlEncode (T.unpack $ s <> str))) - ! A.alt (toValue str) - ! A.title (toValue str) - let brtag = if html5 then H5.br else H.br - return $ case t of - InlineMath -> m - DisplayMath -> brtag >> m >> brtag + return $ imtag ! A.style "vertical-align:middle" + ! A.src (toValue $ url <> T.pack (urlEncode (T.unpack $ s <> str))) + ! A.alt (toValue str) + ! A.title (toValue str) + ! A.class_ mathClass GladTeX -> return $ customParent (textTag "eq") ! @@ -1142,11 +1143,7 @@ inlineToHtml opts inline = do DisplayMath -> str PlainMath -> do x <- lift (texMathToInlines t str) >>= inlineListToHtml opts - let m = H.span ! A.class_ mathClass $ x - let brtag = if html5 then H5.br else H.br - return $ case t of - InlineMath -> m - DisplayMath -> brtag >> m >> brtag + return $ H.span ! A.class_ mathClass $ x (RawInline f str) -> do ishtml <- isRawHtml f if ishtml diff --git a/test/command/5655.md b/test/command/5655.md index 35987c10a..692009562 100644 --- a/test/command/5655.md +++ b/test/command/5655.md @@ -2,13 +2,13 @@ % pandoc --webtex $T_n={n+1 \choose 2}$ ^D -

T_n={n+1 \choose 2}

+

T_n={n+1 \choose 2}

```` ```` % pandoc --webtex $$T_n={n+1 \choose 2}$$ ^D -


T_n={n+1 \choose 2}

+

T_n={n+1 \choose 2}

```` diff --git a/test/lhs-test.html b/test/lhs-test.html index 8ec8e5dd9..621d79163 100644 --- a/test/lhs-test.html +++ b/test/lhs-test.html @@ -74,6 +74,7 @@ code span.va { color: #19177c; } /* Variable */ code span.vs { color: #4070a0; } /* VerbatimString */ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */ + .display.math{display: block; text-align: center; margin: 0.5rem auto;} diff --git a/test/s5-inserts.html b/test/s5-inserts.html index 2574715d3..1df9dd018 100644 --- a/test/s5-inserts.html +++ b/test/s5-inserts.html @@ -15,6 +15,7 @@ div.column{display: inline-block; vertical-align: top; width: 50%;} div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} ul.task-list{list-style: none;} + .display.math{display: block; text-align: center; margin: 0.5rem auto;} STUFF INSERTED diff --git a/test/writer.html4 b/test/writer.html4 index 80106bd56..56b78dfb1 100644 --- a/test/writer.html4 +++ b/test/writer.html4 @@ -15,6 +15,7 @@ div.column{display: inline-block; vertical-align: top; width: 50%;} div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} ul.task-list{list-style: none;} + .display.math{display: block; text-align: center; margin: 0.5rem auto;} @@ -432,7 +433,7 @@ Blah
  • α ∧ ω
  • 223
  • p-Tree
  • -
  • Here’s some display math:
    $$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$$
  • +
  • Here’s some display math: $$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$$
  • Here’s one that has a line break in it: α + ω × x2.
  • These shouldn’t be math:

    diff --git a/test/writer.html5 b/test/writer.html5 index 431503b03..321b65afd 100644 --- a/test/writer.html5 +++ b/test/writer.html5 @@ -15,6 +15,7 @@ div.column{display: inline-block; vertical-align: top; width: 50%;} div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} ul.task-list{list-style: none;} + .display.math{display: block; text-align: center; margin: 0.5rem auto;}