# How to use \sloppy for just some references?

I’m using XeLaTeX within MiKTeX and also the biblatex package for the literature.

I’ve noticed that my bibliography set using \printbibliography is not set with the \sloppy option by default, which is quite good in my opinion.

What I would like to be able to do is to make \sloppy or \sloppypar only those references in the bibliography that actually need it, that means those records which get overfull \hbox. I don’t want it to be done automatically but I haven’t found a way to do it even manually. Is this even possible?

-
You could try to use the execute field in the bib-entry to insert the code (untested as you didn't provide a small example to play around with). –  Ulrike Fischer May 18 '11 at 9:12

I'd set \emergencystretch before \printbibliography:

\begingroup
\setlength{\emergencystretch}{8em}
\printbibliography
\endgroup


TeX uses \emergencystretch only when a paragraph doesn't fit with the usual parameters, so this may solve the problem. Experiment with the value of \emergencystretch.

-

As Ulrike Fischer has hinted: Use the execute special field to add \sloppy for the respective reference entries.

\documentclass{article}

\usepackage{biblatex}

\newcommand*{\displayemergencystretch}{%
Emergency stretch: \the\emergencystretch
}

\renewbibmacro*{finentry}{%
\finentry
}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
}
@misc{B02,
execute = {\sloppy},
author = {Buthor, B.},
year = {2002},
title = {Bravo},
}
@misc{C03,
author = {Cuthor, C.},
year = {2003},
title = {Charlie},
}
\end{filecontents}

\nocite{*}

\begin{document}

\sloppy

A \verb|\sloppy| paragraph~-- \displayemergencystretch

\fussy

A \verb|\fussy| paragraph~-- \displayemergencystretch

\printbibliography

\end{document}


-
I tried this but it actually did not work. No idea why not. –  josefec Jul 14 '12 at 6:57

This isn't 100% a direct answer, but as I just fought through a similar problem in my bibliography, here's my approach. It uses the ragged2e package, which defines a \RaggedRight command that still permits hyphenation -- and crucially for me at least, that includes hyphens inside urls (when using the url package). I decided to enable \RaggedRight only for @electronic items (whose main contents are a short title and a wicked-to-linebreak url), and defined my own .bst file. It's a copy/paste/modify from abbrvnat.bst, and here's the relevant excerpt:

FUNCTION {electronic}
{ output.bibitem
url empty$'skip$ { "\begin{FlushLeft}" write$newline$ } if$format.authors output new.block format.title "title" output.check year empty$ month empty$day and and 'skip$
{
new.block
format.date output
}
if$new.block format.url output note empty$ 'skip${ new.block note output } if$
fin.entry
url empty$'skip$ { "\end{FlushLeft}" write$newline$ } if$}  .bst files are tricky beasts, but the upshot of this code is, if there is a url, then I surround the contents of the entry with a FlushLeft environment, which enables \RaggedRight on this paragraph -- and only this paragraph. To use the execute field, as @UlrikeFischer suggested, you could redefine output.bibitem and fin.entry to check for the execute field and output it: % in output.bibitem execute empty$ 'skip$"\begingroup" execute * write$
% in fin.entry
execute empty$'skip$ "\endgroup" write\$


Then your execute field could contain \RaggedRight and you'd get the same effect as my code above, but for all .bib items that you annotated. It's not quite the automatic "overfull hbox" solution, but it might be useful anyway.

-
This is a regular natbib solution, not biblatex which is what @josefec is using. –  Alan Munn Jun 30 '11 at 3:32
@AlanMunn, touche, I missed that key detail...my bad! I'm not a biblatex user (yet), let alone informed-enough expert, so I can't help there, then. But maybe the ideas above are helpful for people anyway. –  Ben Lerner Jun 30 '11 at 20:51
I consider it wrong to use hyphens in URLs, for the simple reason that - can be part of a valid URL, and therefore adding a hyphen can change the URL. –  celtschk Jan 9 '12 at 7:58