LaTeX reader: pass through macro defs in rawLaTeXBlock...

even if the `latex_macros` extension is set.
This reverts to earlier behavior and is probably safer
on the whole, since some macros only modify things in
included packages, which pandoc's macro expansion can't
modify.

Closes #4246.
This commit is contained in:
John MacFarlane 2018-01-13 22:12:32 -08:00
parent 485535464d
commit e7d95cadf5
4 changed files with 8 additions and 5 deletions

View file

@ -272,10 +272,8 @@ rawLaTeXBlock = do
lookAhead (try (char '\\' >> letter)) lookAhead (try (char '\\' >> letter))
-- we don't want to apply newly defined latex macros to their own -- we don't want to apply newly defined latex macros to their own
-- definitions: -- definitions:
(do (_, raw) <- rawLaTeXParser macroDef (snd <$> rawLaTeXParser macroDef)
(guardDisabled Ext_latex_macros >> return raw) <|> return "") <|> ((snd <$> rawLaTeXParser (environment <|> blockCommand)) >>= applyMacros)
<|> (do (_, raw) <- rawLaTeXParser (environment <|> blockCommand)
applyMacros raw)
rawLaTeXInline :: (PandocMonad m, HasMacros s, HasReaderOptions s) rawLaTeXInline :: (PandocMonad m, HasMacros s, HasReaderOptions s)
=> ParserT String s m String => ParserT String s m String

View file

@ -3,5 +3,6 @@
\newcommand{\gen}{a\ Gen\ b} \newcommand{\gen}{a\ Gen\ b}
abc abc
^D ^D
[Para [Str "abc"]] [RawBlock (Format "latex") "\\newcommand{\\gen}{a\\ Gen\\ b}"
,Para [Str "abc"]]
``` ```

View file

@ -3,6 +3,7 @@
\newcommand{\my}{\phi} \newcommand{\my}{\phi}
$\my+\my$ $\my+\my$
^D ^D
\newcommand{\my}{\phi}
$\phi+\phi$ $\phi+\phi$
``` ```
@ -73,6 +74,7 @@ x &= y\\\end{aligned}\]
\my+\my \my+\my
\end{equation} \end{equation}
^D ^D
\newcommand{\my}{\phi}
\begin{equation} \begin{equation}
\phi+\phi \phi+\phi
\end{equation} \end{equation}
@ -96,5 +98,6 @@ x &= y\\\end{aligned}\]
\newcommand{\my}{\emph{a}} \newcommand{\my}{\emph{a}}
\my \my
^D ^D
\newcommand{\my}{\emph{a}}
\emph{a} \emph{a}
``` ```

View file

@ -54,6 +54,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "Author",S
,OrderedList (3,Example,TwoParens) ,OrderedList (3,Example,TwoParens)
[[Plain [Str "Third",Space,Str "example."]]] [[Plain [Str "Third",Space,Str "example."]]]
,Header 2 ("macros",[],[]) [Str "Macros"] ,Header 2 ("macros",[],[]) [Str "Macros"]
,RawBlock (Format "latex") "\\newcommand{\\tuple}[1]{\\langle #1 \\rangle}"
,Para [Math InlineMath "\\langle x,y \\rangle"] ,Para [Math InlineMath "\\langle x,y \\rangle"]
,Header 2 ("case-insensitive-references",[],[]) [Str "Case-insensitive",Space,Str "references"] ,Header 2 ("case-insensitive-references",[],[]) [Str "Case-insensitive",Space,Str "references"]
,Para [Link ("",[],[]) [Str "Fum"] ("/fum","")] ,Para [Link ("",[],[]) [Str "Fum"] ("/fum","")]