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?

  • 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 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
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. :)

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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