Search code examples
pandocquarto

Multi-line math fails in Quarto


Quarto 1.2.269, Pandoc 2.19.2, XeTeX 3.141592653-2.6-0.999994

index.qmd

---
title: "Why do I get a warning and failure to convert?"
---

This works:

$$
a = \pi r^2
$$

These do not:

$$
a_n = \begin{cases}
          3n + 1  & \text{ if } n \text{ is odd} \\
          n / 2 & \text{ otherwise}
      \end{cases}
$$

$$
1 + 2 = 3 \\
3 + 2 = 5
$$

_quarto.yml

project:
  type: book

book:
  title: "MRE"
  chapters:
    - index.qmd

format:
  epub:
    toc: true  # whatever

Then, attempt rendering...

$ quarto render

pandoc 
  to: epub
  output-file: MRE.epub
  toc: true
  number-sections: true
  default-image-extension: png
  
metadata
  crossref:
    chapters: true
  title: MRE
  
[WARNING] Could not convert TeX math 
      a_n = \begin{cases}
            3n + 1  & \text{ if } n \text{ is odd } \\
            n / 2 & \text{ otherwise }
        \end{cases}
  , rendering as TeX
[WARNING] Could not convert TeX math 
  1 + 2 = 3 \\
  3 + 2 = 5
  , rendering as TeX:
  1 + 2 = 3 \\
  ^
  unexpected control sequence \\
  expecting "%", "\\label", "\\tag", "\\nonumber" or whitespace
Output created: _book/MRE.epub

...and the resulting epub looks like this:

epub output

What am I doing wrong? How do I use cases environment or multi-line math in Quarto?

Note: This works with project type website, but not with project type book.


Solution

  • You could try to wrap it in LateX environments, e.g. equation or align (works both in PDF and HTML outputs)

    \begin{equation*}
        a_n = \begin{cases}
                  3n + 1  & \text{ if } n \text{ is odd} \\
                  n / 2 & \text{ otherwise}
              \end{cases}
    \end{equation*}
    
    \begin{align*}
    1 + 2 = 3 \\
    3 + 2 = 5
    \end{align*}
    

    Here for instance as HTML Book output:

    enter image description here