# Missing \endcsname inserted. due to conflict between biblatex and underscore

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:}{}

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

• 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. May 31 at 19:52

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:}{}

\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
\ifx\protect\@typeset@protect
\ifmmode \sb \else \BreakableUnderscore \fi
\else
\ifx\protect\@unexpandable@protect \noexpand_%
\else \protect_%
\fi\fi
a_b $a_b$ \textcite{hilt_when_2022}
`