# Unusual numbering: combine alph, Alph, arabic

I would like to have an unusual numbering aAa going as follows:

 0 -> *
-------------------------
1 -> a
2 -> b
...
25 -> y
26 -> z
-------------------------
27 -> A
28 -> B
...
51 -> Y
52 -> Z
-------------------------
53 -> 1
54 -> 2
55 -> 3
...


Since it might be used in page numbering or similar sensitive contexts, the command \@aAa should be introduced so that \pagenumbering{aAa} works (I'm not going to use it this way but I still need it). As well, a fully expandable solution is welcomed.

-
Remark: I have an answer myself, but it is quite heavy and definitely not expandable. I'm searching for a simpler solution. –  tohecz Jan 1 '13 at 19:14

With the use of the already defined macros that return the alphabetical expression of a counter, this seems pretty straightforward.

## Why \aAa and \@aAa?

Firstly, what is the difference between \<number style> and \@<number style>?

Whereas the argument of \@<number style> is a “number” which can be a counter, a \numexpr or just 42 , the argument of \<number style> has to be the name of a LaTeX counter, to be more precise, a name of a counter defined by \newcounter{<name>} (which defines a TeX counter named \c@<name>).

It must not be a <number> unless, of course, someone defined a counter named \c@<number>, but then we could get the <number style> expression of \c@<number> but not of <number>!

## \aAa

The usual definition of \<number style> is:

\def\<number style>#1{\expandafter\@<number style>\csname c@#1\endcsname


I have defined \aAa in the same way, which brings us to \@aAa.

## \@aAa

The pretty straightforward part is that I have used a few simple if-conditions, in pseudo code:

if counter = 0 then
*
else if counter < 27
alph(counter - 26)
else if counter < 53
Alph(counter - 52)
else
counter - 52
end if


where alph(arg)/Alph(arg) returns a/A for arg = 1, b/B for arg = 2, and so on.

Which “function” (read: macro) in LaTeX does this? The \@<number style> ones do. \<number style>{<arg>} would return the value of a counter named \c@<arg> (which probably doesn’t even exist).

(The macro \pagenumbering{<arg>} redefines \thepage as \@<arg>\c@page.)

## Code

\documentclass{article}
\makeatletter
\def\aAa#1{\expandafter\@aAa\csname c@#1\endcsname}% LaTeX
\def\@aAa#1{%
\ifnum#1=0*%
\else\ifnum#1<27
\@alph{#1}%
\else\ifnum#1<53
\@Alph{\numexpr#1-26\relax}%
\else
\@arabic{\numexpr#1-52\relax}%
\fi
\fi
\fi
}
\makeatother

\usepackage{pgffor}% for the \foreach loop
\pagenumbering{aAa}
\newcounter{aAatest}
\renewcommand*{\theaAatest}{\aAa{aAatest}}
%\renewcommand*{\theaAatest}{{\fboxsep=0pt\fbox{\aAa{aAatest}}}}% test for spurious spaces
\usepackage[T1]{fontenc}% for correct \meaning output
\begin{document}
0: \theaAatest\par\setcounter{aAatest}{3}
3: \theaAatest\par\setcounter{aAatest}{51}
51: \theaAatest\par\setcounter{aAatest}{55}
55: \theaAatest
\medskip

\edef\x{\theaAatest}% expansion?
\meaning\x% gives:
\show\x% gives:
% > \x=macro:
% ->3.
% l.33 \show\x
\medskip

\foreach \i in {0,...,59}{
\setcounter{aAatest}{\i} \i: \theaAatest\par
}

\end{document}


## Output

-
You have some spurious spaces in there... It is expandable: try \edef\x{\theaAatest}\show\x –  cgnieder Jan 1 '13 at 20:14
+1 I had something similar, but I was just using \alph, \Alph (with no @); could you say why you used \@alph? –  cmhughes Jan 1 '13 at 20:52
@cmhughes Quite simple: \@alph return the alphabetical expression of its argument (counter, numexpr, or a number), not the alphabetical expression of a LaTeX counter. See my updated answer for a hopefully more helpful explanation. –  Qrrbrbirlbel Jan 1 '13 at 21:29
@cmhughes the point is that to define \@aAa you have to use \@alph and friends. To define \aAa directly you could use \alph and friends, but why to copy the code twice while the provided definition is the correctly desinged one, you see ... –  tohecz Jan 1 '13 at 21:34
@6rt4uu That is a property of the command \show: It shows the value of \x and interrupts the compilation process. To continue, simply press <enter>. Anyways, you only need the first 20 lines of the code, the rest is only a test that it works correctly. –  tohecz Jan 19 '13 at 23:47