lex@cogsci.ed.ac.uk (Alexander Holt) (07/13/90)
[I did try <latex-help@sumex-aim.stanford.edu> a month ago, but no response] I'm writing some LaTeX macros in which I would like to turn an integer into the corresponding lowercase letter, thus 1 -> a, 2 -> b, etc. LaTeX sometimes needs to do this itself for the value of counters and uses these definitions: \def\@alph#1{\ifcase#1\or a\or b\or c\or d\else\@ialph{#1}\fi} \def\@ialph#1{\ifcase#1\or \or \or \or \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\@ctrerr\fi} \def\@ctrerr{\@latexerr{Counter too large}\@ehb} Here the TeX command \ifcase is used - which expects a <number>. My problem is that I would sometimes like to do: \@alph{\ref{...}} where the \ref{...} is a LaTeX reference to a counter. But I get the error: ! Missing number, treated as zero. <to be read again> \edef <argument> \edef \@tempa {\@nameuse {r@ex:big2}}\expandafter \@car \@tempa \... \@ifundefined ...me #1\endcsname \relax #2\else #3 \fi \@alph #1->\ifcase #1 \or a\or b\or c\or d\else \@ialph {#1}\fi ... since the \ref{...} expands into this \edef ... sequence and TeX cannot interpret this as a number. How can I arrange things so that \ifcase finds the number eventually produced by \ref? (This all assumes that the label being \ref'd is defined at this point - when it is not, then I have a different problem! I would like a way to detect this case by examining the output of \ref so that I can bypass the call to \@alph and avoid an error.) I would be very grateful for any advice on this. Lex Holt (lex@cogsci.ed.ac.uk)
max@Neon.Stanford.EDU (Max Hailperin) (07/31/90)
In article <1538@scott.ed.ac.uk> lex@cogsci.ed.ac.uk (Alexander Holt) writes: >[I did try <latex-help@sumex-aim.stanford.edu> a month ago, but no >response] Please, please, everybody: If you get no response from LaTeX-help in some reasonable period (maybe a week, certainly not a month), send a note to LaTeX-help-coordinator@sumex-aim.stanford.edu asking what went wrong. Sometimes one of the volunteers falls off the face of the earth without letting the coordinator know. The only way this gets caught is if a helpful prosepctive helpee inquires. At that point, lots of useful things can happen: the question can be expedited to a non-fallen-off-the-face-of-the-earth helper, the f-o-t-f-o-t-e helper can be temporarily removed from the round-robin rotation to prevent further non-responses, and diagnosis can be attempted to discover what happened to the f-o-t-f-o-t-e helper and reverse the falling. Oh yes, as to the problem; here's a definition (which should be put in a file called alphref.sty or such and put in [] in the documentstyle line): \def\alphref#1{\@ifundefined{r@#1}{?}{\edef\@tempa{\@nameuse{r@#1}}\expandafter \expandafter\expandafter\@alph\expandafter\@car\@tempa \@nil\null}} I've chosen to expand to a ? in the undefined label case; that can be changed. For an explanation of why on earth so many \expandafter's are needed, see the second page of Appendix D in the TeXbook.