jgm/pandoc

New approach to LaTeX math environments

jgm opened this issue · 0 comments

jgm commented

Certain LaTeX environments contain math but cannot occur in math mode: e.g., align. So

\[
\begin{align}...
...\end{align}
\]

is not legal. We would like to handle these in the best possible way. Parsing them to RawInline elements would be one approach, but this would mean that they were lost when converting to non-LaTeX formats. So instead we parse them as pandoc Math inlines. But because the LaTeX writer outputs Math inlines between \[..\] or \(..\), we modify these environments to versions that can live inside math mode: e.g., align -> aligned. For the most part this gives acceptable results, but there are rough edges. align environments are numbered, and aligned environments are not, so numbering gets lost when round-tripping LaTeX -> Markdown -> LaTeX.

Proposal: instead of "downshifting" these environments in the LaTeX reader, we could just put them in Math inlines. They should be harmless there, except in (a) LaTeX output and (b) HTML output using KaTeX. (MathJaX just allows them inside \[...\], and texmath, which we use for conversion to non-TeX math formats, can handle align.) For (a) and (b) we could do a check in the writers and, when these environments are encountered in Math, we could either "downshift" them or (in the case of LaTeX) just emit a raw LaTeX block.

Here are the affected environments: https://github.com/jgm/pandoc/blob/main/src/Text/Pandoc/Readers/LaTeX/Math.hs#L84-L110
The "downshifting" is done here and in mathEnvWith.

If we implemented this change, we'd also need to add handling to texmath for some of these special environments. (Some, but not all, are currently handled.)

I'm putting this up for comment and further consideration.