如何处理 .bib 文件中的连字符?

如何处理 .bib 文件中的连字符?

我使用 .bib 文件作为参考文献。有些条目的标题或摘要中有连字符,这会导致 LaTex 出错。它返回

l.22 ...y Local Adaptation and Fitness Trade,Äė
                                                 Offs}

这是 .bib 条目

@article{Hereford2009,
author = {Hereford, Joe},
doi = {10.1086/597611},
file = {:Users/remi/Documents/Biologie/Literature/BackgroundSelection/597611.pdf:pdf},
issn = {0003-0147},
journal = {The American Naturalist},
keywords = {adaptation,genetic drift,genotype-by-environment interaction,local,natural selection,population divergence,reciprocal},
number = {5},
pages = {579--588},
title = {{A Quantitative Survey of Local Adaptation and Fitness Trade‐Offs}},
url = {http://www.jstor.org/stable/10.1086/597611},
volume = {173},
year = {2009}
}

我该如何处理它而不必在整个.bib 文件中替换它们?

这是我的包和文档配置

\documentclass[
12pt,
a4paper,
oneside,
%twoside,
headinclude,footinclude,
BCOR5mm, 
]{scrartcl}

\input{structure.tex}
\usepackage{amssymb}
\usepackage{pifont}
\usepackage{hhline}
\usepackage{multirow}
\newcommand{\xmark}{\ding{55}}

\hyphenation{Fortran hy-phen-ation}

答案1

行中的破折号

title = {{A Quantitative Survey of Local Adaptation and Fitness Trade‐Offs}},

确实不是一个“简单”的破折号(ASCII 代码 45),而是一个 Unicode 编码字符(代码 U+2010)。

请注意,这是一个 LaTeX 问题,而不是 BibTeX 问题。

你可以做几件事。例如,

  • 对(U+2010)进行全局搜索,并将所有实例替换为-(U+0045)。

  • 切换到可以直接处理该字符的 TeX 引擎和字体系列U+2010。以下示例中使用了 LuaLaTeX 和 EB Garamond 字体。

在此处输入图片描述

% !TEX TS-program = lualatex
\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{mybib.bib}
@article{Hereford2009,
author  = {Hereford, Joe},
doi     = {10.1086/597611},
file    = {:Users/remi/Documents/Biologie/Literature/BackgroundSelection/597611.pdf:pdf},
issn    = {0003-0147},
journal = {The American Naturalist},
keywords= {adaptation,genetic drift,genotype-by-environment interaction,local,natural selection,population divergence,reciprocal},
number  = {5},
pages   = {579--588},
title   = {{A Quantitative Survey of Local Adaptation and Fitness Trade‐Offs}},
url     = {http://www.jstor.org/stable/10.1086/597611},
volume  = {173},
year    = {2009}
}
\end{filecontents}

\usepackage{natbib}
\bibliographystyle{apalike} % choose your bibliography style

\usepackage{fontspec}
\setmainfont{EB Garamond}

\begin{document}
\nocite{*}
\bibliography{mybib}
\end{document}

答案2

\usepackage[applemac]{inputenc}如果我的文档中有错误的输出,我可以重现它。

\begin{filecontents*}{\jobname.bib}
@article{Hereford2009,
author = {Hereford, Joe},
doi = {10.1086/597611},
file = {:Users/remi/Documents/Biologie/Literature/BackgroundSelection/597611.pdf:pdf},
issn = {0003-0147},
journal = {The American Naturalist},
keywords = {adaptation,genetic drift,genotype-by-environment interaction,local,natural selection,population divergence,reciprocal},
number = {5},
pages = {579--588},
title = {{A Quantitative Survey of Local Adaptation and Fitness Trade‐Offs}},
url = {http://www.jstor.org/stable/10.1086/597611},
volume = {173},
year = {2009}
}
\end{filecontents*}

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[applemac]{inputenc}

\begin{document}

\cite{Hereford2009}

\bibliographystyle{plain}

\bibliography{\jobname}

\end{document}

在此处输入图片描述

如果我将其改为

\begin{filecontents*}{\jobname.bib}
@article{Hereford2009,
author = {Hereford, Joe},
doi = {10.1086/597611},
file = {:Users/remi/Documents/Biologie/Literature/BackgroundSelection/597611.pdf:pdf},
issn = {0003-0147},
journal = {The American Naturalist},
keywords = {adaptation,genetic drift,genotype-by-environment interaction,local,natural selection,population divergence,reciprocal},
number = {5},
pages = {579--588},
title = {{A Quantitative Survey of Local Adaptation and Fitness Trade‐Offs}},
url = {http://www.jstor.org/stable/10.1086/597611},
volume = {173},
year = {2009}
}
\end{filecontents*}

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8,applemac]{inputenc}

\DeclareUnicodeCharacter{2010}{-}

\begin{document}

\cite{Hereford2009}

\bibliographystyle{plain}

\inputencoding{utf8}
\bibliography{\jobname}
\inputencoding{applemac} % just in case something follows

\end{document}

我得到了正确的输出。

在此处输入图片描述

最好开始对所有文档使用 UTF-8。

相关内容