几天来我一直在努力解决这个错误。我的一些引用都出现了这个错误。这是一个最小的例子
引文.bib
@InProceedings{Cohn_1995,
author = {Cohn, a},
title ={A hierarchical representation of qualitative shape based on connection and convexity},
booktitle = {Spatial information theory a theoretical basis for GIS},
year = {1995},
pages = {311--326}
}
测试.tex
\documentclass[12pt]{article}
\usepackage{natbib}
\usepackage{graphicx}
% Suggested packages for algorithm formatting
\usepackage{algorithm}
%\usepackage{algorithmic}
\usepackage{algpseudocode}
% To solve issue with _ in DOI
\usepackage[strings]{underscore}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage[hyphenbreaks]{breakurl}
\usepackage[table]{xcolor}
\usepackage{amssymb,amsmath}
\usepackage{subfigure}
\begin{document}
\title{BibTeX in action}
\author{Martin J. Osborne}
\date{2008-1-13}
\maketitle
% Your main text begins here.
\section{Introduction}
Hello \cite{Cohn_1995}
\bibliographystyle{plainnat}
\bibliography{citations}
\end{document}
这是我收到的错误。有什么方法可以找出我的引文中存在的问题吗?
line 25: Missing \endcsname inserted. \bibcite{Cohn_1995}{{1}{1995}{{Cohn}}{{}}}
line 25: Extra \else. \bibcite{Cohn_1995}{{1}{1995}{{Cohn}}{{}}}
line 25: Extra \endcsname. \bibcite{Cohn_1995}{{1}{1995}{{Cohn}}{{}}}
line 25: Extra \else. \bibcite{Cohn_1995}{{1}{1995}{{Cohn}}{{}}}
: You are using breakurl while processing via pdflatex.
: Citation(s) may have changed.
谢谢
答案1
导致您遇到的问题的直接原因是您加载了下划线_
包。当 LaTeX 在诸如指令参数之类的地方遇到未转义的实例时,加载此包可能会发生奇怪的事情。\cite
正如您所发现的,即使使用选项加载包,也可能发生这种情况strings
。
你真的需要加载这个underscore
包吗?我注意到你的代码包含注释“解决 DOI 中 _ 的问题”。然而,这是不是url
这确实是加载 underscore 包的一个很好的理由。如果加载了或更好的是包,效率会更高,xurl
因为大多数支持 doi 的书目样式(包括plainnat
!)会自动将字段内容装入包装器doi
中\url{...}
。
在以下示例中,我补充了您的书目条目中缺失的几个字段,包括字段doi
包含下划线字符。观察 (a) cite 键仍然包含下划线字符,字段也是如此doi
,以及 (b)xurl
包已加载。使用此设置,doi 字段中的下划线字符可以很好地处理,而且,作为额外奖励,您不必编辑引用键。
\documentclass[12pt]{article}
\begin{filecontents}[overwrite]{citations.bib}
@InProceedings{Cohn_1995,
author = {Cohn, A. G.},
title = {A hierarchical representation of qualitative shape
based on connection and convexity},
booktitle = {Spatial information theory. A theoretical basis for GIS},
editor = {A. U. Frank and W. Kuhn},
year = {1995},
pages = {311--326},
series = {Lecture Notes in Computer Science},
volume = 988,
doi = {https://doi.org/10.1007/3-540-60392-1_20},
}
\end{filecontents}
\usepackage[authoryear,round]{natbib} % or: \usepackage[numbers]{natbib}
\bibliographystyle{plainnat}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc} % that's the default nowadays
\usepackage[T1]{fontenc} % <-- new
\usepackage{xurl} % <-- new
\usepackage[colorlinks,allcolors=blue]{hyperref}
%%\usepackage[hyphenbreaks]{breakurl} % not needed if 'xurl' package is loaded
\begin{document}
\noindent
\cite{Cohn_1995}
\bibliography{citations}
\end{document}
答案2
显然问题出在引用键上。我应该避免_
在键中使用
来自评论:
The presence of an underscore character in the citation key is not the direct cause of the problem. Instead, the cause is the underscore package, which -- even when loaded with the strings package option -- can do weird things when LaTeX comes across unescaped instances of _.