aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-11-02 10:36:31 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-11-02 10:36:31 -0700
commitdb972b8ea0537a33312554a557e60303d45bd855 (patch)
tree9970a6645751605c4a3926f41a11528a6c95583f /src/Text/Pandoc/Readers
parent724fd655e79a24b5150f0253325d9653f59e9631 (diff)
downloadpandoc-db972b8ea0537a33312554a557e60303d45bd855.tar.gz
LaTeX reader: parse macro defs as raw latex...
when `latex_macros` is disabled. (When `latex_macros` is enabled, we omit them, since pandoc is applying the macros itself.) Previously, it was documented that the macro definitions got passed through as raw latex regardless of whether `latex_macros` was set -- but in fact they never got passed through.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index b1d8a7432..a8df5dd03 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -128,7 +128,7 @@ rawLaTeXBlock = do
lookAhead (try (char '\\' >> letter))
inp <- getInput
let toks = tokenize "source" $ T.pack inp
- snd <$> (rawLaTeXParser toks False macroDef blocks
+ snd <$> (rawLaTeXParser toks False (macroDef (const mempty)) blocks
<|> (rawLaTeXParser toks True
(do choice (map controlSeq
["include", "input", "subfile", "usepackage"])
@@ -1418,7 +1418,7 @@ inline = (mempty <$ comment)
<|> (space <$ whitespace)
<|> (softbreak <$ endline)
<|> word
- <|> macroDef
+ <|> macroDef (rawInline "latex")
<|> inlineCommand'
<|> inlineEnvironment
<|> inlineGroup
@@ -1464,9 +1464,11 @@ end_ t = try (do
preamble :: PandocMonad m => LP m Blocks
preamble = mempty <$ many preambleBlock
where preambleBlock = spaces1
- <|> void (macroDef <|> blockCommand)
+ <|> macroDef (const ())
+ <|> void blockCommand
<|> void braced
- <|> (notFollowedBy (begin_ "document") >> void anyTok)
+ <|> (do notFollowedBy (begin_ "document")
+ void anyTok)
paragraph :: PandocMonad m => LP m Blocks
paragraph = do
@@ -1532,9 +1534,12 @@ authors = try $ do
egroup
addMeta "author" (map trimInlines auths)
-macroDef :: (Monoid a, PandocMonad m) => LP m a
-macroDef =
- mempty <$ (commandDef <|> environmentDef)
+macroDef :: (PandocMonad m, Monoid a) => (String -> a) -> LP m a
+macroDef constructor = do
+ (_, s) <- withRaw (commandDef <|> environmentDef)
+ (constructor (T.unpack $ untokenize s) <$
+ guardDisabled Ext_latex_macros)
+ <|> return mempty
where commandDef = do
(name, macro') <- newcommand <|> letmacro <|> defmacro
guardDisabled Ext_latex_macros <|>
@@ -2368,7 +2373,7 @@ block :: PandocMonad m => LP m Blocks
block = do
res <- (mempty <$ spaces1)
<|> environment
- <|> macroDef
+ <|> macroDef (rawBlock "latex")
<|> blockCommand
<|> paragraph
<|> grouped block