Files
John MacFarlane 0bbbdbcdb6 LaTeX reader/writer: change handling of math environments.
Certain environments in LaTeX will trigger math mode and can't
occur within math mode: e.g., `align` or `equation`.  Previously
we "downshifted" these, parsing an `align` environment as a
Math element with `aligned`, and an `equation` environment as a
regular display math element.  With this shift, we put these in
Math inlines but retain the original environments.

This works because:

1) texmath handles these environments just fine,
2) and so does MathJax;
3) when writing LaTeX we detect these environments in Math elements
   and emit them verbatim instead of putting them in `$..$` or
   `$$..$$`.

Closes #9711. Closes #9296.
2025-08-11 17:40:41 -07:00

2.0 KiB

% pandoc -f markdown+latex_macros -t markdown+raw_tex-raw_attribute
\newcommand{\my}{\phi}
$\my+\my$
^D
\newcommand{\my}{\phi}

$\phi+\phi$
% pandoc -f markdown-latex_macros -t markdown+raw_tex-raw_attribute
\newcommand{\my}{\phi}
$\my+\my$
^D
\newcommand{\my}{\phi}

$\my+\my$

\let macros should be expanded at point of definition, while \newcommand macros should be expanded at point of use:

% pandoc -f latex -t latex
\let\a\b
\def\b{\emph{ouk}}
\a a
^D
a̱
% pandoc -f latex -t latex
\newcommand{\a}{\b}
\newcommand{\b}{\emph{ouk}}
\a a
^D
\emph{ouk}a
% pandoc -f latex -t latex
\def\BDpos{}
\def\BDneg{-}
\def\beq{\begin{align}}
\def\eeq{\end{align}}
\def\e#1{\emph{#1}}
\def\f#1#2{\emph{#1--#2}}

$5\BDneg 6\BDpos 7$

\beq
x &= y\\
\eeq

\e{hi}

\f{hi}{ok}
^D
\(5-67\)

\begin{align}
x &= y\\
\end{align}

\emph{hi}

\emph{hi--ok}
% pandoc -f markdown+latex_macros -t markdown+raw_tex-raw_attribute
\newcommand{\my}{\phi}
\begin{equation}
\my+\my
\end{equation}
^D
\newcommand{\my}{\phi}

\begin{equation}
\phi+\phi
\end{equation}
% pandoc -f markdown-latex_macros -t markdown+raw_tex-raw_attribute
\newcommand{\my}{\phi}
\begin{equation}
\my+\my
\end{equation}
^D
\newcommand{\my}{\phi}

\begin{equation}
\my+\my
\end{equation}
% pandoc -f markdown+latex_macros -t markdown+raw_tex-raw_attribute
\newcommand{\my}{\emph{a}}
\my
^D
\newcommand{\my}{\emph{a}}
\emph{a}

https://tex.stackexchange.com/questions/258/what-is-the-difference-between-let-and-def

% pandoc -f latex -t plain
\def\bar{hello}
\let\fooi\bar
\def\fooii{\bar}
\fooi +\fooii

\def\bar{goodbye}
\fooi +\fooii
^D
hello+hello

hello+goodbye
% pandoc -f latex -t plain
\def\txt{a}
\def\foo{\txt}
\let\bar\foo
\bar % -> a
\def\txt{b}
\bar % -> b
\def\foo{OH}
\bar % -> b
^D
a b b
% pandoc -f latex -t plain
\def\aaa{aaa}
\def\bbb{x\aaa}
\edef\ccc{y\aaa}
\def\aaa{AAA}
\bbb \ccc
^D
xAAAyaaa
% pandoc -f latex -t plain
\gdef\aaa{aaa}
\gdef\bbb{x\aaa}
\xdef\ccc{y\aaa}
\gdef\aaa{AAA}
\bbb \ccc
^D
xAAAyaaa