Bibtex Latex-Workshop 缺少插入 endcsname

Bibtex Latex-Workshop 缺少插入 endcsname

我对在 Linux 中使用 textlive 和 vscode 以及扩展名 Latex-Workshop 的 Latex 还很陌生,我花了一些时间让它们一起工作,但最后它工作正常,只是我不断收到标题中的错误“缺少插入 endcsname”在我的 bibfile 中的一个特定条目中:

@article{llavearticulo,
  author  = {Arthur B Cummings and David Eftekhary and Frank G House},
  title   = {The accurate determination of college students
             coefficients of friction},
  journal = {Journal of Sketchy Physics},
  volume  = {13},
  year    = {2003},
  number  = {2},
  pages   = {46--129}
}

这只是一篇来自 Latex 课程的虚拟文章。MWE:

\documentclass[12pt]{report}

\usepackage[a4paper, margin=2.54cm, head=1.27cm, foot=1.27cm]{geometry}
\usepackage[spanish]{babel}
\usepackage{natbib}
\usepackage{fancyhdr}
\usepackage{import}
\usepackage{hyperref}
\usepackage{xcolor}
\usepackage[table]{xcolor}
\usepackage{pdflscape}
\usepackage{ulem}
\usepackage{amsmath}
\usepackage{multicol}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{cellspace}
\usepackage{graphicx}
\usepackage[spanish]{cleveref}
\usepackage{url}

\graphicspath{{./images}}

\newcommand{\mychapter}[2]{
    %\setcounter{chapter}{#1}
    %\setcounter{section}{0}
    \chapter*{#1 #2}
    \addcontentsline{toc}{chapter}{#1 #2}
    \refstepcounter{chapter}
}

\fancypagestyle{plain}{
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
}
\pagestyle{plain}

\renewcommand{\contentsname}{Índice general}
\renewcommand{\listfigurename}{Índice de cuadros}
\renewcommand{\listtablename}{Índice de figuras}

\title{My title}
\author{My myself}
\date{}

\begin{document}

\maketitle

Otras formas de citas
\begin{itemize}
    \item \cite[p.12]{llavearticulo}
    \item \cite[e.g.][p.12]{llavearticulo}
    \item \cite[e.g.][]{llavearticulo}
    \item \cite[][]{llavearticulo}
    \item \citep{llavearticulo}
    \item \cite*{llavearticulo}
    \item \citep*{llavearticulo}
\end{itemize}


\newpage
\bibliography{sources}
\bibliographystyle{chicago}

\end{document}

检查生成的文件,main.bbl 文件在结尾之前的行有错误:

\begin{thebibliography}{}

\bibitem[\protect\citeauthoryear{Cummings, Eftekhary, and House}{Cummings et~al.}{2003}]{llavearticulo}
Cummings, A.~B., D.~Eftekhary, and F.~G. House (2003).
\newblock The accurate determination of college students coefficients of friction.
\newblock {\em Journal of Sketchy Physics\/}~{\em 13\/}(2), 46--129.

\end{thebibliography}

已经查找过以前的问题,但只有稍微相似的问题在 bib 文件中使用了带有奇怪字符的键或在某些字段中使用下划线。

答案1

首先:以后请更好地修剪你的 MWE。你加载的大多数包在文档中都没有使用,如果你做了一些初步修剪(逐个注释掉每个包,看看它是否会影响问题),你可能会得出这样的结论:下面是一个更简单的示例

\documentclass[12pt]{report}

\usepackage[spanish]{babel}
\usepackage{natbib}



\title{My title}
\author{My myself}
\date{}

\begin{document}

\maketitle

Otras formas de citas
\begin{itemize}
    \item \cite[p.12]{llavearticulo}
    \item \cite[e.g.][p.12]{llavearticulo}
    \item \cite[e.g.][]{llavearticulo}
    \item \cite[][]{llavearticulo}
    \item \citep{llavearticulo}
    \item \cite*{llavearticulo}
    \item \citep*{llavearticulo}
\end{itemize}


\newpage
\bibliography{sources}
\bibliographystyle{chicago}

\end{document}

而罪魁祸首就babel在那个spanish选项里。

问题是,babel-spanish 创建了几个简写,以便使用标准 ASCII 字符集快速输入重音字符。其中包括能够输入~n并将其编译为ñ。不幸的是,在西班牙语 babel 之外,字符~还会插入(特定类型的)空格,并且natbib(尤其是在chicago样式中)使用它来对参考书目项目进行一些格式化。

两种可能的解决方案

  • 如果你根本不使用 babel 简写(根据你发布的 MWE,你似乎用 Unicode 键入文档,并且可以ñ直接键入字符),最简单的方法是在 babel 中完全关闭简写。你可以通过向 中添加适当的选项来实现这一点\uspackage[...]{babel}。例如,尝试

    \usepackage[spanish, es-noshorthands, shorthands=off]{babel}
    
  • 如果你确实使用了 babel 简写,你也可以在打印参考书目之前关闭有问题的简写。尝试将代码的最后几行替换为

\newpage
\shorthandoff{~}   % <- turns off the ~ short hand
\bibliography{sources}
\bibliographystyle{chicago}

\end{document}

相关内容