# \alph without counters [duplicate]

When I iterate numbers with TikZ \foreach, they are stored in a macro. Now, when I need the letter corresponding to this macro, I can only convert it by saving it to a counter and then receiving it again.

\foreach \n in {1,...,10} {
\setcounter{number}{\n}
\edef\letter{\alph{number}}
}


Directly issuing

\alph{\n}


does not work. I think it would be more efficient to avoid the counter. Is it possible convert directly?

\alph expects a counter following it.

But you could resort to using clues from the internal meaning of \alph

\documentclass{article}
\usepackage{pgffor}
\makeatletter
\def\aeAlph#1{\@alph{#1}}
\makeatother

\begin{document}

\foreach \n in {1,...,10}{
\edef\letter{\aeAlph{\n}}
Letter=\letter\par
}

\end{document}


Calling texdef -t latex alph from the command line gives you

\alph:
macro:#1->\expandafter \@alph \csname c@#1\endcsname


which tells you that \alph takes the name of a counter and "looks up" its value via \csname c@#1\endcsname which is LaTeX's way of storing counter values.

• no need for \expandafter: \edef\letter{\@alph{\n}} will do Nov 24 '13 at 20:59
• @cgnieder Just fixed that. Nov 24 '13 at 20:59
• When the code exported to a package nonetheless, there is even no need to \makeatletter, so \alph can just be replaced directly with its @-variant.
– XZS
Nov 24 '13 at 21:03
• @XZS I'm not sure what context you're using this in. If you remove the \makeatletter business from my MWE, it will fail. If you're in a package, then most likely \makeatletter has already been called; and then, as you say, it's not necessary (or even possibly destructive if you include the \makeatother). Nov 24 '13 at 21:07
• @A.Ellett \foreach\n in{1,...,10}{Letter=\aeAlph{\n}\par} is sufficient: why the \edef? Nov 25 '13 at 8:46