Trim whitespace from math in --webtex.

This fixes problems with --webtex and markdown output,
when display math starts or ends with a newline.

Closes #7892.
This commit is contained in:
John MacFarlane 2022-02-03 13:21:27 -08:00
parent 9618b66fe8
commit b9ac243986
2 changed files with 14 additions and 8 deletions

View file

@ -1465,13 +1465,15 @@ inlineToHtml opts inline = do
case writerHTMLMathMethod opts of
WebTeX url -> do
let imtag = if html5 then H5.img else H.img
let str' = T.strip str
let s = case t of
InlineMath -> "\\textstyle "
DisplayMath -> "\\displaystyle "
return $ imtag ! A.style "vertical-align:middle"
! A.src (toValue . (url <>) . urlEncode $ s <> str)
! A.alt (toValue str)
! A.title (toValue str)
! A.src (toValue . (url <>) .
urlEncode $ s <> str')
! A.alt (toValue str')
! A.title (toValue str')
! A.class_ mathClass
GladTeX ->
return $

View file

@ -485,8 +485,10 @@ inlineToMarkdown opts (Math InlineMath str) = do
case () of
_ | variant == Markua -> return $ "`" <> literal str <> "`" <> "$"
| otherwise -> case writerHTMLMathMethod opts of
WebTeX url -> inlineToMarkdown opts
(Image nullAttr [Str str] (url <> urlEncode str, str))
WebTeX url ->
let str' = T.strip str
in inlineToMarkdown opts
(Image nullAttr [Str str'] (url <> urlEncode str', str'))
_ | isEnabled Ext_tex_math_dollars opts ->
return $ "$" <> literal str <> "$"
| isEnabled Ext_tex_math_single_backslash opts ->
@ -507,9 +509,11 @@ inlineToMarkdown opts (Math DisplayMath str) = do
return $ blankline <> attributes <> cr <> literal "```" <> cr
<> literal str <> cr <> literal "```" <> blankline
| otherwise -> case writerHTMLMathMethod opts of
WebTeX url -> (\x -> blankline <> x <> blankline) `fmap`
inlineToMarkdown opts (Image nullAttr [Str str]
(url <> urlEncode str, str))
WebTeX url ->
let str' = T.strip str
in (\x -> blankline <> x <> blankline) `fmap`
inlineToMarkdown opts (Image nullAttr [Str str']
(url <> urlEncode str', str'))
_ | isEnabled Ext_tex_math_dollars opts ->
return $ "$$" <> literal str <> "$$"
| isEnabled Ext_tex_math_single_backslash opts ->