jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.6k stars 3.38k forks source link

Passing `american` to `\babelfont` produces LaTeX error when `realscript` is used #8728

Closed fiapps closed 1 year ago

fiapps commented 1 year ago

Explain the problem. MWE (test.md):

---
lang: en-US
mainfont: cochineal
header-includes: | 
    ```{=latex}
    \usepackage{realscripts}

test^[this]

Command line: `pandoc test.md --pdf-engine=xelatex -o test.pdf`
Error:

Error producing PDF. ! LaTeX Error: Key 'fontspec-opentype/Language' accepts only a fixed set of (LaTeX) choices.

For immediate help type H . ...

l.74 test\footnote{


Environment: pandoc 3.1.1, macOS 12.6.3, TeXLive 2023

The error depends on the line `\babelfont[american]{rm}{cochineal}`. If `american` is changed to `english`, xelatex completes the required two passes without error. With `american`, it fails on the second pass. Also if `[american]` is deleted, two XeLaTeX passes complete without error. I know 3.1.2 has been released, but it's not yet available through Homebrew, and the LaTeX template looks like it would still produce this line.

The bug here may be in `babel`, because specifying `[american]` works with TeXLive 2021, but I don't think `pandoc` should be passing any language here in the template. As I read the `babel` documentation, one passes a language to `\babelfont` in order to use a different font for a specific language. So this first invocation should not pass a language, because it's setting the default font. It's only with the new `babelfonts` variable that a language should be passed, to override the default `\babelfont` for a specific language or languages.

So I propose changing line 366 of `data/templates/default.latex` from
`\babelfont[$babel-lang$]{rm}[$for(mainfontoptions)$$mainfontoptions$$sep$,$endfor$]{$mainfont$}`
to
`\babelfont{rm}[$for(mainfontoptions)$$mainfontoptions$$sep$,$endfor$]{$mainfont$}`
jgm commented 1 year ago

You're probably right. We can try it. See #8538 -- I want to make sure we don't break what we fixed there.

jgm commented 1 year ago

OK, seems to work in both cases. I'll make the change.

fiapps commented 1 year ago

Thanks for the quick fix. I'll just use the corrected template with --template until the next release.