LaTeX reader: fix bug parsing macro arguments.

If `\cL` is defined as `\mathcal{L}`, and `\til` as `\tilde{#1}`,
then `\til\cL` should expand to `\tilde{\mathcal{L}}`, but pandoc
was expanding it to `\tilde\mathcal{L}`.  This is fixed by
parsing the arguments in "verbatim mode" when the macro expands
arguments at the point of use.

Closes #6796.
This commit is contained in:
John MacFarlane 2020-11-02 15:04:16 -08:00
parent 5760cd850f
commit 6cbe5efd56
2 changed files with 21 additions and 1 deletions

View file

@ -484,7 +484,11 @@ doMacros' n inp =
Nothing -> mzero
Just (Macro expansionPoint argspecs optarg newtoks) -> do
let getargs' = do
args <- case optarg of
args <-
(case expansionPoint of
ExpandWhenUsed -> withVerbatimMode
ExpandWhenDefined -> id)
$ case optarg of
Nothing -> getargs M.empty argspecs
Just o -> do
x <- option o bracketedToks

16
test/command/6796.md Normal file
View file

@ -0,0 +1,16 @@
```
% pandoc -f latex -t markdown
\newcommand{\cL}{\mathcal{L}}
\newcommand{\til}[1]{\tilde{#1}}
$$\til\cL$$
\newcommand{\mc}[1]{\mathcal{#1}}
\newcommand{\dL}{\mc{L}}
$$\til\dL$$
^D
$$\tilde{\mathcal{L}}$$
$$\tilde{\mathcal{L}}$$
```