4

I was trying to replace a list of journal names with their abbreviations. Some journal names contain an ampersand symbol, but the codes below do not seem to work.

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{example.bib}
@article{example,
    author = {First Last},
    title = {Title},
    journal = {Subject \& Subject},
    year = {0000}, volume = {0}, number = {0},
}
\end{filecontents}


\usepackage{biblatex}
\addbibresource{example.bib}

\DeclareSourcemap{\maps[datatype=bibtex]{\map{\step[fieldsource=journal, match={Subject \& Subject}, replace={S\& S}]}}}

\begin{document}

\nocite{*}
\printbibliography

\end{document}
2
  • 1
    Can you please add a complete example?
    – egreg
    Commented Aug 9 at 8:50
  • @egreg Thank you. Updated.
    – FSY
    Commented Aug 9 at 9:11

1 Answer 1

4

As explained in Ampersand in Biber Sourcemap we have to encode the ampersand as \x{26} so things don't explode in the .bcf file. But since \x looks like a LaTeX command we need to "escape" it with \string. Additionally, we need to escape the backslash as \\ in RegExp, because \ is RegExp's escape character.

This leads to

\documentclass{article}

\usepackage{biblatex}
\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=journal,
        match={Subject \\\string\x{26} Subject},
        replace={S \\\string\x{26} S}]
    }
  }
}

\begin{filecontents}{\jobname.bib}
@article{example,
  author  = {First Last},
  title   = {Title},
  journal = {Subject \& Subject},
  year    = {0000}, volume = {0}, number = {0},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

First Last. “Title”. In: S & S 0.0 (0).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .