# Help with a custom-command: Space should not be inserted

I have a problem with a command i make for a specific glossary:

\newcommand{\term}[4]{\glslink{term:#1}{#2}}
\makeatletter
\def\term#1{\def\tempa{#1}\futurelet\next\term@i}% Save first argument
\def\term@i{\ifx\next\bgroup\expandafter\term@ii\else\expandafter\term@end\fi}%Check brace
\makeatother


It should work like this:

'\term{BAR}' -> '\glslink{term:BAR}{BAR}'


It works fine except of the space that is entered before the Result.

It seems to work like that

'\term{BAR}' -> '\xspace\glslink{term:BAR}{BAR}'

-

Your example works fine on my TeXLive installation. Please post a complete compilable example so we can have a closer look. The space seems not to come from your code anyway. Also your first line seems to be unrelated to the example and should be removed.

You can achieve the same using:

\makeatletter
\newcommand*{\term}[2][\@tempa]{%
\begingroup
\def\@tempa{#2}%
\endgroup
}
\makeatother


Usage:

'\term{BAR}' -> '\glslink{term:BAR}{BAR}'


I assume here that \glslink is happy inside a group. Otherwise the code is a little bit more complicated.