[Tex/LaTex] Avoid line break when using \cite{} and biblatex

biblatexcitingline-breaking

How can I enforce latex not to make line breaks of this form?

Assume, this code

First line~\cite{ref13,ref14,ref15,ref16,ref17}. Second line.

Produces the following output (line break because of the end of the line):

First line [13-
17]. Second line

While I would like to enforce smth like this:

First
line [13-17].
Second line

I'm using biblatex. But I would also be interested to know the answer for the case of using the standard latex bibliography.

UPDATE

A brute-force solution, thanks to @koleygr:

 \newcommand{\mcite}[1]{\mbox{\cite{#1}}}

Best Answer

Update

With new info in the question, this seems like a good answer for biblatex. For standard bibliographies, you would need to alter the relevant bst file to replace the -- with \textendash, but this is always a pain.

\documentclass{article}
\usepackage[style=numeric-comp]{biblatex}
\addbibresource{biblatex-examples.bib}
\DefineBibliographyExtras{english}{%
  \renewrobustcmd*{\bibrangedash}{\textendash}
}
\begin{document}
\fbox{\parbox{3.8cm}{%
\begin{sloppypar}
Filler text filler text \cite{baez/article,bertram,doody,gillies}.
\end{sloppypar}

\noindent\textbf{cf.\@ default behaviour}

Filler text filler text [1--4].}}
\end{document}

enter image description here


Your question is a little unclear, but I assume you are referring to page ranges?

Both - and -- contain (I think) an implied \penalty\hyphenpenalty after them, so they will break as you are seeing.

With default settings for both standard bibliographies and biblatex, you could use \cite[13\textendash 17]{entry}, which won't break.

If I where using biblatex I'd use \mkcomprange (see Table 13 in the manual for set up) and ensure \bibrangedash is not breakable (by default in English it is defined as \textendash\penalty\hyphenpenalty).

(Note: This doesn't seem to work with xelatex which allows a break after \textendash. Perhaps someone else can help with this case.)

Something like this:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{book,
  author = {Author},
  title = {Title}
}
\end{filecontents}
\usepackage[style=authortitle]{biblatex}
\addbibresource{\jobname.bib}
\setcounter{mincompwidth}{1000}
\DefineBibliographyExtras{english}{%
  \renewrobustcmd*{\bibrangedash}{\textendash}
}
\DeclareFieldFormat{postnote}{\mkcomprange[{\mkpageprefix[pagination]}]{#1}}
\begin{document}
\hsize 4cm

\begin{sloppypar}
\cite[13-17]{book}
\end{sloppypar}

\noindent
\textbf{cf.\@ default behaviour}

\DeclareFieldFormat{postnote}{\mkpageprefix[pagination]{#1}}
\cite[13--17]{book}

\noindent
\textbf{and with} \verb+\textendash+

\begin{sloppypar}
\cite[13\textendash 17]{book}
\end{sloppypar}

\end{document}

enter image description here

Related Question