summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-02-26 22:59:21 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-02-26 22:59:21 -0800
commit6cfd2e8fa9aa755366f2453d2a6e6a9490d67ec1 (patch)
tree2da60ebb375b35810779db3e0f40abc1d9359e99 /src/Text/Pandoc/Writers
parent61958de6c2544e1e595bef4a5cf8f8561a0bf39f (diff)
Docx writer: Better treatment of display math.
Display math inside a paragraph is now put in a separate paragraph, so it will render properly (centered and without extra blank lines around it). Partially addresses #742.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index 39b5a716d..7a782efb6 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Conversion of 'Pandoc' documents to docx.
-}
module Text.Pandoc.Writers.Docx ( writeDocx ) where
-import Data.List ( intercalate )
+import Data.List ( intercalate, groupBy )
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.Map as M
@@ -425,10 +425,16 @@ blockToOpenXML opts (Para [Image alt (src,'f':'i':'g':':':tit)]) = do
captionNode <- withParaProp (pStyle "ImageCaption")
$ blockToOpenXML opts (Para alt)
return $ mknode "w:p" [] (paraProps ++ contents) : captionNode
-blockToOpenXML opts (Para lst) = do
- paraProps <- getParaProps
- contents <- inlinesToOpenXML opts lst
- return [mknode "w:p" [] (paraProps ++ contents)]
+blockToOpenXML opts (Para lst)
+ | any isDisplayMath lst && not (all isDisplayMath lst) = do
+ -- chop into several paragraphs so each displaymath is its own
+ let lsts = groupBy (\x y -> (isDisplayMath x && isDisplayMath y) ||
+ not (isDisplayMath x || isDisplayMath y)) lst
+ blocksToOpenXML opts (map Para lsts)
+ | otherwise = do
+ paraProps <- getParaProps
+ contents <- inlinesToOpenXML opts lst
+ return [mknode "w:p" [] (paraProps ++ contents)]
blockToOpenXML _ (RawBlock format str)
| format == "openxml" = return [ x | Elem x <- parseXML str ]
| otherwise = return []
@@ -629,16 +635,13 @@ inlineToOpenXML opts (Quoted quoteType lst) =
where (open, close) = case quoteType of
SingleQuote -> ("\x2018", "\x2019")
DoubleQuote -> ("\x201C", "\x201D")
-inlineToOpenXML opts (Math InlineMath str) =
- case texMathToOMML DisplayInline str of
+inlineToOpenXML opts (Math mathType str) = do
+ let displayType = if mathType == DisplayMath
+ then DisplayBlock
+ else DisplayInline
+ case texMathToOMML displayType str of
Right r -> return [r]
Left _ -> inlinesToOpenXML opts (readTeXMath str)
-inlineToOpenXML opts (Math DisplayMath str) =
- case texMathToOMML DisplayBlock str of
- Right r -> return [br, r, br]
- Left _ -> do
- fallback <- inlinesToOpenXML opts (readTeXMath str)
- return $ [br] ++ fallback ++ [br]
inlineToOpenXML opts (Cite _ lst) = inlinesToOpenXML opts lst
inlineToOpenXML _ (Code attrs str) =
withTextProp (rStyle "VerbatimChar")
@@ -769,3 +772,6 @@ parseXml refArchive relpath =
Just d -> return d
Nothing -> fail $ relpath ++ " missing in reference docx"
+isDisplayMath :: Inline -> Bool
+isDisplayMath (Math DisplayMath _) = True
+isDisplayMath _ = False