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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

alphalph defines three methods for continuing a set of symbols if you hit the end.

  • alph continues like so: a,b,c…z,aa,ab,ac…
  • mult continues like so: a,b,c…z,aa,bb,cc…
  • wrap continues like so: a,b,c…z,a,b,c…

I'd like something that works like these, except that it continues as follows:

  • a,b,c…z,za,zb,zc…zy,zz,zza…

This looks weird for letters, obviously. But if you were defining something that takes a number as input and outputs that number of dots, say, then it makes sense. The actual use case is the following: I want to define something that takes a counter as input and outputs that number represented by dice (using epsdice). At the moment, I just explicitly define the number function like so:

  \expandafter\@dicecount\csname c@#1\endcsname%

(Note I added some randomness here, but I'd settle for a case where it just outputs a bunch of sixes and then whatever. Bonus points if you can build in this pseudorandomness)

I tried looking at the code of alphalph, but I'm not at the stage where I can understand that. But I guess for the "one shot" case, patching alphalph is probably not what I want, and there's a simpler way of just testing whether a number is bigger than 6, adding a die if it is, and so on…

share|improve this question
I think that your proposition of "numbering" is more logical than the standard propositions because it respects the lexical order. – projetmbc Dec 7 '11 at 17:52
You can make alph obey lexical order by prepending a suitable number of "zeroes". This is how we make normal numbers obey lexical order: 01,02,03… – Seamus Dec 7 '11 at 20:08
The feature that I was lookinf for this kind of feature : tex.stackexchange.com/questions/37508/… . – projetmbc Dec 8 '11 at 9:24
up vote 11 down vote accepted

\cs_new:cpn {@weirdalph} #1
   \prg_replicate:nn {\int_div_truncate:nn {#1}{26}}{z}
   \int_to_alph:n {\int_mod:nn {#1}{26}}

\cs_new:cpn {@dicecount} #1
   \prg_replicate:nn {\int_div_truncate:nn {#1}{6}}{\epsdice{6}}
   \exp_args:Nx \epsdice{\int_mod:nn{#1}{6}}

\def\weirdalph#1{\expandafter\@weirdalph\csname c@#1\endcsname}
\def\dicecount#1{\expandafter\@dicecount\csname c@#1\endcsname}




\arabic{pippo}: \weirdalph{pippo}


\arabic{pippo}: \weirdalph{pippo}


\arabic{pippo}: \dicecount{pippo}


With \int_div_truncate:nn we compute the quotient, that is, the number of z's, which are inserted with \prg_replicate:nn (thanks to Bruno Le Floch). Then we compute the remainder (\int_mod:nn) converting it into a character via \int_to_alph:n. It's easy to modify it for 6 and \epsdice.

enter image description here

share|improve this answer
Since you're not using the step argument of \prg_stepwise_function:nnnN (i.e., you're simply copying the z a given number of times), you should use \prg_replicate:nn {\int_div_truncate:nn {#1}{26}}{z} instead. Also, I think the preferred way to get non-expl-syntax functions is to use xparse (although it is an overkill here). – Bruno Le Floch Dec 7 '11 at 16:00
@BrunoLeFloch One function a day. :) – egreg Dec 7 '11 at 16:37
@BrunoLeFloch Well, as it's being given an \@... name it would be easier to simply \makeatletter in addition to \ExplSyntaxOn and create \@weirdchar directly. – Joseph Wright Dec 7 '11 at 16:48

I came up with this-not really very clean code, but it works (without the epsdice package, I don't have it installed).


  \@whilenum \c@dicecount>\@dicesize \do {%
  \ifnum \c@dicecount>0 \texttt{\number\c@dicecount}\fi

\item \dice{1}
\item \dice{2}
\item \dice{3}
\item \dice{4}
\item \dice{5}
\item \dice{6}
\item \dice{7}
\item \dice{8}
\item \dice{9}
\item \dice{10}
\item \dice{11}
\item \dice{12}
\item \dice{13}
\item \dice{14}
\item \dice{15}
\item \dice{16}
\item \dice{17}
\item \dice{18}
share|improve this answer

Your Answer


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.