由于 biblatex 和下划线冲突,缺少 \endcsname 插入

由于 biblatex 和下划线冲突,缺少 \endcsname 插入

当我同时拥有 biblatex 和 underscore 包时,我遇到了“缺少 \endcsname 插入”错误。我的文本需要这两个包。

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

引文如下

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

我找不到解决这一问题的方法。

答案1

最简单的方法就是避免underscore

如果您确实需要它,您可以在活动下划线的定义中添加一个测试,以检查下划线是否在构造中使用(发布\csname...\endcsname时此类测试不可用)。underscore

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

在此处输入图片描述

相关内容