@@ -48,11 +48,12 @@ import Data.Char (isSpace, toLower)
48type Refs = [([Inline], Target)]
48type Refs = [([Inline], Target)]
50data WriterState =
50data WriterState =
51− WriterState { stNotes :: [[Block]]
51+ WriterState { stNotes :: [[Block]]
52− , stLinks :: Refs
52+ , stLinks :: Refs
53− , stImages :: [([Inline], (String, String, Maybe String))]
53+ , stImages :: [([Inline], (String, String, Maybe String))]
54− , stHasMath :: Bool
54+ , stHasMath :: Bool
55+ , stHasRawTeX :: Bool
55− , stOptions :: WriterOptions
56+ , stOptions :: WriterOptions
58-- | Convert Pandoc to RST.
59-- | Convert Pandoc to RST.
@@ -60,7 +61,7 @@ writeRST :: WriterOptions -> Pandoc -> String
60writeRST opts document =
61writeRST opts document =
61 let st = WriterState { stNotes = [], stLinks = [],
62 let st = WriterState { stNotes = [], stLinks = [],
62 stImages = [], stHasMath = False,
63 stImages = [], stHasMath = False,
63− stOptions = opts }
64+ stHasRawTeX = False, stOptions = opts }
64 in evalState (pandocToRST document) st
65 in evalState (pandocToRST document) st
66-- | Return RST representation of document.
67-- | Return RST representation of document.
@@ -84,6 +85,7 @@ pandocToRST (Pandoc meta blocks) = do
84 refs <- liftM (reverse . stLinks) get >>= refsToRST
85 refs <- liftM (reverse . stLinks) get >>= refsToRST
85 pics <- liftM (reverse . stImages) get >>= pictRefsToRST
86 pics <- liftM (reverse . stImages) get >>= pictRefsToRST
86 hasMath <- liftM stHasMath get
87 hasMath <- liftM stHasMath get
88+ rawTeX <- liftM stHasRawTeX get
87 let main = render colwidth $ foldl ($+$) empty $ [body, notes, refs, pics]
89 let main = render colwidth $ foldl ($+$) empty $ [body, notes, refs, pics]
88 let context = defField "body" main
90 let context = defField "body" main
89 $ defField "toc" (writerTableOfContents opts)
91 $ defField "toc" (writerTableOfContents opts)
@@ -91,6 +93,7 @@ pandocToRST (Pandoc meta blocks) = do
91 $ defField "math" hasMath
93 $ defField "math" hasMath
92 $ defField "title" (render Nothing title :: String)
94 $ defField "title" (render Nothing title :: String)
93 $ defField "math" hasMath
95 $ defField "math" hasMath
96+ $ defField "rawtex" rawTeX
94 $ metadata
97 $ metadata
95 if writerStandalone opts
98 if writerStandalone opts
96 then return $ renderTemplate' (writerTemplate opts) context
99 then return $ renderTemplate' (writerTemplate opts) context
@@ -392,6 +395,9 @@ inlineToRST (Math t str) = do
392 else blankline $$ (".. math:: " <> text str) $$ blankline
395 else blankline $$ (".. math:: " <> text str) $$ blankline
393inlineToRST (RawInline f x)
396inlineToRST (RawInline f x)
394 | f == "rst" = return $ text x
397 | f == "rst" = return $ text x
398+ | f == "latex" || f == "tex" = do
399+ modify $ \st -> st{ stHasRawTeX = True }
400+ return $ ":raw-latex:`" <> text x <> "`"
395 | otherwise = return empty
401 | otherwise = return empty
396inlineToRST (LineBreak) = return cr -- there's no line break in RST (see Para)
402inlineToRST (LineBreak) = return cr -- there's no line break in RST (see Para)
397inlineToRST Space = return space
403inlineToRST Space = return space