Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
\def\term@ii#1{\glslink{term:\tempa}{#1}}%Two args
\def\term@end{\glslink{term:\tempa}{\tempa}}%Single args
\makeatother

It should work like this:

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

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}'
'\term{BAR}{FOO}' -> '\xspace\glslink{term:BAR}{FOO}'
share|improve this question
add comment

1 Answer

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}%
   \glslink{term:#2}{#1}%
   \endgroup
}
\makeatother

Usage:

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

'\term[FOO]{BAR}' -> '\glslink{term:BAR}{FOO}'

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.