6

I need to hyphenate a long lastname with a hyphen in it in a reference, e.g.:

@article{LastHyphenName:2013xy,
author = {Longlast-Namewithhyphen, Antonio and Anotherlastname, David},
title = {{How to hyphenate a reference that has a lastname with a hyphen?}},
journal = {Contributions To the TeX Stackexchange},
year = {2013},
volume = {2},
pages = {539--557},
}

I read in Line breaking (or hyphenation?) of references in apalike that one can hyphenate even a word from the .bib file with \hyphenation, but words that already have a hyphen cannot be hyphenated, or you do something like it's done in this SO thread. However, I think there has to be another way than manipulating the BibTeX entries.

Any solutions for this?

EDIT:

  • I'm editing my library externally and it is still growing as I'm adding new references to the bibliography during the writing process, thus substituting the hyphens with a shorthand in the final (exported) .bib file is not very efficient time-wise.

  • Also, my bibliography has a ton of authors with their last names being of hispanic origin which would mean time-costly, manual editing of the .bib file (I know that hispanic last names are normally not connected with a hyphen, but the hyphens is internationally introduced to avoid confusion).

I'm writing my thesis with \classicthesis, so the preamble is much more complex, but here's a MWE:

\documentclass{scrbook} % KOMA-Script article
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage[round]{natbib}
\usepackage{fontspec}
\usepackage{xunicode}
\setmainfont[Mapping=tex-text]{Minion Pro}
\usepackage[english]{babel}


\begin{document} 
\hyphenchar\font=\string"7F

\parbox{1cm}{\cite{LastHyphenName:2013xy}}

\bibliographystyle{kluwer} 
\bibliography{lib}

\end{document}

.bib file

@article{LastHyphenName:2013xy,
author = {Longlast-Namewithhyphen, Antonio and Anotherlastname, David},
title = {{How to hyphenate a reference that has a lastname with a hyphen?}},
journal = {Contributions To the TeX Stackexchange},
year = {2013},
volume = {2},
pages = {539--557},
}

Changing the hyphenchar is not working.

  • 3
    My impression is that changing the names (adding a hyphen) adds to confusion. One should always use the name: is "Paulo-Roberto Massa-Cereda" the same author as "Paulo Roberto Massa Cereda" or not? (Paulo will forgive me for using his name.) – egreg Feb 19 '13 at 10:55
  • 1
    You could change the hyphenchar. See egreg's answer here http://tex.stackexchange.com/questions/63232/why-can-words-with-hyphen-char-not-be-hyphenated/63234#63234 – Ulrike Fischer Feb 19 '13 at 11:03
  • What is your bibliography style? Do you use last names in the running text (to refer) or they only appear in the bibliography section? IMHO it is not a good idea to include long lastnames in the running text, you can make shorter keys or just use numbers as IEEE style, e.g. [1]. – Aydin Feb 19 '13 at 11:05
  • @Aydin I'm in geosciences, and generally the usage of shorted keys or numbers is not common. – Paglia Orba Feb 19 '13 at 12:19
  • 1
    @egreg OK, but the hispanic authors' names are spelled like this in the actual paper. Also, there's also last names that actually contain two names connected with a hyphen, e.g. married couples who paired their last names. – Paglia Orba Feb 19 '13 at 12:31
  • @UlrikeFischer I like the question of topskip, but changing the \hyphenchar doesn't seem to work with a reference. – Paglia Orba Feb 19 '13 at 12:35
  • @PagliaOrba: It should work in a reference too - if you change the hyphenchar of the correct font, and if you use T1-encoding (and if nothing else prevents hyphenation). But without a complete example nobody can tell you what's going on in your document. – Ulrike Fischer Feb 19 '13 at 12:43
  • You could also try out biber. With it it is possible to manipulate entries and replace strings. http://tex.stackexchange.com/questions/83943/how-to-replace-a-given-string-in-a-bibliography-with-biblatex/83968#83968 – Ulrike Fischer Feb 19 '13 at 12:46
  • I use xunicode. I added a MWE. – Paglia Orba Feb 19 '13 at 13:30
  • I set my bibliography \RaggedRight because I basically gave up on decent justification with all those long URLs in paragraphs I couldn't change. I don't think it looks bad. Bibliographies look kinda "ragged" anyway. Everything looks better than \sloppy. Another possibility would be to use \small for your whole bibliography. People are used to this because it's a common trick to cheat more space into a paper and it gives TeX and microtype more degrees of freedom to squeeze long stuff into one line. – Christian Feb 19 '13 at 13:40
  • 1
    @Christian I just used the parbox to demonstrate that the hyphenation (i.e. line break) is not working by changing the hyphenchar. – Paglia Orba Feb 19 '13 at 13:44
  • Oh so you problem is not the bibliography but the main text? – Christian Feb 19 '13 at 13:51
  • 1
    it's about hyphenating a reference in the main body text and the reference is not wrapped correctly because the author has a lastname with a hyphen in it. it's all in the the question :) – Paglia Orba Feb 19 '13 at 14:00
  • In my case it appears this happens if the first name has a hyphen in it. Adding \hspace{0.01cm} before this name was the solution. – Maria S. Jul 26 '19 at 15:17

3 Answers3

7

with package babel use

\defineshorthand{"=}{\penalty1000-\hskip0pt}

and then

author = {Longlast"=Namewithhyphen, Antonio and Anotherlastname, David},
  • This would be one solution. But I edit my bibliography externally (like BibDesk) and the bibliography is still changing during the writing process, thus, I would have to edit the bib file every time after I added a new reference to the bibliography (the bibliography has tons of spanish/hispanic authors with hypenated last names). – Paglia Orba Feb 19 '13 at 10:11
  • @PagliaOrba Two solutions: (1) have the name as written here in BibDesk – I do that to some extent (although I use LaTeX commands). (2) Write a script to post-process your .bib file accordingly and include it into your build process. Do not manually edit generated files (such as the .bib file in this case). BibDesk also has a script hook for saving files but I don’t know how to use that and if it helps here. – Konrad Rudolph Mar 19 '13 at 19:47
4

I use \hyp{} from the hyphenat package and have Biber replace all hyphens in the author field with it. Put this in your preamble:

\usepackage{hyphenat}
\DeclareSourcemap{
  \maps[datatype = bibtex]{
    \map{
     \step[fieldsource = author, match = \regexp{-}, replace = \regexp{\{\\hyp\{\}\}}]
    }
  }
}

For some reason, Biber started to include abstract and annotation in the .bbl file after that, which may give you issues with special characters. To solve that, you can include this in your .biber.conf:

<?xml version="1.0" encoding="UTF-8"?>
<config>
<sourcemap>
  <maps datatype="bibtex" map_overwrite="1">
    <map>
      <map_step map_field_set="abstract" map_null="1"/>
      <map_step map_field_set="annote" map_null="1"/>
    </map>
  </maps>
</sourcemap>
</config>
1

Use two hyphen signs.

For instance, author = {Longlast--Namewithhyphen, Antonio and Anotherlastname, David}

It's not required to use any additional packages.