Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
1  
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

1 Answer 1

up vote 16 down vote accepted

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

enter image description here

share|improve this answer
1  
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
1  
@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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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