7

I am using a .bib files for my references. Some entries have a hyphen in the title or in the abstract which mess up with LaTex. It returns

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

Here is the .bib entry

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

How can I deal with it without having to replace them in the whole .bib file?

Here are my packages and document configuration

\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
    How was the bib entry created -- by typing all words at a keyboard, or by copying and pasting from some source? Are you sure these dashes are "simple" dashes, or could they be non-ASCII-encoded en-dash, em-dash, or math-minus signs? – Mico Feb 2 '16 at 20:45
  • The bib file was automatically produced by Mendeley. The symbol is short and is a hyphen if I am not mistaken (which I failed to notice before). – Remi.b Feb 2 '16 at 21:25
  • 1
    If the dash character in question were a simple, i.e., ASCII-encoded, character (decimal "45", hex "2D"), BibTeX and LaTeX would not be complaining. The only possibility left, then, is that the character -- even though it may 'look like' a dash -- is not ASCII-encoded; what it really is is anyone's guess at this point. Is there something keeping you from doing a global search-and-replace on the character? – Mico Feb 2 '16 at 21:27
  • No, I could just do search-and-replace but I thought that it was a good opportunity to learn about LaTex by finding "LaTex-way" around this problem. But well...if there are none, then I will just delete my post I guess! – Remi.b Feb 2 '16 at 21:29
  • 1
    It would help if you posted a couple of bib entries that contain offending dash-like characters. – Mico Feb 2 '16 at 21:30
6

The dash character in the line

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

is indeed not a "simple" dash (ASCII code 45), but a unicode-encoded character (code U+2010).

Observe that this is a LaTeX issue, not a BibTeX issue.

You can do several things. E.g.,

  • Do a global search of (U+2010) and replace all instances with - (U+0045).

  • Switch to a TeX engine and a font family that can handle the character U+2010 directly. In the following example, LuaLaTeX and the EB Garamond font are used.

enter image description here

% !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}
| improve this answer | |
4

I can reproduce the faulty output if I have \usepackage[applemac]{inputenc} in my 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[applemac]{inputenc}

\begin{document}

\cite{Hereford2009}

\bibliographystyle{plain}

\bibliography{\jobname}

\end{document}

enter image description here

If I change this to

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

I get correct output.

enter image description here

It's best if you start using UTF-8 for all of your documents.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.