[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:


... 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:

   \protected at edef\@myarg{#1}%

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):

   \let\@xsecondtoken\@empty \def\@ysecondtoken{#2}%
\def\@mynastylist{"\"\`\'}% ... or more or less ...
   \ifx#1\@mynastytest \else

First I had used an \if... instead of \@xsecondtoken
etc. perhaps I should have kept it instead of what is
now present.

Lucky typesetting,

More information about the texhax mailing list