git.iko.soy/typeable/pandoc
on master help sign in
Docx writer: properly handle display math in spans.

Closes #4826. This isn't a complete solution, since other nestings of display math may still cause problems, but it should work for what is by far the most common case. Note that this also involves an API change: `isDisplayMath` is now exported from Text.Pandoc.Writers.Shared.

commit4ec02053bba3f280b63267c90f2faeafe74d5c64 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 17 Aug 2018, 21:25 (8 years ago) parent175da00
2 files changed+10−6
src/Text/Pandoc/Writers/Docx.hs+6−4 src/Text/Pandoc/Writers/Shared.hs+4−2
src/Text/Pandoc/Writers/Docx.hs+6−4
@@ -66,7 +66,8 @@ import Text.Pandoc.Readers.Docx.StyleMap
6666import Text.Pandoc.Shared hiding (Element)
6767import Text.Pandoc.Walk
6868import Text.Pandoc.Writers.Math
69−import Text.Pandoc.Writers.Shared (fixDisplayMath, metaValueToInlines)
69+import Text.Pandoc.Writers.Shared (isDisplayMath, fixDisplayMath,
70+ metaValueToInlines)
7071import Text.Printf (printf)
7172import Text.TeXMath
7273import Text.XML.Light as XML
@@ -915,9 +916,10 @@ blockToOpenXML' opts (Para lst)
915916 | null lst && not (isEnabled Ext_empty_paragraphs opts) = return []
916917 | otherwise = do
917918 isFirstPara <- gets stFirstPara
918− paraProps <- getParaProps $ case lst of
919− [Math DisplayMath _] -> True
920− _ -> False
919+ let displayMathPara = case lst of
920+ [x] -> isDisplayMath x
921+ _ -> False
922+ paraProps <- getParaProps displayMathPara
921923 bodyTextStyle <- pStyleM "Body Text"
922924 let paraProps' = case paraProps of
923925 [] | isFirstPara -> [mknode "w:pPr" []
src/Text/Pandoc/Writers/Shared.hs+4−2
@@ -38,6 +38,7 @@ module Text.Pandoc.Writers.Shared (
3838 , resetField
3939 , defField
4040 , tagWithAttrs
41+ , isDisplayMath
4142 , fixDisplayMath
4243 , unsmartify
4344 , gridTable
@@ -187,8 +188,9 @@ tagWithAttrs tag (ident,classes,kvs) = hsep
187188 ] <> ">"
188189
189190isDisplayMath :: Inline -> Bool
190−isDisplayMath (Math DisplayMath _) = True
191−isDisplayMath _ = False
191+isDisplayMath (Math DisplayMath _) = True
192+isDisplayMath (Span _ [Math DisplayMath _]) = True
193+isDisplayMath _ = False
192194
193195stripLeadingTrailingSpace :: [Inline] -> [Inline]
194196stripLeadingTrailingSpace = go . reverse . go . reverse