我正在使用BibTeX
。当我的 bib 文件包含带有doi
如下字段的引用时:
Doi = {10.1007/978-94-007-2421_10}
它无法编译。我BibTeX
认为那_
是一个数学符号。但是当我剪切这个符号时,它可以编译。
Doi = {10.1007/978-94-007-2421}
以下是 MWE:
\Documentclass{llncs}
\usepackage{xcolor}
\usepackage[hyphens,spaces]{url}
\urlstyle{rm}
\usepackage[colorlinks,urlcolor=blue]{hyperref}
\usepackage{filecontents}
\begin{document}
\title{My Title}
\author{My Name}
\maketitle
Foo bar baz \cite{maggino2012a}.
\bibliographystyle{splncs04}
\begin{filecontents*}{\jobname.bib}
@incollection{maggino2012a,
Author = {Maggino, Filomena and Zumbo, Bruno D},
Booktitle = {Handbook of social indicators and quality of life research},
Doi = {10.1007/978-94-007-2421-1_10},
Editor = {Land K., Michalos A., Sirgy M.},
Pages = {201--238},
Publisher = {Springer, Dordrecht},
Title = {Measuring the quality of life and the construction of social indicators},
Year = {2012},
}
\end{filecontents*}
\bibliography{\jobname}
\end{document}
答案1
我遇到了同样的问题,使用另一种 BibTeX 样式。在 .bst 文件中,format.doi
用以下代码替换该函数,该代码转义_
字符(也转义%
和^
),并允许在 DOI 中的相关点处换行。
INTEGERS { l }
% the real length of a string (text.length$ doesn't count some special characters)
FUNCTION {string.length}
{ #1 'l :=
{duplicate$ duplicate$ #1 l substring$ = not}
{l #1 + 'l :=}
while$
pop$ l
}
STRINGS{replace find text}
INTEGERS{find_length}
% usage: <string> "~" "tilde" find.replace
FUNCTION{find.replace}
{ 'replace :=
'find :=
'text :=
find string.length 'find_length :=
""
{ text empty$ not }
{ text #1 find_length substring$ find =
{
replace *
text #1 find_length + global.max$ substring$ 'text :=
}
{ text #1 #1 substring$ *
text #2 global.max$ substring$ 'text :=
}
if$
}
while$
}
% allow line breaks when formatting a DOI
FUNCTION {allowbreaks.doi}
{
"_" "\_\allowbreak{}" find.replace
"^" "\^" find.replace
"%" "\%" find.replace
"/" "/\allowbreak{}" find.replace
"-" "-\allowbreak{}" find.replace
}
FUNCTION {format.doi}
{ doi empty$
{ "" }
{ "\MyDOI{https://doi.org/" doi * "}{" * doi allowbreaks.doi * "}" * }
if$
}
您还需要在 LaTeX 文件中提供 \MyDOI 的定义(如下所示),或将其替换为 \doi
\newcommand{\MyDOI}[2]{\BeginAccSupp{E=Digital Object Identifier}\textsc{DOI}\EndAccSupp{}: \href{#1}{#2}}
答案2
(我已更新此答案以反映 Springer 最近将文档类更新至 2.21 版的事实llncs
。结果是不再需要定义\doi
宏的替换。)
以下是如何使 MWE 工作,以便包含 TeX 特殊字符的 doi 字符串不会使 LaTeX 阻塞。请注意,我还将字段editor
从更改Editor = {Land K., Michalos A., Sirgy M.},
为Editor = {Land, K. and Michalos, A. and Sirgy, M.},
。在author
和editor
字段中,请使用关键字and
来分隔作者。我还将字段中当前包含的信息分隔publisher
为单独的publisher
和address
字段。
\documentclass{llncs} % to be used with v. 2.21 (or later) of 'llncs' class
\begin{filecontents}[overwrite]{mybib.bib}
@incollection{maggino2012a,
Author = {Maggino, Filomena and Zumbo, Bruno D.},
Booktitle = {Handbook of Social Indicators and
Quality of Life Research},
Doi = {10.1007/978-94-007-2421-1_10},
Editor = {Land, K. and Michalos, A. and Sirgy, M.},
Pages = {201--238},
Publisher = {Springer},
Address = {Dordrecht},
Title = {Measuring the quality of life and the
construction of social indicators},
Year = {2012},
}
\end{filecontents}
\bibliographystyle{splncs04}
\usepackage{iftex}
\ifpdftex
\usepackage[T1]{fontenc}
\fi
\usepackage{xcolor}
\usepackage{xurl} % allow line breaks anywhere in a URL string
\urlstyle{same % optional
\usepackage[colorlinks,urlcolor=blue,citecolor=blue]{hyperref}
\begin{document}
\cite{maggino2012a}
\bibliography{mybib}
\end{document}