jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.02k stars 3.35k forks source link

Error when listing is on a page break and lang is cs #7137

Open r0polach opened 3 years ago

r0polach commented 3 years ago

pandoc 2.11.4 for windows (x86_64), miktex 21.1 (x64)

When I run pandoc test_input.txt -o test_output.pdf -f markdown --listings on the attached file test_input.txt, I got following error:

Error producing PDF.
! Incomplete \iffalse; all text was ignored after line 129.
<inserted text>
                \fi
l.129 ON

test_input.txt

It is caused by combination of two facts:

If I remove lang: "cs" or if the text flow does not push the listing on the edge of the page, then everything would be ok.

tarleb commented 3 years ago

I can confirm this, tested on Ubuntu 20.04. The error happens with pdflatex and lualatex, but not with xelatex. I think we're using babel with the former two and polyglossia with the latter, so this all points to a weird interaction between babel support for Czech. Call pandoc with --pdf-engine=xelatex as a workaround.

Not sure if there is anything that can be done in pandoc. Could you raise the issue with the babel maintainers?

tarleb commented 3 years ago

Interestingly, I get a different error when using TeXlive 2020:

! Missing \endcsname inserted.
<to be read again> 
                   \unhbox 
l.27 ... `\-one}{{}{1}{Chapter One}{section*.1}{}}
r0polach commented 3 years ago

I also sometimes see different error message, depending probably on "how much" the code block is out of the page...

Unfortunatelly I cannot use xelatex, because I have important macro in lua, so I need lualatex...

tarleb commented 3 years ago

Closing this now, as this seems to be a babel issue. I'd be happy to reopen if there is something that could be done in pandoc to work around it.

r0polach commented 3 years ago

Could you please point me where I should fill a report about that?

tarleb commented 3 years ago

I'm not sure, but https://github.com/latex3/babel would probably be the right place.

tarleb commented 3 years ago

See also https://www.ctan.org/pkg/babel-czech

r0polach commented 3 years ago

As described in https://github.com/latex3/babel/issues/132#issuecomment-845069695 and following comments, there are some workarounds. I am not sure, but maybe something could be incorporated in pandoc itself, so not all users affected by this are pushed to investigate the error solution for themselves individually?

tarleb commented 3 years ago

Thanks @r0polach. Reopening while we investigate the proposed solutions.

jgm commented 3 years ago

We already have code that disables all language-specific shorthands in the default template. This is relatively recent, though. Have you tested with the latest version of pandoc?

tarleb commented 3 years ago

Somehow that hadn't occur to me. I tested now, and everything works fine with the current development version.

tarleb commented 3 years ago

Actually, I forgot that I had previously put a `\shorthandoff{-}`{=latex} in the file that I used for testing. Without this, it still fails.

tarleb commented 3 years ago

I like the solution you came up with @r0polach. It could be added to the default template, but it seems a bit too specific for that.

\usepackage{ifthen}
\ifthenelse{\equal{\language}{czech}}{\AtBeginDocument{\shorthandoff{-}}}{}%

This is an unfortunate situation, but I'm still not sure if this should be fixed in pandoc.

jgm commented 3 years ago

So, am I to understand that this code doesn't in fact get rid of all language-specific shorthands?

% get rid of language-specific shorthands (see #6817):
\let\LanguageShortHands\languageshorthands
\def\languageshorthands#1{}
tarleb commented 3 years ago

That's my understanding as well.

jgm commented 3 years ago

I think we need the advice of a babel expert -- there must be a way to globally turn off language-specific shorthands. (I've posted on the linked babel thread.)