Skip to content

Enable latex_macros for output writers #9677

Closed
@asmaier

Description

@asmaier

At the moment the extension latex_macros can only be activated for input readers (https://pandoc.org/MANUAL.html#latex-macros). As far as I can see it is active by default e.g. for markdown and latex. However when converting the following test.tex

\documentclass[12pt,a4paper,twoside]{book}
\usepackage[intlimits]{amsmath}	

% brackets
\newcommand{\lra}[1]{ \left( #1 \right) }
\newcommand{\lrb}[1]{ \left[ #1 \right] }
\newcommand{\lrc}[1]{ \left\{ #1 \right\} }

\begin{document}

Lorem ipsum dolor sit amet.

\begin{align}
a & = \lra{b + c} \label{eq2} \\
c & = \lrb{d + e} \label{eq3} \\
e & = \lrc{f + g} \label{eq4}
\end{align}

Refer to \eqref{eq2} - \eqref{eq4}.

\end{document}

from latex to markdown test.md via

pandoc --wrap=preserve -s -t markdown -f latex -o test.md test.tex

the latex macros get expanded although that would not be necessary (because latex_macros extension is active for markdown by default):

Lorem ipsum dolor sit amet.

$$\begin{aligned}
a & =  \left( b + c \right)  \label{eq2} \\
c & =  \left[ d + e \right]  \label{eq3} \\
e & =  \left\{ f + g \right\}  \label{eq4}
\end{aligned}$$

Refer to [\[eq2\]](#eq2){reference-type="eqref" reference="eq2"} - [\[eq4\]](#eq4){reference-type="eqref" reference="eq4"}.

I figured out, that one can prevent the expansion of the latex macros by using the input format latex-latex_macros like

pandoc --wrap=preserve -s -t markdown -f latex-latex_macros -o test.md test.tex

which results in

    ```{=latex}
    \newcommand{\lra}[1]{ \left( #1 \right) }
    ```
    ```{=latex}
    \newcommand{\lrb}[1]{ \left[ #1 \right] }
    ```
    ```{=latex}
    \newcommand{\lrc}[1]{ \left\{ #1 \right\} }
    ```
    Lorem ipsum dolor sit amet.
    
    $$\begin{aligned}
    a & = \lra{b + c} \label{eq2} \\
    c & = \lrb{d + e} \label{eq3} \\
    e & = \lrc{f + g} \label{eq4}
    \end{aligned}$$
    
    Refer to [\[eq2\]](#eq2){reference-type="eqref" reference="eq2"} - [\[eq4\]](#eq4){reference-type="eqref" reference="eq4"}.

However this won't render correctly.

So my suggestion would be to not extend latex macros if the output format has explicitily activated the extension latex_macros, e.g.

pandoc -t markdown+latex_macros -f latex-o test.md test.tex

This could also be done for HTML output like

pandoc -s --mathjax -t html5+latex_macros -f markdown -o test.html test.md

because mathjax supports latex macros, too : https://docs.mathjax.org/en/latest/input/tex/macros.html .

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions