[texhax] Implementing control sequences with key values
Uwe Lueck
uwe.lueck at web.de
Sun Nov 14 19:02:34 CET 2010
"Paul Isambert" <zappathustra at free.fr>, 14.11.2010 17:28:25
>Selon "Philip Taylor (Webmaster, Ret'd)" :
>> Wolfgang Schuster wrote:
>> > \def\direction#1=#2#3
>> > {\def\currentdirection{#2#3}}
>> >
>> > \tracingmacros1
>> >
>> > \direction=LTR Direction: \currentdirection\par
>> > \direction=RTL Direction: \currentdirection\par
>> >
>> > \vskip\baselineskip
>> >
>> > \direction =LTR Direction: \currentdirection\par
>> > \direction =RTL Direction: \currentdirection\par
>> >
>> > \vskip\baselineskip
>> >
>> > \direction = LTR Direction: \currentdirection\par
>> > \direction = RTL Direction: \currentdirection\par
>> >
>> > \bye
>>
>> 11/10 for effort, Wolfgang, but there are some common cases
>> for which it does not work :
>>
>> \direction = LTR\relax Direction: \currentdirection\par
>> \direction = RTL\relax Direction: \currentdirection\par
>>
>> \vskip\baselineskip
>>
>> \direction = LTR%
>> Direction: \currentdirection\par
>> \direction = RTL%
>> Direction: \currentdirection\par
>
>
> If the direction is always made of three letters, as I think it is, then
>
> \def\direction=#1#2#3{...}
>
> might work well. Of course it forbids
>
> \direction={RTL}
>
> Anyway, Vafa, are you trying to mimick TeX assignments or key-value's? In the
> former case (which is investigated here), nothing will be perfect. In the
> latter, though, the "key = value" pair is normally well delimited (e.g. by a
> comma or the end of the list), so the value can be easily retrieved.
Wolfgang's code is redundant both in the definition and testing.
The core of his idea is:
\def\direction=#1 {\def\currentdirection{#1}}
The problem (noted by Paul and Phil) is that it is somewhat difficult with TeX
to catch a "parameter word" with varying "word" delimiters. Wolfgang chose
delimiters "=" and " ", which of course fails when " " is replaced by anything else.
And even the "=": TeX allows assignments with or without "=",
while Wolfgang's suggestion fails with
\direction RTL
I.e., it is "difficult" to emulate TeX's assignment parsing by macros.
(Well, \@ifnextchar= etc. ...)
A similar problem has been noted with the FiNK package:
It is "difficult" to replace \input by a self-defined macro.
-- Ah, cf. Phil on "\magnification hacks" ...
"Wolfgang Schuster" , 14.11.2010 14:52:54:
[...]
>Yes but i would recommend i method which fits to the macro package, e.g.
> \setdirection{LTR} or \setdirection[RTL]
\set... is so obvious, and with this construction I wonder why anyone
should want to have an "=" assignment syntax. I have defined such commands
so often and now think that I could use "\MakeSet":
\def\MakeSet#1{%
\expandafter\edef\csname set#1\endcsname{%
\def\expandafter\noexpand\csname#1\endcsname}}
\MakeSet{direction}
\setdirection{RTL}Direction: \direction\par
\setdirection{LTR}Direction: \direction\par
When this has been understood, \@bsphack and \@esphack might be added ...
Cheers,
Uwe.
More information about the texhax
mailing list