# Possible incompatibility between babel, listings and biblatex causes problem with unbreakable space in bibliography [duplicate]

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}

\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.

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 StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Jul 26 '18 at 9:23

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)

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.
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~= }

\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}