[Tex/LaTex] Defining starred versions of commands (* macro)

macrosstarred-version

I would like to define a *'d version of a command, something like

\newcommand{\foo}{blah}
\newcommand{\foo*}{blahblah}

If I try to do this, LaTeX complains that I'm trying to redefine \foo, so I guess I need to do something special to handle *s. But what?

Best Answer

See this entry in the UK TeX FAQ.

The "elegant" way is to use the suffix package (which requires eTeX):

\documentclass{article}

\usepackage{suffix}
\newcommand\foo{blah}
\WithSuffix\newcommand\foo*{blahblah}

\begin{document}

\foo

\foo*

\end{document}
Related Question