Bibtex Latex-Workshop 挿入された endcsname がありません

Bibtex Latex-Workshop 挿入された endcsname がありません

私は Linux で Textlive と vscode を使って Latex を操作している初心者で、拡張機能 Latex-Workshop を使っています。これらを連携させるのに少し時間がかかりましたが、最終的には問題なく動作しています。ただし、bibfile 内の特定のエントリのタイトルに「挿入されていない 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}
}

これは 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をもっとうまく整理してください。ロードしたパッケージのほとんどはドキュメントでは使用されていません。予備的な整理(各パッケージを1つずつコメントアウトして、それが問題に影響するかどうか確認する)を行えば、次の例の方がはるかに最小限であるという結論に達するかもしれません。

\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) 参考文献項目の一部の書式設定に使用します。

2つの解決策

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

関連情報