Assuming you're not using any packages redefining \cite
& friends, here's a solution. (Andrey Vihrov's comments about \mbox
es and \sloppy
still apply.)
\documentclass[11pt]{article}
\makeatletter
% \def\@cite#1#2{[{#1\if@tempswa , #2\fi}]}% OLD
\def\@cite#1#2{[{#1\if@tempswa ,~#2\fi}]}% NEW
\makeatother
\begin{document}
Some text that is just long enough to create an unwanted line break \cite[p.~99]{test}.
\begin{thebibliography}{9}
\bibitem{test} A bibitem.
\end{thebibliography}
\end{document}
EDIT: Replaced \penalty\@m\
with ~
in the definition of \@cite
.
You have a number of better alternatives.
First. Package verbatim
\documentclass{article}
\usepackage{verbatim,color,lipsum}
\newenvironment{blockcode}
{\leavevmode\small\color{blue}\verbatim}
{\endverbatim}
\begin{document}
\lipsum*[2]
\begin{blockcode}
alias vi="vim"
\end{blockcode}
\lipsum*[3]
\end{document}
Pros: easy. Cons: not really customizable.
Second. Package fancyvrb
\documentclass{article}
\usepackage{fancyvrb,color,lipsum}
\DefineVerbatimEnvironment{blockcode}
{Verbatim}
{fontsize=\small,formatcom=\color{blue}}
\begin{document}
\lipsum*[2]
\begin{blockcode}
alias vi="vim"
\end{blockcode}
\lipsum*[3]
\end{document}
Pros: very customizable. Cons: less easy to learn how to manage the definitions.
Third. Package listings
\documentclass{article}
\usepackage{listings,color,lipsum}
\lstnewenvironment{blockcode}[1][]
{\lstset{language=Bash,
columns=fullflexible,
basicstyle=\small\ttfamily,
keywordstyle=\color{blue},
}}
{}
\begin{document}
\lipsum*[2]
\begin{blockcode}
alias vi="vim"
\end{blockcode}
\lipsum*[3]
\end{document}
Pros: keyword coloring for the supported languages. Cons: doesn't support UTF-8
Best Answer
Consider using inline verbatim:
\verb|is_terminating()|
. For some discussion on the different verbatim environments, read this.The
listings
package also provides a form of inline verbatim through its inline code macro\lstinline
. It works uses the same interface as inline verbatim with delimiters defining the inline code range:\lstinline!is_terminating()!
.