4

In (La)TeX, is there a way to redefine the command (that is "<backslash> <space>")?

I have lots of texts where is used as non-breakable space after "." characters like in Dr.\  or Mr.\  and I want to make that space in the output just a bit shorter than the normal space.

Please note, I do not want to change the texts, but rather redefine the macro in the preamble. Is this possible?

  • 3
    The \ macro inserts ordinary (breakable) space, not non-breakable space. For non-breakable space, you should use (and suitably modify, as necessary) the ~ symbol. – Mico Oct 24 '14 at 5:59
9

I would strongly recommend against this, but it can be done. The command is a primitive meaning 'a normal space' so shows up in various places, in particular the definition of \nonbreakspace. Thus a 'safe' redefinition of must at least deal with that:

\documentclass{article}
\let\hardspace\ %
\DeclareRobustCommand*\nobreakspace{\leavevmode\nobreak\hardspace}
%\let\ ~
\begin{document}

Some text to show that this is now a non-breaking space in a demo:
Mr.\ Black.

\let\ ~

Some text to show that this is now a non-breaking space in a demo:
Mr.\ Black.

\end{document}

I've commented out \let\ ~ in the preamble in the above so that the demo shows the effect of the change, but in a real case you'd apply it to everything. As pointed out by others, you really should use the correct mark-up to differentiate between a 'forced' normal space and a non-breaking space.

  • As the poster I have to explain what the reason for my question was: I write my papers in Markdown and convert them with pandoc via LaTeX to pdf or to html. Markdown has basckslash-space as non-breakable space and I though that the same is in TeX, but of course not: So pandoc converts the Markdown-backslash-space into TeX-tilde, so if anything I redefine tilde in LaTeX as a little narrower space. Done that and it works great. But your answer is of course perfectly valid for the backslash-space redefinition. – halloleo Nov 1 '14 at 1:24
0

For example, starting from the definition of ~:

\makeatletter
\def\hallospace{\penalty\@M \kern0.3em} % say, 0.3em
\let\oldspace=\ %
\let\ =\hallospace
\makeatother

(And remember to use ~ as an unbreakable space in the future).

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.