1

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}}}
  • 2
    I suppose you can use a command like \mbox{\cite{Args}} But since you didn't gave a MWE I haven't tested that and havent seen such a problem neither... – koleygr Jan 29 '18 at 1:10
  • Thanks, this does the job. I'm surprised if this is not implemented as a standard feature in biblatex. – mavzolej Jan 29 '18 at 6:17
  • 1
  • 1
    How can \cite{ref13-ref17} even work? biblatex will treat this as a single entry. – David Purton Jan 29 '18 at 9:43
  • 1
    @moewe, good call! I missed that. I'll fix it tomorrow. Can't undelete from phone. – David Purton Jan 29 '18 at 13:06
2

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

  • I am sorry! Someone has changed the code of my question and the meaning has been changed completely :( Please see now. The question is about the place in the text where the citation is appearing. – mavzolej Jan 29 '18 at 6:07
  • No worries! Actually, I can probably change my answer. I think you can probably still automate it without resorting to an mbox – David Purton Jan 29 '18 at 7:03
  • 1
    Starting with biblatex 3.11 (as of now unreleased) biblatex will automatically normalise page ranges in the postnote. So the trick with using comp ranges and disabling the compression by modifying the counters won't be needed any more. – moewe Jan 29 '18 at 8:16

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.