Skip to content

TeX reader: support amsmath spacing aliases and \cr - #305

Merged
jgm merged 1 commit into
jgm:masterfrom
faysou:tex-spacing-commands-cr
Nov 3, 2026
Merged

jgm merged 1 commit into
jgm:masterfrom
faysou:tex-spacing-commands-cr

Conversation

@faysou

@faysou faysou commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

The TeX reader rejects several standard amsmath spacing commands and the plain TeX row separator \cr. One unknown command makes the whole formula fail, so pandoc falls back to raw TeX for every output format:

printf '$a \\negthinspace b$\n' | pandoc -f markdown -t typst
[WARNING] Could not convert TeX math a \negthinspace b, rendering as TeX:
...
unexpected control sequence \negthinspace

This PR adds the missing spacing aliases with the widths of their short forms:

Command Width (em) Short form
\thinspace 1/6 \,
\negthinspace -1/6 \!
\thickspace 5/18 \;
\negthickspace -5/18 none
\negmedspace -2/9 none

It also accepts \cr as a row separator wherever \\ ends a row, for example in cases, matrix, and array:

printf '$$\\begin{cases} a \\cr b \\end{cases}$$\n' | pandoc -f markdown -t typst
unexpected control sequence \cr

New reader tests: test/reader/tex/space_commands.test and test/reader/tex/cr.test. The full test suite passes with GHC 9.10.3.

`\thinspace`, `\negthinspace`, `\thickspace`, `\negthickspace`, and
`\negmedspace` failed to parse, so one of them made the whole formula
fall back to raw TeX. They now map to the same widths as `\,`, `\!`,
`\;`, and their negative forms.

`\cr` failed to parse in arrays and amsmath environments such as
`cases` and `matrix`. It now ends a row like `\\`.
@jgm
jgm merged commit 3e827e8 into jgm:master Nov 3, 2026
6 checks passed
@jgm

jgm commented Nov 3, 2026

Copy link
Copy Markdown
Owner

thanks!

@faysou

faysou commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

waw, that was quick, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants