peiTeX / qrbill

LaTeX package to create qrbills based on the Swiss standard
13 stars 3 forks source link

Backslash in name leads to error #13

Closed The-Compiler closed 2 years ago

The-Compiler commented 2 years ago

One of my customers has a backslash in their company name (yes, they're IT related; yes, they did it for fun; no, I don't find it very funny either).

Unfortunately, something like:

\documentclass{standalone}
\usepackage[ngerman]{babel}

\usepackage{xcolor}
\usepackage{qrbill}

\begin{document}

\QRbill[
creditor*={foo\textbackslash{}bar LLC\\
    Postfach \\
    404\\
    2342\\
    Zurich\\
    CH},
Account=CH1280808005649899718,
]

\end{document}

leads to:


<QR code requested for "SPC
0200
1
CH1280808005649899718
S
foo\TU\textbackslash  {}bar LLC
Postfach
404
2342
Zurich
CH

CHF

NON

EPD
//S1

" in version 0-M.>
! Missing \endcsname inserted.
<to be read again> 
\TU\textbackslash 
l.17 ]

? 

Is there a way I can escape it to make this work? If not, is this something that can be fixed, or an issue with the qrcode package?

TeXhackse commented 2 years ago

It can be both. the package could have an option to convert it to strings or you change your input to a backslash with catcode 12. I tagged it as enhancement because it's a feature to add this option.

TeXhackse commented 2 years ago

Maybe I was not clear enough, this exects a bit background knowledge of LaTeX.

To workaround this you can generate a char using the charcode of the backslash and category code „other“.

\documentclass{standalone}
\usepackage[ngerman]{babel}

\usepackage{qrbill}

\ExplSyntaxOn
\newcommand*{\tokenBS}{\char_generate:nn {92} {12}}
\ExplSyntaxOff

\begin{document}

    \QRbill[
    creditor*={foo\tokenBS bar LLC\\
        Postfach \\
        404\\
        2342\\
        Zurich\\
        CH},
    Account=CH1280808005649899718,
    ]

\end{document}

Note: On recent TeX installations ngerman is no longer required - though you might prefer swissgerman to avoit “ß” anyway. The default for german now is the same as former ngerman

The-Compiler commented 2 years ago

To workaround this you can generate a char using the charcode of the backslash and category code „other“.

Ah, perfect, thanks! That does indeed work fine. Don't mind a workaround since I generate the .tex from Python anyways.

I was playing around with \catcode to redefine \, but couldn't get it to work.

Note: On recent TeX installations ngerman is no longer required - though you might prefer swissgerman to avoit “ß” anyway. The default for german now is the same as former ngerman

That was copied from the doc example. I opened #14 to update it.

TeXhackse commented 2 years ago

I added an option which will use all input data to be parsed as string. This resolves this issue as well.

In case you want to mix up special characters and real LaTeX code you have to escape it manually of course.