@@ -45,6 +45,7 @@ import Text.Pandoc.Shared hiding (Element)
45import Text.Pandoc.Options
45import Text.Pandoc.Options
46import Text.Pandoc.Readers.TeXMath
46import Text.Pandoc.Readers.TeXMath
47import Text.Pandoc.Highlighting ( highlight )
47import Text.Pandoc.Highlighting ( highlight )
48+import Text.Pandoc.Walk
48import Text.Highlighting.Kate.Types ()
49import Text.Highlighting.Kate.Types ()
49import Text.XML.Light
50import Text.XML.Light
50import Text.TeXMath
51import Text.TeXMath
@@ -108,7 +109,7 @@ writeDocx :: WriterOptions -- ^ Writer options
108 -> IO BL.ByteString
109 -> IO BL.ByteString
109writeDocx opts doc@(Pandoc meta _) = do
110writeDocx opts doc@(Pandoc meta _) = do
110 let datadir = writerUserDataDir opts
111 let datadir = writerUserDataDir opts
111− let doc' = bottomUp (concatMap fixDisplayMath) doc
112+ let doc' = walk fixDisplayMath doc
112 refArchive <- liftM (toArchive . toLazy) $
113 refArchive <- liftM (toArchive . toLazy) $
113 case writerReferenceDocx opts of
114 case writerReferenceDocx opts of
114 Just f -> B.readFile f
115 Just f -> B.readFile f
@@ -810,17 +811,17 @@ stripLeadingTrailingSpace = go . reverse . go . reverse
810 where go (Space:xs) = xs
811 where go (Space:xs) = xs
811 go xs = xs
812 go xs = xs
813−fixDisplayMath :: Block -> [Block]
814+fixDisplayMath :: Block -> Block
814fixDisplayMath (Plain lst)
815fixDisplayMath (Plain lst)
815 | any isDisplayMath lst && not (all isDisplayMath lst) =
816 | any isDisplayMath lst && not (all isDisplayMath lst) =
816 -- chop into several paragraphs so each displaymath is its own
817 -- chop into several paragraphs so each displaymath is its own
817− map (Plain . stripLeadingTrailingSpace) $
818+ Div ("",["math"],[]) $ map (Plain . stripLeadingTrailingSpace) $
818 groupBy (\x y -> (isDisplayMath x && isDisplayMath y) ||
819 groupBy (\x y -> (isDisplayMath x && isDisplayMath y) ||
819 not (isDisplayMath x || isDisplayMath y)) lst
820 not (isDisplayMath x || isDisplayMath y)) lst
820fixDisplayMath (Para lst)
821fixDisplayMath (Para lst)
821 | any isDisplayMath lst && not (all isDisplayMath lst) =
822 | any isDisplayMath lst && not (all isDisplayMath lst) =
822 -- chop into several paragraphs so each displaymath is its own
823 -- chop into several paragraphs so each displaymath is its own
823− map (Para . stripLeadingTrailingSpace) $
824+ Div ("",["math"],[]) $ map (Para . stripLeadingTrailingSpace) $
824 groupBy (\x y -> (isDisplayMath x && isDisplayMath y) ||
825 groupBy (\x y -> (isDisplayMath x && isDisplayMath y) ||
825 not (isDisplayMath x || isDisplayMath y)) lst
826 not (isDisplayMath x || isDisplayMath y)) lst
826−fixDisplayMath x = [x]
827+fixDisplayMath x = x