# Defining Commands With Multiple Meaning

I have defined a new command in my source code:

\newcommand{\IN}{interface}


which prints out interface, but there are times where I would like it to print Interface (with a capital I) or interfaces instead, how can I do this without defining 2 more new commands?

• Type interface'. It's easier. – egreg Dec 31 '13 at 22:25
• Related to egreg's comment, just self-publicity :P, here are two answers related to this topic: Writing readable LaTeX and Speedy LaTeXing. – Manuel Jan 1 '14 at 2:34
• Though of course you can do just about anything with macros, the best way to use them is to encapsulate material that is either complicated (involving some algorithmic or typesetting considerations) or changeable (such as semantic markup taking the place of explicit formatting). Replacing simple, if common, words is probably obfuscating (unless, of course, "interface" is a changeable semantic term). – Ryan Reich Jan 1 '14 at 3:23

Something like this?

# Code

\documentclass{article}
\newcommand*{\IN}[1][0]{%
\ifnum#1=0 interface\fi
\ifnum#1=1 Interface\fi
\ifnum#1=2 interfaces\fi
}
\begin{document}
\IN, \IN[1], \IN[2]
\end{document}


# Output

However, as Egreg said, type 'interface' is easy. :)

You may also define a starred command for capitals and simply append s for plurals:

\documentclass{article}
\makeatletter
\DeclareRobustCommand*{\IN}{%
\@ifstar{Interface}{interface}}
\makeatother
\begin{document}
Singular: \IN, \IN*
\par Ways to write plurals: \IN s, \IN{s}, \IN{}s, \IN*s
\end{document}


\DeclareRobustCommand is needed to make the command not fragile, so you don't need to \protect` it in titles, etc.