aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MANUAL.txt4
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs21
2 files changed, 15 insertions, 10 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index fd08ab075..b15f93018 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -4337,8 +4337,8 @@ When `latex_macros` is disabled, the raw LaTeX and math will
not have macros applied. This is usually a better approach when
you are targeting LaTeX or PDF.
-Whether or not `latex_macros` is enabled, the macro definitions
-will still be passed through as raw LaTeX.
+The macro definitions will be passed through as raw LaTeX
+only if `latex_macros` is not enabled.
## Links
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