git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader `rawLaTeXBlock`: handle macros that resolve to a...

...`\begin` or `\end`. Fixes #4667.

commit7119715a6af7d04d17e40bb76e901c11bf27d3f3 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 30 May 2018, 12:48 (8 years ago) parent0dbbf16
2 files changed+37−1
src/Text/Pandoc/Readers/LaTeX.hs+17−1 test/command/4667.md+20
src/Text/Pandoc/Readers/LaTeX.hs+17−1
@@ -286,7 +286,23 @@ rawLaTeXBlock :: (PandocMonad m, HasMacros s, HasReaderOptions s)
286286rawLaTeXBlock = do
287287 lookAhead (try (char '\\' >> letter))
288288 snd <$> (rawLaTeXParser False macroDef blocks
289− <|> rawLaTeXParser True(environment <|> macroDef <|> blockCommand) blocks)
289+ <|> rawLaTeXParser True
290+ (environment <|> macroDef <|> blockCommand)
291+ (mconcat <$> (many (block <|> beginOrEndCommand))))
292+
293+-- See #4667 for motivation; sometimes people write macros
294+-- that just evaluate to a begin or end command, which blockCommand
295+-- won't accept.
296+beginOrEndCommand :: PandocMonad m => LP m Blocks
297+beginOrEndCommand = try $ do
298+ Tok _ (CtrlSeq name) txt <- anyControlSeq
299+ guard $ name == "begin" || name == "end"
300+ (envname, rawargs) <- withRaw braced
301+ if M.member (untokenize envname)
302+ (inlineEnvironments :: M.Map Text (LP PandocPure Inlines))
303+ then mzero
304+ else return $ rawBlock "latex"
305+ (T.unpack (txt <> untokenize rawargs))
290306
291307rawLaTeXInline :: (PandocMonad m, HasMacros s, HasReaderOptions s)
292308 => ParserT String s m String
test/command/4667.mdnew file+20
@@ -0,0 +1,20 @@
1+```
2+pandoc -t latex
3+---
4+header-includes:
5+- \newcommand{\blandscape}{\begin{landscape}}
6+- \newcommand{\elandscape}{\end{landscape}}
7+...
8+
9+\blandscape
10+
11+testing
12+
13+\elandscape
14+^D
15+\begin{landscape}
16+
17+testing
18+
19+\end{landscape}
20+```