[texhax] Read and process single characters
Uwe Lück
uwe.lueck at web.de
Fri Jun 24 21:48:01 CEST 2005
[This might be interesting for `Glisterings' in TuGboat]
At 16:50 24.06.05, Torsten Wagner wrote:
>does somebody know how to read single characters and process them one by one.
>so that
>
>\mycommand{my text}
>\mycommand{My text}
>
>results both in
>
>My text
>
>For sure, furthermore it would be nice if
>
>\mycommand{MY TEXT}
>
>results as shown above too.
For LaTeX:
\makeatletter
\newcommand{\mycommand}[1]{\@mycommand#1\@mycommand}
\def\@mycommand#1#2\@mycommand{%
\MakeUppercase{#1}\MakeLowercase{#2}}
\makeatother
... e.g. (Or \def\mycommand#1 etc., in particular without
LaTeX. Without LaTeX \Make... also must be replaced.)
This needs TeX knowledge, see the Macros chapter
of the TeXbook.
>I found /uppercase and /lowercase to handle whole tokens. But how can I
>split a token into single characters?
? It seems that you have an unusual understanding of "token".
However, if the argument of \mycommand may start with a
macro expanding to characters, something like this is needed:
\DeclareRobustCommand{\mycommand}[1]{%
\protected at edef\@myarg{#1}%
\expandafter\@mycommand\@myarg\@mycommand}
This still can be fooled by an #1 starting with a brace
or with \emph ...
Another difficulty is that the argument might start with an
accent command, or with the double quote mark from
german.sty or babel. So better (without \@myarg):
\def\@mycommand#1#2#3\@mycommand{%
\let\@firsttoken#1%
\let\@xsecondtoken\@empty \def\@ysecondtoken{#2}%
\expandafter\@mynastytest\@mynastylist\@mynastytest
\MakeUppercase{#1\@xsecondtoken}%
\MakeLowercase{\@ysecondtoken#3}%
}
\def\@mynastylist{"\"\`\'}% ... or more or less ...
\def\@mynastytest#1{%
\ifx#1\@mynastytest \else
\ifx\@firsttoken#1%
\let\@xsecondtoken\@ysecondtoken
\let\@ysecondtoken\@empty
\fi
\expandafter\@mynastytest
\fi}
First I had used an \if... instead of \@xsecondtoken
etc. perhaps I should have kept it instead of what is
now present.
Lucky typesetting,
Uwe.
More information about the texhax
mailing list