[texhax] \labal{\lowercase}
Adam ENDRODI
borso at vekoll.saturnus.vein.hu
Tue Apr 10 15:43:38 CEST 2007
Hello list,
I've got a problem which I'm struggling with for a week. I would like
to write a macro that creates a (LaTeX) \label of the lowercase text
of its argument:
\def\MyLabel#1{\label{\lowercase{#1}}
Obviously it doesn't work. My conception was that the problem is
\lowercase, which is processed "in the stomach" of the interpreter
(according to the TRM). So I began to write macros that aviod
calling both \lowercase and \lccode, and I've come up with this:
(I'm just getting into virgin tex; nevertheless the macros are
intended for LaTeX usage)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Returns the lower case counterpart of character #1 if it is a
% capital letter, or #1 otherwise.
\def\LowChar#1{%
\ifnum`#1=`A a\else\ifnum`#1=`B b\else\ifnum`#1=`C c\else
\ifnum`#1=`D d\else\ifnum`#1=`E e\else\ifnum`#1=`F f\else
\ifnum`#1=`G g\else\ifnum`#1=`H h\else\ifnum`#1=`I i\else
\ifnum`#1=`J j\else\ifnum`#1=`K k\else\ifnum`#1=`L l\else
\ifnum`#1=`M m\else\ifnum`#1=`N n\else\ifnum`#1=`O o\else
\ifnum`#1=`P p\else\ifnum`#1=`Q q\else\ifnum`#1=`R r\else
\ifnum`#1=`S s\else\ifnum`#1=`T t\else\ifnum`#1=`U u\else
\ifnum`#1=`V v\else\ifnum`#1=`W w\else\ifnum`#1=`X x\else
\ifnum`#1=`Y y\else\ifnum`#1=`Z z\else #1%
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
\fi\fi\fi\fi\fi\fi\fi}
% Cycle through the characters of the string via tail recursion.
\def\lowit at b#1#2\@{%
\def\lowit at tmp{#1}%
\expandafter\ifx\lowit at tmp\empty\else
\edef\lowit at buf{\lowit at buf \LowChar#1}%
\lowit at b#2\@
\fi}
% The lowercase string is stored in \lowit at buf temporarily.
\def\lowit at a#1{%
\def\lowit at buf{}%
\expandafter\lowit at b#1\empty\empty\@%
\lowit at buf\egroup}
% This is the entry point. It takes a string and expands to its lowercase.
% The \catcode manipulations are necessarry so \lowit at b won't ignore whitespace.
\def\LowIt{%
\bgroup%
\def\whitespace{ }%
\catcode`\ =\active\lccode`\~`\ \lowercase{\let~\whitespace}%
\catcode`\^^I=\active\lccode`\~`\^^I\lowercase{\let~\whitespace}%
\catcode`\^^M=\active\lccode`\~`\^^M\lowercase{\let~\whitespace}%
\lowit at a}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Now, LowIt{BLA BLA BLA} is typeset to ``bla bla bla'' correctly; I was
very happy to see that. However, when I try to \typeout{\LowIt{BLA BLA}
the whole thing blows up because \typeout (and \label for that matter)
seem to \edef \LowIt; then tex starts complaining about \whitespace being
undefined. Ouch.
Earlier someone (Uwe?) posted a code fragment that looked primising:
\newcommand{\foo}{%
\stepcounter{foo}%
\edef\thelabel{\noexpand\label{bar:\thefoo}}%
\thelabel}
While it does magic with \label, I could not apply the idea to my problem.
Can you give me a hand?
bit,
adam
More information about the texhax
mailing list