# How do I get microtype's “outer spacing” to work with the xspace package?

Microtype adds extra space to the start and end of letterspaced text, configured via the \SetTracking command's "outer spacing" option. Unfortunately, xspace breaks this. For example, I define a few macros for acronyms:

\newcommand{\foo}[0]{\textsc{foo}\xspace}


The result of typesetting the text "bar \foo bar" now turns out lopsided: there is more space before "FOO" than after. Anyone know of a good workaround for this?

The following document adds lots of outer spacing to demonstrate the problem more clearly:

\documentclass{report}
\usepackage[tracking]{microtype}
\SetTracking
[outer spacing={2000*,,}]
{encoding=*, shape={sc,scit}}
{100}
\usepackage{xspace}
\newcommand{\foo}[0]{\textsc{foo}\xspace}
\begin{document}

bar \foo bar

bar \textsc{foo} bar

\end{document}


This prints

"bar      foo bar"


in the first paragraph, and

"bar      foo      bar"


in the second.

-
Welcome to TeX.SE. While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. –  Peter Grill Jun 13 '12 at 4:56

This has been fixed in microtype v2.5a (after a mere eleven months...).

-

Instead of using \xspace, you can use the trick with a terminating slash in the definition:

\documentclass{report}
\usepackage[tracking]{microtype}
\SetTracking
[outer spacing={2000*,,}]
{encoding=*, shape={sc,scit}}
{100}

\newcommand{\newfoo}{}% In case \newfoo is defined
\def\newfoo/{\textsc{newfoo}}

\begin{document}

bar \textsc{foo} bar

bar \newfoo/ bar

\end{document}

-