3

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?

Torbjørn T.
  • 206,688
fYre
  • 253
  • 1
  • 3
  • 6
  • 9
    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 01 '14 at 02: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 01 '14 at 03:23

2 Answers2

5

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

enter image description here

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

osjerick
  • 6,970
5

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.

Oleg Domanov
  • 1,496