[Tex/LaTex] Misplaced alignment tab character & in bibliography

bibererrors

TeXtudio gives me the error Misplaced alignment tab character &. in the line where I insert my bibliography. This line is \include{\dir/bibliography} which links to

\manualmark%
\markboth{\spacedlowsmallcaps{\bibname}}{\spacedlowsmallcaps{\bibname}}
\refstepcounter{dummy}
\addtocontents{toc}{\protect\vspace{\beforebibskip}} 
\addcontentsline{toc}{chapter}{\tocEntry{\bibname}}
\label{app:bibliography}

\emergencystretch=1em%
\printbibliography

I think the problem might be caused by & symbols within the references, of which there are very many. I could replace them with \& or "and", but maybe there's an easier solution.

I'm using MiKTeX and Biber.

Best Answer

The character & has a special meaning for LaTeX: It marks new table columns or new alignment columns in general (think align).

As such you can't generally use & in its meaning as ampersand character in standard LaTeX and must escape it to \&, see Escape character in LaTeX. There are some exceptions to this rule: In \verb|...| and other verbatim commands as well as \url and some related commands you can often use & without escaping it, but there are some subtle points with those commands (see for example How to use a link as footnote that has special characters inside?).

It's pretty much the same for the bibliography. You should escape & to \& in .bib files except in special verbatim fields like doi, eprint and url.

The best solution™ is to make sure to escape & to \& in the .bib file unless it is in a doi, eprint, url or otherwise verbatim field. E.g. instead of

publisher = {Pub & Co.},

you should write

publisher = {Pub \& Co.},

If for some reason you absolutely cannot bring yourself to fix your .bib file once for good, you can have Biber do that on the fly for you (but this is at most the second best solution™). (biblatex uses an XML format to communicate with Biber, where & is also a special character, so we better escape it as \x{26}.)

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=authoryear, backend=biber]{biblatex}

\DeclareSourcemap{
  \maps{
    \map{
      \step[fieldsource=publisher,
        match=\regexp{\x{26}},
        replace=\regexp{\\\x{26}}]
    }
  }
}

\begin{filecontents}{\jobname.bib}
@book{appleby,
  author    = {Humphrey Appleby},
  title     = {On the Importance of the Civil Service},
  date      = {1980},
  publisher = {Pub & Co.},
}
\end{filecontents}
\addbibresource{\jobname.bib}


\begin{document}
\cite{appleby}
\printbibliography
\end{document}

"Pub & Co." displayed as desired

Related Ampersand in Sourcemap for BibTex.