Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

alph counters > 26

30 views
Skip to first unread message

Will Douglas

unread,
Mar 17, 1999, 3:00:00 AM3/17/99
to

Would any bright bulb out there have extended the \alph definition to
allow for ...x,y,z,aa,ab,ac,ad... or something similar? I'm using the
Manyfoot package to run three registers of notes in an edition, and it
would be very helpful to be able to have n>26 notes per chapter in the
alphabetically-tagged register.

I suppose the other possibility is to reset that counter at every
page...

-wbd.

Robin Fairbairns

unread,
Mar 18, 1999, 3:00:00 AM3/18/99
to
Will Douglas <william...@wolfson.ox.ac.uk> wrote:
>Would any bright bulb out there have extended the \alph definition to
^^^^^^^^^^^

>allow for ...x,y,z,aa,ab,ac,ad... or something similar? I'm using the
>Manyfoot package to run three registers of notes in an edition, and it
>would be very helpful to be able to have n>26 notes per chapter in the
>alphabetically-tagged register.

will a fading old hacker do?

\newcommand\aalph[1]{\expandafter\@aalph\csname c@#1\endcsname}
\newcommand\@aalph[1]{\@tempcnta#1%
\ifnum\@tempcnta<27
\@alph\@tempcnta
\else
\advance\@tempcnta\m@ne
\@tempcntb\@tempcnta
\divide \@tempcnta by26
\@alph\@tempcnta
\multiply \@tempcnta by26
\advance \@tempcntb -\@tempcnta
\advance \@tempcntb \@ne
\@alph\@tempcntb
\fi
}

(needs to be in a .sty file or something)

>I suppose the other possibility is to reset that counter at every
>page...

aha! i've got macros for doing that...
--
Robin Fairbairns, Cambridge

Will Douglas

unread,
Mar 18, 1999, 3:00:00 AM3/18/99
to
In article <7crdco$mjg$1...@pegasus.csx.cam.ac.uk>, Robin Fairbairns
<r...@cl.cam.ac.uk> wrote:

> Will Douglas <william...@wolfson.ox.ac.uk> wrote:
> >Would any bright bulb out there have extended the \alph definition to
> ^^^^^^^^^^^

> will a fading old hacker do?


Robin, the day you fade it will all seem rather dimmer. Thank you for
the fragment, and yes, I think that reset-per-page code would go dowwn
very nicely too!


-wbd.

Donald Arseneau

unread,
Mar 18, 1999, 3:00:00 AM3/18/99
to
In article <7crdco$mjg$1...@pegasus.csx.cam.ac.uk>, r...@cl.cam.ac.uk (Robin Fairbairns) writes...

>will a fading old hacker do?

That's the explanation eh?

>\newcommand\@aalph[1]{\@tempcnta#1%
> \ifnum\@tempcnta<27
> \@alph\@tempcnta
> \else
> \advance\@tempcnta\m@ne

counter-presentation macros must be robust, and preferably expandable.
If the conversion can't* be done by expansion, then it should be made
self-protecting, as in:

\newcommand*\@aalph[1]{%
\ifnum #1<27
\@alph{#1}%
\else
\protect \@aalph@{\number#1}%
\fi
}

\def\@aalph@#1{\@tempcnta#1\relax


\@tempcntb\@tempcnta
\divide \@tempcnta by26
\@alph\@tempcnta
\multiply \@tempcnta by26
\advance \@tempcntb -\@tempcnta
\advance \@tempcntb \@ne
\@alph\@tempcntb
}


Any bright bulbs out there wanna write an expandable version?


Donald Arseneau as...@triumf.ca
-----
* See the LaTeX definition of \Roman and note the effort exerted to
define it expandably.


Heiko Oberdiek

unread,
Mar 19, 1999, 3:00:00 AM3/19/99
to
as...@reg.triumf.ca (Donald Arseneau) wrote:

>Any bright bulbs out there wanna write an expandable version?

\ifcase... ;-)

Becoming serious: It is possible to write an expandable version:
1. Count the subtractions of 26 and convert the rest to a letter.
2. Go back to 1. with the previous count of subtractions to get
the next letter from behind.
1. 2. 1. 2. ...
3. Reverse letters.
Requires
* a expandible subtraction, also possible
* a lot of time, a lot of time to write the marcos
* a lot of macros

Best regards
Heiko <ober...@ruf.uni-freiburg.de>

Heiko Oberdiek

unread,
Mar 19, 1999, 3:00:00 AM3/19/99
to
as...@reg.triumf.ca (Donald Arseneau) wrote:

>\newcommand*\@aalph[1]{%
> \ifnum #1<27
> \@alph{#1}%
> \else
> \protect \@aalph@{\number#1}%
> \fi
>}
>
>\def\@aalph@#1{\@tempcnta#1\relax
> \@tempcntb\@tempcnta
> \divide \@tempcnta by26
> \@alph\@tempcnta
> \multiply \@tempcnta by26
> \advance \@tempcntb -\@tempcnta
> \advance \@tempcntb \@ne
> \@alph\@tempcntb
>}

0:\@aalph{0}
1:\@aalph{1}
26:\@aalph{26}
27:\@aalph{27}
51:\@aalph{51}
52:\@aalph{52}
701:\@aalph{701}
702:\@aalph{702}

gives 0: 1:a 26:z 27:ab 51:az 52:ba 701:zz ???
The 702 item gives an error.

I have understand the counting in the following way:
1= a
...
26= z
27=aa
...
52=az
53=ba
...

>Any bright bulbs out there wanna write an expandable version?

Yes.

%%% cut %%% alphalph.sty %%% cut %%%
% File: alphalph.sty
% Version: 1999/03/19 v0.1
% Author: Heiko Oberdiek
%
% Function: Expandible "alphalph" number format.
%
% Copyright: Copyright (C) 1999 Heiko Oberdiek.
%
% This program can be redistributed and/or modified
% under the terms of the LaTeX Project Public License
% distributed from CTAN archives in directory
% macros/latex/base/lppl.txt; either version 1 of
% the License, or (at your option) any later version.
%
% Requirement: tex or latex
%
% Use: \alphalph{<number>} ==> a..z, aa..az, ...
% \AlphAlph{<number>} ==> A..Z, AA..AZ, ...
% Numbering starts with 1 = a. <number>
% can be any kind of a TeX number.
% '@' is used in case of an error.
%
% History: 1999/03/19 v0.1: first public release (comp.text.tex)
%

% Storing the \catcode of @.
\expandafter\edef\csname aa@atcode\endcsname{\the\catcode`\@ }
\catcode`\@=11

% Providing utils of the LaTeX kernel, if they aren't.
\expandafter\ifx\csname @firstoftwo\endcsname\relax
\long\def\@firstoftwo#1#2{#1}%
\long\def\@secondoftwo#1#2{#2}%
\fi
\expandafter\ifx\csname @ifundefined\endcsname\relax
\def\@ifundefined#1{%
\expandafter\ifx\csname#1\endcsname\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}%
\fi

% Package identification in the log file
\@ifundefined{ProvidesPackage}{%
\immediate\write-1{%
Package: alphalph 1999/03/19 v0.1 %
Expandible \string"alphalph\string" number format (HO)%
}%
}{%
\ProvidesPackage{alphalph}[%
1999/03/19 v0.1 %
Expandible \string"alphalph\string" number format (HO)]%
}

% Definitions for preventing \if-nesting.
\long\def\aa@ReturnAfterElseFi#1\else#2\fi{\fi#1}
\long\def\aa@ReturnAfterFi#1\fi{\fi#1}

\def\aa@alph#1{%
\ifcase#1
@% error symbol
\or a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or k\or l\or m%
\or n\or o\or p\or q\or r\or s\or t\or u\or v\or w\or x\or y\or z%
\else
@% error symbol
\fi
}
\def\aa@Alph#1{%
\ifcase#1 @%
\or A\or B\or C\or D\or E\or F\or G\or H\or I\or J\or K\or L\or M%
\or N\or O\or P\or Q\or R\or S\or T\or U\or V\or W\or X\or Y\or Z%
\else
@% error symbol
\fi
}

\def\alphalph{\aa@callmake\aa@alph}
\def\AlphAlph{\aa@callmake\aa@Alph}

\def\aa@callmake#1#2{%
\expandafter\aa@make\expandafter{\number#2}#1%
}
\def\aa@make#1#2{%
\ifnum#1<1
\expandafter @% error symbol
\else
\aa@ReturnAfterFi{%
\aa@process1;#1;1..#2%
}%
\fi
}

% #1: decimal result count
% #2: the number
% #3: reverse decimal digit format of the result count
% The result count is uses twice:
% a) as a decimal number #1 in order to compare with the number #2
% b) as a series of decimal numbers #3, each of them stands for an
% letter of the result, reverse ordered and delimited by an '.'.
% Both result counts are incremented until the number #2 is reached.
\def\aa@process#1;#2;{%
\ifnum#1=#2
\expandafter\aa@getresult
\else
\aa@ReturnAfterFi{%
\expandafter\aa@process\number\aa@inc{#1}\aa@alphinc{;#2;}%
}%
\fi
}

\def\aa@getresult#1..#2{%
\aa@@getresult!#2#1..%
}
% #1: result
% #2: \alph, \Alph
% #3: next "digit"
\def\aa@@getresult#1!#2#3.{%
\ifx\\#3\\%
\aa@ReturnAfterElseFi{#1}% ready
\else
\aa@ReturnAfterFi{%
\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter
\aa@@getresult
\expandafter\expandafter\expandafter\expandafter
#2{#3}#1!#2%
}%
\fi
}

% \aa@inc adds one to its argument #1.
\def\aa@inc#1{%
\ifnum#1<9
\aa@nextdigit{#1}%
\else
\aa@reverse#1!!%
\fi
}
\def\aa@nextdigit#1{\ifcase#1 1\or2\or3\or4\or5\or6\or7\or8\or9\fi}
\def\aa@reverse#1#2!#3!{%
\ifx\\#2\\%
\aa@addone#1#3!!%
\else
\aa@reverse#2!#1#3!%
\fi
}
\def\aa@addone#1#2!#3!{%
\ifnum#1<9
\expandafter\aa@lastreverse\number\aa@nextdigit#1 #2!#3!%
\else
\aa@ReturnAfterFi{%
\ifx\\#2\\%
10#3%
\else
\aa@ReturnAfterFi{%
\aa@addone#2!0#3!%
}%
\fi
}%
\fi
}
\def\aa@lastreverse#1#2!#3!{%
\ifx\\#2\\%
#1#3%
\else
\aa@ReturnAfterFi{%
\aa@lastreverse#2!#1#3!%
}%
\fi
}

% \aa@alphinc adds 1 to the "decimal digit result format".
% #1 tokens to be set, if command ready.
% #2 next alpha digit
\def\aa@alphinc#1#2.{%
\ifx\\#2\\%
\aa@ReturnAfterElseFi{%
#11..% ready
}%
\else
\aa@ReturnAfterFi{%
\ifnum#2<26
\aa@ReturnAfterElseFi{%
\expandafter\aa@alphinclast\expandafter
{\number\aa@inc{#2}}{#1}%
}%
\else
\aa@ReturnAfterFi{%
\aa@alphinc{#11.}%
}%
\fi
}%
\fi
}
\def\aa@alphinclast#1#2{#2#1.}

\catcode`\@=\aa@atcode
\endinput
%%% cut %%% alphalph.sty %%% cut %%%

Best regards
Heiko <ober...@ruf.uni-freiburg.de>

Robin Fairbairns

unread,
Mar 19, 1999, 3:00:00 AM3/19/99
to
Heiko Oberdiek <ober...@ruf.uni-freiburg.de> wrote:
>as...@reg.triumf.ca (Donald Arseneau) wrote:
>
>>\newcommand*\@aalph[1]{%
>> \ifnum #1<27
>> \@alph{#1}%
>> \else
>> \protect \@aalph@{\number#1}%
>> \fi
>>}
>>
>>\def\@aalph@#1{\@tempcnta#1\relax
>> \@tempcntb\@tempcnta
>> \divide \@tempcnta by26
>> \@alph\@tempcnta
>> \multiply \@tempcnta by26
>> \advance \@tempcntb -\@tempcnta
>> \advance \@tempcntb \@ne
>> \@alph\@tempcntb
>>}
>gives 0: 1:a 26:z 27:ab 51:az 52:ba 701:zz ???
>The 702 item gives an error.

donald missed out my
\advance\@tempcnta \m@ne
which should be the second line of his \@aalph@

>>Any bright bulbs out there wanna write an expandable version?
>
>Yes.

argh
--
Robin Fairbairns, Cambridge

Heiko Oberdiek

unread,
Apr 15, 1999, 3:00:00 AM4/15/99
to
Hello,

Will Douglas <william...@wolfson.ox.ac.uk> wrote:
>Would any bright bulb out there have extended the \alph definition to

>allow for ...x,y,z,aa,ab,ac,ad... or something similar? I'm using the
>Manyfoot package to run three registers of notes in an edition, and it
>would be very helpful to be able to have n>26 notes per chapter in the
>alphabetically-tagged register.

as...@reg.triumf.ca (Donald Arseneau) wrote:
>Any bright bulbs out there wanna write an expandable version?

ober...@ruf.uni-freiburg.de (Heiko Oberdiek) wrote:
>Yes.
>
>%%% cut %%% alphalph.sty %%% cut %%%
>% File: alphalph.sty
>% Version: 1999/03/19 v0.1

alphalph, version 1.1 is now available on CTAN in directory:
CTAN:macros/latex/contrib/supported/oberdiek/

Added: fast e-TeX variant
The macros are still fully expandable and can be used with both
plain-TeX and LaTeX.

Yours sincerely
Heiko <ober...@ruf.uni-freiburg.de>

0 new messages