2

This question already has an answer here:

The following example compiles with an error:

\documentclass{article}

\usepackage[english]{babel}\usepackage{csquotes}

\usepackage{listings}%\usepackage{listingsutf8}

\usepackage[style=ieee]{biblatex}

\usepackage{filecontents}
\begin{filecontents}{bib.bib}
    @Article{A1, title = {A b}}
    @Article{A2, title = {A~b}}
\end{filecontents}

\addbibresource{bib.bib}

\begin{document}

    A: \cite{A1}.\\
    B: \cite{A2}.\\

    \printbibliography

\end{document}

l.23 Undefined control sequence.

Something probably causes the ~ character in bibliography entry to be confusing for LaTeX, as document with \cite{A2} commented out compiles with no errors.

Result after removing <code>\cite{A2}</code>

Either changing \usepackage[english]{babel} to \usepackage{babel}
or changing \usepackage[style=ieee]{biblatex} to \usepackage{biblatex},
or removing \usepackage{listings} (which is necessary, but its application was removed from the MWE),
also causes the document to compile without errors, so there are four factors involved: all three of these packages together with the usage of tilde character in bibliography.

I cannot figure out the reason because this incompatibility, but resolving it would be quite useful for me.

marked as duplicate by Ulrike Fischer, Stefan Pinnow, user36296, egreg babel Jul 26 '18 at 9:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5

As Ulrike Fischer said in the comments below, this is a bug in listings. The package uses \lccode to define types of character for later use. This \lccode trick uses ~ because it's the one standard active character in LaTeX. But listings "forgets" to reset this \lccode to the original value and then \the\lccode`~ remains equal to 122 (that of z).

To fix the problem you can reset the \lccode of ~ right after listings is loaded. Also, as egreg found out here, the same issue happens with \/, so the same fix can be used for both:

\usepackage{listings}
\lccode`~=0 % Fix for ~
\lccode`\/=0 % Fix for \/ (https://tex.stackexchange.com/a/202621/134574)

Old answer:

The problem is actually unrelated to biblatex. The same error is raised by the following MWE:

\documentclass{article}
\usepackage{babel}
\usepackage{listings}
\begin{document}
\MakeLowercase{A~b}
\end{document}

and the error is:

! Undefined control sequence.
<to be read again> az
                     b
l.12 \MakeLowercase{A~b}

This happens with biblatex because it uses \MakeLowercase.

The error is, I think, due to some incompatibility caused by the interaction of babel and listings.

Apparently the \lccode of ~ is defined to z and this z is undefined. A workaround (not sure if the best alternative) is to make this definition:

\begingroup\lccode`~=`z\lowercase{\endgroup\let~= }

then your MWE works fine:

\documentclass{article}

\usepackage[english]{babel}\usepackage{csquotes}

\usepackage{listings}%\usepackage{listingsutf8}

\usepackage[style=ieee]{biblatex}

\usepackage{filecontents}
\begin{filecontents}{bib.bib}
    @Article{A1, title = {A b}}
    @Article{A2, title = {A~b}}
\end{filecontents}

\addbibresource{bib.bib}

\begingroup\lccode`~=`z\lowercase{\endgroup\let~= }

\begin{document}

    A: \cite{A1}.\\
    B: \cite{A2}.\\

    \printbibliography

\end{document}

Not the answer you're looking for? Browse other questions tagged or ask your own question.