git.iko.soy/typeable/pandoc
on master help sign in
RST writer: better handling of raw latex inline.

We use `` :raw-latex:`...` `` and add a definition for this role to the template. Closes #1961.

commit28497d484e85fd495e92f06416f978763f333518 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 7 Apr 2015, 22:05 (12 years ago) parentca6a8d6
3 files changed+18−8
data/templates+1−1 src/Text/Pandoc/Writers/RST.hs+12−6 tests/writer.rst+5−1
data/templates+1−1

Submodule changed.

src/Text/Pandoc/Writers/RST.hs+12−6
@@ -48,11 +48,12 @@ import Data.Char (isSpace, toLower)
4848type Refs = [([Inline], Target)]
4949
5050data WriterState =
51− WriterState { stNotes :: [[Block]]
52− , stLinks :: Refs
53− , stImages :: [([Inline], (String, String, Maybe String))]
54− , stHasMath :: Bool
55− , stOptions :: WriterOptions
51+ WriterState { stNotes :: [[Block]]
52+ , stLinks :: Refs
53+ , stImages :: [([Inline], (String, String, Maybe String))]
54+ , stHasMath :: Bool
55+ , stHasRawTeX :: Bool
56+ , stOptions :: WriterOptions
5657 }
5758
5859-- | Convert Pandoc to RST.
@@ -60,7 +61,7 @@ writeRST :: WriterOptions -> Pandoc -> String
6061writeRST opts document =
6162 let st = WriterState { stNotes = [], stLinks = [],
6263 stImages = [], stHasMath = False,
63− stOptions = opts }
64+ stHasRawTeX = False, stOptions = opts }
6465 in evalState (pandocToRST document) st
6566
6667-- | Return RST representation of document.
@@ -84,6 +85,7 @@ pandocToRST (Pandoc meta blocks) = do
8485 refs <- liftM (reverse . stLinks) get >>= refsToRST
8586 pics <- liftM (reverse . stImages) get >>= pictRefsToRST
8687 hasMath <- liftM stHasMath get
88+ rawTeX <- liftM stHasRawTeX get
8789 let main = render colwidth $ foldl ($+$) empty $ [body, notes, refs, pics]
8890 let context = defField "body" main
8991 $ defField "toc" (writerTableOfContents opts)
@@ -91,6 +93,7 @@ pandocToRST (Pandoc meta blocks) = do
9193 $ defField "math" hasMath
9294 $ defField "title" (render Nothing title :: String)
9395 $ defField "math" hasMath
96+ $ defField "rawtex" rawTeX
9497 $ metadata
9598 if writerStandalone opts
9699 then return $ renderTemplate' (writerTemplate opts) context
@@ -392,6 +395,9 @@ inlineToRST (Math t str) = do
392395 else blankline $$ (".. math:: " <> text str) $$ blankline
393396inlineToRST (RawInline f x)
394397 | f == "rst" = return $ text x
398+ | f == "latex" || f == "tex" = do
399+ modify $ \st -> st{ stHasRawTeX = True }
400+ return $ ":raw-latex:`" <> text x <> "`"
395401 | otherwise = return empty
396402inlineToRST (LineBreak) = return cr -- there's no line break in RST (see Para)
397403inlineToRST Space = return space
tests/writer.rst+5−1
@@ -10,6 +10,10 @@ Pandoc Test Suite
1010 :format: html latex
1111..
1212
13+.. role:: raw-latex(raw)
14+ :format: latex
15+..
16+
1317This is a set of tests for pandoc. Most of them are adapted from John Gruber’s
1418markdown test suite.
1519
@@ -657,7 +661,7 @@ Ellipses…and…and….
657661LaTeX
658662=====
659663
660−-
664+- :raw-latex:`\cite[22-23]{smith.1899}`
661665- :math:`2+2=4`
662666- :math:`x \in y`
663667- :math:`\alpha \wedge \omega`