I'm looking at the source code of a book where I found:
D.{\mbox{$~$}}Knuth
What's the purpose of this?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityIn the \mbox
, the space will not be compressed (nor expanded, for that matter) by line-width considerations.
As Manuel points out and egreg emphasizes, the construct \mbox{$~$}
"is really useless," as it is functionally indistinguishable from and less efficient than \mbox{ }
. Nonetheless, I use it in the MWE below to most directly answer the OP's original question. Were the reader to mimic the technique, please use \mbox{ }
.
\documentclass[10pt]{book}
\begin{document}
\noindent\hrulefill
\def\dx{4.2in}
\hspace{\dx}D.{\mbox{$~$}}Knuth
\hspace{\dx}D.~Knuth
\def\dx{0in}
\hspace{\dx}D.{\mbox{$~$}}Knuth
\hspace{\dx}D.~Knuth
\end{document}
To see this on a grand scale, here I use \sloppy
to give LaTeX all the rope it needs to hang itself:
\documentclass[10pt]{book}
\sloppy
\begin{document}
\noindent\hrulefill
\def\dx{3.64in}
\hspace{\dx} D.{\mbox{$~$}}Knuth rocks!
\hspace{\dx} D.~Knuth rocks!
\end{document}
D.\mbox{ }Knuth
. Even if you want the tie, there's no need for $..$
, just \mbox{~}
.
\mbox{$~$}
is really useless and \mbox{ }
is much better (if one really wants a non expanding space.
You can define a new command that uses the normal interword space with the possibility to shrink it if the line needs shrinking, but not stretching it. It's necessary to add \@
in order to properly set the space factor (the \
command does it implicitly).
In the example I use the low level \hbox spread
command in order to show the effect; it typesets the text in a box stretched (or shrinked) by the stated amount.
\documentclass{article}
\DeclareRobustCommand{\nostretchspace}{%
\nolinebreak\@\hspace{\fontdimen2\font minus \fontdimen4\font}%
}
\begin{document}
\hbox spread 2cm{D.~Knuth wrote \TeX}
\hbox spread 2cm{D.\nostretchspace Knuth wrote \TeX}
\hbox spread -3pt{D.\mbox{ }Knuth wrote \TeX}
\hbox spread -3pt{D.\nostretchspace Knuth wrote \TeX}
\end{document}
Note that \mbox{ }
doesn't give a good result in the third line.
\sim
? I think it's a simple mistake because he doesn't know that~
just works. The same I've seen inputing{$\left.\right.$}
between\\
so the error doesn't appears.\,
is better anyhow.)