@@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29Conversion of 'Pandoc' documents to docx.
29Conversion of 'Pandoc' documents to docx.
31module Text.Pandoc.Writers.Docx ( writeDocx ) where
31module Text.Pandoc.Writers.Docx ( writeDocx ) where
32−import Data.List ( intercalate )
32+import Data.List ( intercalate, groupBy )
33import qualified Data.ByteString as B
33import qualified Data.ByteString as B
34import qualified Data.ByteString.Lazy as BL
34import qualified Data.ByteString.Lazy as BL
35import qualified Data.Map as M
35import qualified Data.Map as M
@@ -425,10 +425,16 @@ blockToOpenXML opts (Para [Image alt (src,'f':'i':'g':':':tit)]) = do
425 captionNode <- withParaProp (pStyle "ImageCaption")
425 captionNode <- withParaProp (pStyle "ImageCaption")
426 $ blockToOpenXML opts (Para alt)
426 $ blockToOpenXML opts (Para alt)
427 return $ mknode "w:p" [] (paraProps ++ contents) : captionNode
427 return $ mknode "w:p" [] (paraProps ++ contents) : captionNode
428−blockToOpenXML opts (Para lst) = do
428+blockToOpenXML opts (Para lst)
429+ | any isDisplayMath lst && not (all isDisplayMath lst) = do
430+ -- chop into several paragraphs so each displaymath is its own
431+ let lsts = groupBy (\x y -> (isDisplayMath x && isDisplayMath y) ||
432+ not (isDisplayMath x || isDisplayMath y)) lst
433+ blocksToOpenXML opts (map Para lsts)
429− paraProps <- getParaProps
435+ paraProps <- getParaProps
430− contents <- inlinesToOpenXML opts lst
436+ contents <- inlinesToOpenXML opts lst
431− return [mknode "w:p" [] (paraProps ++ contents)]
437+ return [mknode "w:p" [] (paraProps ++ contents)]
432blockToOpenXML _ (RawBlock format str)
438blockToOpenXML _ (RawBlock format str)
433 | format == "openxml" = return [ x | Elem x <- parseXML str ]
439 | format == "openxml" = return [ x | Elem x <- parseXML str ]
434 | otherwise = return []
440 | otherwise = return []
@@ -629,16 +635,13 @@ inlineToOpenXML opts (Quoted quoteType lst) =
629 where (open, close) = case quoteType of
635 where (open, close) = case quoteType of
630 SingleQuote -> ("\x2018", "\x2019")
636 SingleQuote -> ("\x2018", "\x2019")
631 DoubleQuote -> ("\x201C", "\x201D")
637 DoubleQuote -> ("\x201C", "\x201D")
632−inlineToOpenXML opts (Math InlineMath str) =
638+inlineToOpenXML opts (Math mathType str) = do
639+ let displayType = if mathType == DisplayMath
633− case texMathToOMML DisplayInline str of
642+ case texMathToOMML displayType str of
634 Right r -> return [r]
643 Right r -> return [r]
635 Left _ -> inlinesToOpenXML opts (readTeXMath str)
644 Left _ -> inlinesToOpenXML opts (readTeXMath str)
636−inlineToOpenXML opts (Math DisplayMath str) =
637− case texMathToOMML DisplayBlock str of
638− Right r -> return [br, r, br]
640− fallback <- inlinesToOpenXML opts (readTeXMath str)
641− return $ [br] ++ fallback ++ [br]
642inlineToOpenXML opts (Cite _ lst) = inlinesToOpenXML opts lst
645inlineToOpenXML opts (Cite _ lst) = inlinesToOpenXML opts lst
643inlineToOpenXML _ (Code attrs str) =
646inlineToOpenXML _ (Code attrs str) =
644 withTextProp (rStyle "VerbatimChar")
647 withTextProp (rStyle "VerbatimChar")
@@ -769,3 +772,6 @@ parseXml refArchive relpath =
769 Just d -> return d
772 Just d -> return d
770 Nothing -> fail $ relpath ++ " missing in reference docx"
773 Nothing -> fail $ relpath ++ " missing in reference docx"
775+isDisplayMath :: Inline -> Bool
776+isDisplayMath (Math DisplayMath _) = True
777+isDisplayMath _ = False