# How to prevent getting a space after an abbreviation using the abbrevs package?

If I use the abbrevs package and define a \newabbrev using the following code

\newabbrev\gb{Great Britain}


and use it in the following example (taken from the xspace package documentation):

\gb, a small island off the coast of France


I get "Great Britain , a small island off the coast of France", which has a superfluous space inserted before the comma

In the xspace package documentation, they also defines an abbreviation for "Great Britain", but using \newcommand instead of \newabbrev, and they are also having the problem with the superfluous space before the comma. They solve it by putting the macro \xspace after the full name, i.e. Great Britain\xspace. When I follow their example and redefine the abbreviation as

\newabbrev\gb{Great Britain\xspace}


it has the opposite effect, i.e., an extra superfluous space is added before the comma (which I can't illustrate here). I have also tried to insert \@ before xspace (which I found out you could do in this quite similar question), but that has no effect.

Any idéa of how to prevent an abbreviation defined with \newabbrev to insert a space after the abbreviation has been used? The reason I'm using the abbrevs package is because it provides a way of using one expansion of the abbreviation the first time it is used, and another expansion the resting times. I could just as well change to some other package that allowed me to do the same thing.

-
Said simply, none of the example in the documentation of abbrevs works as advertised. :( –  egreg Jun 14 '12 at 13:00

This seems to be a bug in the abbrevs package. It's supposed to test the following token of the abbreviation against the tokens in \nospacelist and insert \space if it is not part of \nospacelist. However, the macro responsible for the test has a wrong if:

\newcommand\maybe@space@{%
\@tempswatrue
\expandafter   \@tfor
\expandafter \reserved@a
\expandafter :%
\expandafter =%
\nospacelist
\do \t@st@ic
\if@tempswa
\space
\fi
}


It tests if \@tempswa is true but the macro \t@st@ic (which is defined in latex.ltx and does the actual testing here) sets \maybe@ic to false:

\def \t@st@ic {%
\expandafter\let\expandafter\reserved@b\expandafter=\reserved@a\relax
\ifx\reserved@b\@let@token
\maybe@icfalse
\@break@tfor
\fi
}


So a redefinition of \maybe@space@ solves the issue:

\documentclass{article}
\usepackage{abbrevs}
\newabbrev\gb{Great Britain}

\makeatletter
\renewcommand\maybe@space@{%
% \@tempswatrue % <= this is in the original
\maybe@ictrue % <= this is new
\expandafter   \@tfor
\expandafter \reserved@a
\expandafter :%
\expandafter =%
\nospacelist
\do \t@st@ic
% \if@tempswa % <= this is in the original
\ifmaybe@ic % <= this is new
\space
\fi
}
\makeatother
\begin{document}

\gb, a small island \\
\gb is an island

\end{document}


-
Isn't it easier to use xspace? Maybe something like \let\maybe@space@\xspace –  Marco Daniel Jun 14 '12 at 17:55
@Marco Sure, that works just as fine, at least for the abbreviations (I haven't done much testing and never used abbrevs before...). It's still a bug in the package, though. –  cgnieder Jun 14 '12 at 17:59
Of course. I wanted to provide an alternative approach ;-). –  Marco Daniel Jun 14 '12 at 18:06
@Marco your's is without doubt the user-friendlier one :) I filed a bug report, BTW. –  cgnieder Jun 14 '12 at 18:27
@cgnieder: Thanks, that seems to do the trick. –  StrawberryFieldsForever Jun 15 '12 at 9:50