pythontex icon indicating copy to clipboard operation
pythontex copied to clipboard

Pythontex does not work with German language (yes really)

Open Kamik423 opened this issue 2 years ago • 3 comments

Minimal working example

\documentclass[a4paper]{article}

\usepackage[german, ngerman]{babel}
\usepackage{ngerman} % I am the bad line

\usepackage{pythontex}

\begin{document}

\begin{pycode}
    print("y")
\end{pycode}

\end{document}

Running

xelatex mwe.tex

yields

! Argument of " has an extra }.
<inserted text> 
                \par 
l.284 \StrSubstitute{\pytx@jobname}{"}{}
                                        [\pytx@jobname]

removing the ngerman line makes it run again.

Kamik423 avatar Mar 25 '22 00:03 Kamik423

I'd suggest trying to load pythontex before babel. I expect that ngerman is globally redefining " immediately (making it active, perhaps for umlaut), and this is interfering with pythontex using the " character in the preamble.

gpoore avatar Mar 25 '22 03:03 gpoore

Should this not at least be mentioned in the documentation at some point where users can see it? Or maybe when loading pythontex the package could check for " being redefined and display a more helpful error message?

Kamik423 avatar Apr 22 '22 07:04 Kamik423

I can look into adding a note to the documentation, and at some point, I may be able to add a check for redefinitions of ASCII punctuation characters. The order of loading packages should really be discussed in language packages like ngerman, though, because any time a package globally redefines character or common macro meanings within the preamble, there is significant potential for issues, and such packages should always be loaded as late as possible.

gpoore avatar Apr 22 '22 13:04 gpoore