Bibtex Latex-Workshop 插入缺少 endcsname

Bibtex Latex-Workshop 插入缺少 endcsname

我對在Linux 中使用textlive 和vscode 以及擴展名為Latex-Workshop 的Latex 工作還很陌生,我花了一些時間讓它一起工作,但最終它工作正常,除了我不斷收到標題中的錯誤“Missing ” endcsname 插入到我的書目文件中的一個特定條目上:

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

這只是乳膠課程中的一篇虛擬文章。微量元素:

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

已經查找了先前的問題,但唯一的問題是遠端相似的,即在圍脖檔案中使用帶有奇怪字元的鍵或在某些欄位中使用下劃線的問題。

答案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並將其編譯為ñ.不幸的是,在西班牙語巴別塔之外,該~角色還插入一個(特定類型的)空格,並且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}

相關內容