2

I encounter the "Missing \endcsname inserted" error when I have both biblatex and underscore packages. I need both for my text.

\documentclass{article}
\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[strings]{underscore}
\usepackage[style=authoryear-icomp, 
backend=biber, 
giveninits=false,
uniquelist = false, 
uniquename=init,
isbn=false, 
maxcitenames=3,
dashed=false, 
maxbibnames=999,
doi=false,
url=false,
eprint=false,
date=year,
]{biblatex}
\renewbibmacro{in:}{}
\addbibresource{reference.bib}

\begin{document}
\textcite{hilt_when_2022}
\printbibliography
\end{document}

The citation is

@article{hilt_when_2022,
    title = {When Uncle Sam introduced Main Street to Wall Street: Liberty Bonds and the transformation of American finance},
    volume = {145},
    issn = {0304-405X},
    url = {https://www.sciencedirect.com/science/article/pii/S0304405X21003135},
    doi = {10.1016/j.jfineco.2021.06.043},
    shorttitle = {When Uncle Sam introduced Main Street to Wall Street},
    pages = {194--216},
    number = {1},
    journaltitle = {Journal of Financial Economics},
    shortjournal = {Journal of Financial Economics},
    author = {Hilt, Eric and Jaremski, Matthew and Rahn, Wendy},
    urldate = {2022-05-30},
    date = {2022-07-01},
    langid = {english}
}

I couldn't figure out a way to get around it.

1
  • 1
    As mentioned in the documentation for underscore you must avoid underscores in \cite and \ref commands. Since the package dates from 2006, and is unaware of biblatex the strings. Although there is a mechanism to make it aware of new commands, it doesn't seem to work for biblatex commands.
    – Alan Munn
    May 31 at 19:52

1 Answer 1

2

The simplest way is to avoid underscore.

If you really need it, you can add a test to the definition of the active underscore which checks whether the underscore is used in a \csname...\endcsname construction (such test wasn't available when underscore was released).

\begin{filecontents*}{\jobname.bib}
@article{hilt_when_2022,
    title = {When Uncle Sam introduced Main Street to Wall Street: Liberty Bonds and the transformation of American finance},
    volume = {145},
    issn = {0304-405X},
    url = {https://www.sciencedirect.com/science/article/pii/S0304405X21003135},
    doi = {10.1016/j.jfineco.2021.06.043},
    shorttitle = {When Uncle Sam introduced Main Street to Wall Street},
    pages = {194--216},
    number = {1},
    journaltitle = {Journal of Financial Economics},
    shortjournal = {Journal of Financial Economics},
    author = {Hilt, Eric and Jaremski, Matthew and Rahn, Wendy},
    urldate = {2022-05-30},
    date = {2022-07-01},
    langid = {english}
}
\end{filecontents*}

\documentclass{article}
\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[
  style=authoryear-icomp, 
  backend=biber, 
  giveninits=false,
  uniquelist = false, 
  uniquename=init,
  isbn=false, 
  maxcitenames=3,
  dashed=false, 
  maxbibnames=999,
  doi=false,
  url=false,
  eprint=false,
  date=year,
]{biblatex}

\usepackage[strings]{underscore}

\renewbibmacro{in:}{}
\addbibresource{\jobname.bib}

\begingroup\makeatletter
 \catcode`\_=\active
 \gdef _{% \relax % No relax gives a small vulnerability in alignments
   \ifx\if@safe@actives\iftrue % must be outermost test!
      \string_%
   \else
    \ifincsname\string_\else % <--- added
      \ifx\protect\@typeset@protect
         \ifmmode \sb \else \BreakableUnderscore \fi
      \else
         \ifx\protect\@unexpandable@protect \noexpand_%
         \else \protect_%
      \fi\fi
     \fi % <--- added
    \fi}
  \global\let\ActiveUnderscore=_
  \gdef\normalUnderscoreDef{\let_\ActiveUnderscore}
\endgroup


\begin{document}
a_b $a_b$ \textcite{hilt_when_2022}
\printbibliography
\end{document}

enter image description here

1
  • Thank you! This is very helpful!
    – Bunbury
    May 31 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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