# How to add suffixes to \newcommands in TEX?

I have defined a term using a new command as follows:

\newcommand{\ourmethod}{G-MM\xspace}

Now I'd like to add a suffix to the term that I just defined, e.g. I'd like to use "\ourmethod" to say G-MMs (note that there is an "s" added to the term). How can I do this in LATEX?

• Under what conditions do you want \ourmethod to print G-MM or G-MMs? You can, of course, do \renewcommand{\ourmethod}{G-MMs}. – Werner Dec 11 '15 at 5:13
• It would be easier if you had not used xspace. As it is, \ourmethod{}s wil do the right thing most of the time, but having \xspace{} before the s will break any font specified kerns between the last two letters, and affect possible hyphenation. – David Carlisle Dec 11 '15 at 7:44
• – Peter Grill Dec 11 '15 at 9:04
• @Werner: I would like to be able to add arbitrary suffixed to the command without having to define a new command for every new suffix. So, I'd like to keep \ourmethod to translate to G-MM. – Sobi Dec 11 '15 at 16:07

I think you should follow David's recommendation. But, if you still want to use xspace (or even if you decide not to), I would suggest you define both the singular and plural once with something like:

\DefineTerms{ourmethod}{G-MM}


which creates the two macros: \ourmethod and \ourmethods:

Alternativly, you could define the command where you provide the suffix as an optional parameter in square brackets:

\newcommand{\ourmethod}[1][]{G-MM#1\xspace}


## Code: Using etoolbox

\documentclass{article}
\usepackage{etoolbox}
\usepackage{xspace}

\newcommand{\DefineTerms}[2]{%
\csdef{#1}{#2\xspace}%
\csdef{#1s}{#2s\xspace}%
}

\DefineTerms{ourmethod}{G-MM}

\begin{document}
\verb|\ourmethod|: \ourmethod

\verb|\ourmethods|: \ourmethods
\end{document}


## Code: Without etoolbox:

\documentclass{article}
\usepackage{xspace}

\newcommand{\DefineTerms}[2]{%
\expandafter\newcommand\csname#1\endcsname{#2\xspace}%
\expandafter\newcommand\csname#1s\endcsname{#2s\xspace}%
}

%\newcommand{\ourmethod}{G-MM\xspace}
\DefineTerms{ourmethod}{G-MM}

\begin{document}
\verb|\ourmethod|: \ourmethod

\verb|\ourmethods|: \ourmethods
\end{document}


## Code: Optional Parameter

\documentclass{article}
\usepackage{xspace}

\newcommand{\ourmethod}[1][]{G-MM#1\xspace}

\begin{document}
\verb|\ourmethod|: \ourmethod

\verb|\ourmethod[s]|: \ourmethod[s]
\end{document}