Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spacing issues with xspace

Let's say my macro is \newcommand{\k}{king\xspace}. Then the spacings in "... said the \k." will be fine. But what do I do if I want no spacing in the middle of \k\k.? I want "kingking." not "king king."

Is there a way to do this?

like image 660
queen Avatar asked Feb 23 '11 17:02

queen


3 Answers

\unskip removes any previous skip inserted (which includes a space), so using \K\unskip\K for the odd occasions when you want to remove it could also suffice:

enter image description here

\documentclass{article}
\usepackage{xspace}% http://ctan.org/pkg/xspace
\newcommand{\K}{king\xspace}
\begin{document}
Here is the \K. Here is the \K\K. Here is the \K\unskip\K.
\end{document}
like image 151
Werner Avatar answered Sep 20 '22 00:09

Werner


The whole point of \xspace is to add a space between words and not add space before punctuation. So, if you don't want spaces between the two uses of the macro don't use \xspace. But, of course this will require you to you to use a {} at the end:

\documentclass{article}
\newcommand{\K}{king}%

\begin{document}
At end of sentence \K.\par
In between \K\K{} you want one long word.
\end{document}
like image 44
Peter Grill Avatar answered Sep 24 '22 00:09

Peter Grill


The xspace documentation says that the way to handle this is with {} immediately after your macro invocation:

 \k{}\k

Recent versions of xspace also permit you to specify additional macros that should not generate space after your macro:

 \xspaceaddexceptions{\k}

I wanted to use this for \xspaceaddexceptions{\textsuperscript}, but it didn't work for me since my shop has xspace v1.06 and that's not recent enough. So I used:

 \newcommand{\unix}{\textsc{unix}\xspace}
 \unix{}\textsuperscript{\textregistered}

Which worked fine except in bold section headings, since there's no bold small caps in the font that I'm using. Sigh...

like image 26
Ron Bandes Avatar answered Sep 20 '22 00:09

Ron Bandes