aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-05-30 12:48:07 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-05-30 12:49:01 -0700
commit7119715a6af7d04d17e40bb76e901c11bf27d3f3 (patch)
tree5fa69e6150a44dec263de27f2bcea8629e822a30 /src/Text
parent0dbbf16c3ab4d158499fecfb171080a448be65c5 (diff)
downloadpandoc-7119715a6af7d04d17e40bb76e901c11bf27d3f3.tar.gz
LaTeX reader `rawLaTeXBlock`: handle macros that resolve to a...
...`\begin` or `\end`. Fixes #4667.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 2fdb3d43c..fff628c46 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -286,7 +286,23 @@ rawLaTeXBlock :: (PandocMonad m, HasMacros s, HasReaderOptions s)
rawLaTeXBlock = do
lookAhead (try (char '\\' >> letter))
snd <$> (rawLaTeXParser False macroDef blocks
- <|> rawLaTeXParser True(environment <|> macroDef <|> blockCommand) blocks)
+ <|> rawLaTeXParser True
+ (environment <|> macroDef <|> blockCommand)
+ (mconcat <$> (many (block <|> beginOrEndCommand))))
+
+-- See #4667 for motivation; sometimes people write macros
+-- that just evaluate to a begin or end command, which blockCommand
+-- won't accept.
+beginOrEndCommand :: PandocMonad m => LP m Blocks
+beginOrEndCommand = try $ do
+ Tok _ (CtrlSeq name) txt <- anyControlSeq
+ guard $ name == "begin" || name == "end"
+ (envname, rawargs) <- withRaw braced
+ if M.member (untokenize envname)
+ (inlineEnvironments :: M.Map Text (LP PandocPure Inlines))
+ then mzero
+ else return $ rawBlock "latex"
+ (T.unpack (txt <> untokenize rawargs))
rawLaTeXInline :: (PandocMonad m, HasMacros s, HasReaderOptions s)
=> ParserT String s m String