2

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?

Sobi
  • 125

1 Answers1

7

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:

enter image description here


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}

enter image description here


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}
Peter Grill
  • 223,288