aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-08-17 21:25:14 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-08-17 21:25:14 -0700
commit4ec02053bba3f280b63267c90f2faeafe74d5c64 (patch)
tree630a5a55e703bd684bb3378ea14f7802914ec2a6 /src/Text
parent175da00295da72ae08e23405327f63ba08c3c3a2 (diff)
downloadpandoc-4ec02053bba3f280b63267c90f2faeafe74d5c64.tar.gz
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.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs10
-rw-r--r--src/Text/Pandoc/Writers/Shared.hs6
2 files changed, 10 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index 380374bd6..2055ee1da 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -66,7 +66,8 @@ import Text.Pandoc.Readers.Docx.StyleMap
import Text.Pandoc.Shared hiding (Element)
import Text.Pandoc.Walk
import Text.Pandoc.Writers.Math
-import Text.Pandoc.Writers.Shared (fixDisplayMath, metaValueToInlines)
+import Text.Pandoc.Writers.Shared (isDisplayMath, fixDisplayMath,
+ metaValueToInlines)
import Text.Printf (printf)
import Text.TeXMath
import Text.XML.Light as XML
@@ -915,9 +916,10 @@ blockToOpenXML' opts (Para lst)
| null lst && not (isEnabled Ext_empty_paragraphs opts) = return []
| otherwise = do
isFirstPara <- gets stFirstPara
- paraProps <- getParaProps $ case lst of
- [Math DisplayMath _] -> True
- _ -> False
+ let displayMathPara = case lst of
+ [x] -> isDisplayMath x
+ _ -> False
+ paraProps <- getParaProps displayMathPara
bodyTextStyle <- pStyleM "Body Text"
let paraProps' = case paraProps of
[] | isFirstPara -> [mknode "w:pPr" []
diff --git a/src/Text/Pandoc/Writers/Shared.hs b/src/Text/Pandoc/Writers/Shared.hs
index 2edce7deb..438a35ca4 100644
--- a/src/Text/Pandoc/Writers/Shared.hs
+++ b/src/Text/Pandoc/Writers/Shared.hs
@@ -38,6 +38,7 @@ module Text.Pandoc.Writers.Shared (
, resetField
, defField
, tagWithAttrs
+ , isDisplayMath
, fixDisplayMath
, unsmartify
, gridTable
@@ -187,8 +188,9 @@ tagWithAttrs tag (ident,classes,kvs) = hsep
] <> ">"
isDisplayMath :: Inline -> Bool
-isDisplayMath (Math DisplayMath _) = True
-isDisplayMath _ = False
+isDisplayMath (Math DisplayMath _) = True
+isDisplayMath (Span _ [Math DisplayMath _]) = True
+isDisplayMath _ = False
stripLeadingTrailingSpace :: [Inline] -> [Inline]
stripLeadingTrailingSpace = go . reverse . go . reverse