# How to put a non-breaking space in \cite

How do I put a non-breaking space inside a \cite macro with several citations? \cite{ref1,~ref2} causes an error. If I leave the space out, one is inserted and this is causing the citation to span two lines. I am using bibstyle plain.

-
Why do you want an unbreakable space after a comma? A comma at the end of a line is a perfect position for a line break! –  Marc van Dongen Jan 25 '12 at 0:35
I am using bibstyle plain and I end up with [1, 2,\n 3, 4] which looks bad. –  jaybee Jan 25 '12 at 10:16
@jaybee: well, when you have 4 references in one bracket (which is generally correct), I suggest to leave it as is, i.e. [1, 2,\n 3, 4], because the bracket is long and the lines would be too empty/full. The only other possibility is to re-phrase the text slightly, but this should be done in the final version. –  tohecz Jan 25 '12 at 23:38

If it is an isolated thing (i.e. you need to do it once in your document), put \hbox{\cite{ref1, ref2}}

-

have you tried the option [space] with the package cite ?

-
This is more of a question/comment than an answer. –  qubyte Jan 24 '12 at 10:59
@MarkS.Everitt On the other hand, it is somehow an answer (and probably a correct answer), just written down with a question mark in the end... –  tohecz Jan 25 '12 at 23:39
@tohecz: It's rude to answer a question with a question. ;) –  qubyte Jan 26 '12 at 1:53

Assuming you don't use any packages that modify \cite & friends, a general solution is to change the definition of \@citex, namely, to replace the breakable space (accompanied by a penalty of 1000) with a non-breakable space. (Note: For convenience, I'm using the etoolbox package to do so.)

\documentclass{article}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@citex}{%
,\penalty\@m\ %
}{%
,~%
}
\makeatother

\begin{document}

XXXXXXX XXXXXXX XXXXXXX XXXXXXX XXXXXXX XXiiiiiii \cite{x,y}.

\begin{thebibliography}{9}
\bibitem{x} A bibitem.

\bibitem{y} Another bibitem.
\end{thebibliography}

\end{document}

-