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.

Seeing this post, I'm looking for one good solution for alpha numbering. For my point of view, the way the numbering must be displayed depends on the maximum of the numbers.

  1. If MAX = 26, then the alpha numbering must be a, b, c, ..., z.
  2. If MAX = 26^2, then the alpha numbering must be aa, ab, ac, ..., az, ba, bb, bc, ..., bz, ..., za, zb, zc, ..., zz.
  3. If MAX = 26^n, then the alpha numbering must be similar but with n letters instead of two.

How this features can be obtained by using one command with one constant to indicate the numbers n of letters to use for the alpha numbering ?

share|improve this question
    
I assume that you specify MAX (or n) before the counter is used, or should this numbering style automagically figure out how many letters to use? –  Werner Dec 7 '11 at 23:04
    
If I have to give MAX when I call the "alpha-numbering" command, it's not a problem. –  projetmbc Dec 7 '11 at 23:21
add comment

1 Answer

up vote 10 down vote accepted
\documentclass{article}
\usepackage{expl3,xparse}
\ExplSyntaxOn
\DeclareDocumentCommand {\alphanumbering} { O{3} m } {
    \exp_last_unbraced:Nf \use_none:n {
        \int_to_alph:n {
            \exp_args:Nf \int_from_alph:n { \prg_replicate:nn {#1} {z} }
            + #2 } } }
\ExplSyntaxOff
\begin{document}
  \alphanumbering{1}, \alphanumbering{2}, \ldots{}, \alphanumbering{26},
  \alphanumbering{27}, \ldots{}, \alphanumbering{2*26},
  \ldots{}, \alphanumbering{26*26}, \ldots{}, \alphanumbering{26*26*26},
  \alphanumbering{26*26*26+1}.

  \alphanumbering[6]{12345}
\end{document}
share|improve this answer
    
Thanks for this great solution ! –  projetmbc Dec 8 '11 at 9:22
add comment

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.