Close to numbered macros in LaTeX

I think it is unfortunate that one cannot use numbers in macro names in \LaTeX. Using the xkeyval package, I could obtain something close to it:

\documentclass{article}

\usepackage{xkeyval}

\makeatletter
\define@cmdkey[GRA]{small}{i}{}

\newcommand{\atest}[1]{
  \setkeys[GRA]{small}{#1}%
  \ifcase\cmdGRA@small@i
  \or % i = 1
  A
  \or % i =2
  B
  \or % i =2
  C
  \fi
}
\makeatother

\begin{document}

\atest{i=1} % prints A

\atest{i=2} % prints B

\atest{i=3} % prints C

\end{document}
Advertisements
This entry was posted in LaTeX and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s