[texhax] FW: Re: Implementing control sequences with key values
Uwe Lueck
uwe.lueck at web.de
Sun Nov 14 22:47:33 CET 2010
Correcting my 14.11.2010 19:02:33:
>> Wolfgang Schuster wrote:
>> > \def\direction#1=#2#3
>> > {\def\currentdirection{#2#3}}
I commented:
> Wolfgang's code is redundant both in the definition and testing.
> The core of his idea is:
> \def\direction=#1 {\def\currentdirection{#1}}
But
\def\direction=#1#2 {\def\currentdirection{#1#2}}
is superior in allowing ("optional"!) spaces after "="
in using \direction.
>Selon "Philip Taylor (Webmaster, Ret'd)" :
>> 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
I commented:
> 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.
But one might say that " " is the best choice for the right delimiter,
and the documentation may say that a space as right delimiter
is required, so its your fault if you try another one.
(TeXbook somewhere: "If you are upset about this,
you shouldn't be.")
The semicolon would be another nice right delimiter,
reminding of closing commands in other areas of computation.
Below I am varying my former \MakeSet to get a setup
for assignment commands with space or semicolon as right delimiter.
The tests use the exclamation mark to show effects of blank spaces
after the assignment command. You see that there is no problem
in this respect with space as right delimiter, but it is with semicolon
(of course).
space delimits:\par
\def\MakeCurrentSpace#1{%
\expandafter\edef\csname#1\endcsname=##1##2 {%
\def\expandafter\noexpand\csname current#1\endcsname{##1##2}}}
\MakeCurrentSpace{direction}
\show\direction
!\direction= RTL Direction!\currentdirection!\par
!\direction= LTR Direction!\currentdirection!\par
!\direction = RTL Direction!\currentdirection!\par
!\direction = LTR Direction!\currentdirection!\par
!\direction = RTL Direction!\currentdirection!\par
!\direction = LTR Direction!\currentdirection!\par
\smallskip
semicolon delimits:\par
\def\MakeCurrentSemicolon#1{%
\expandafter\edef\csname#1\endcsname=##1##2;{%
\def\expandafter\noexpand\csname current#1\endcsname{##1##2}}}
\MakeCurrentSemicolon{direction}
\show\direction
!\direction = RTL;Direction!\currentdirection!\par
!\direction = LTR;Direction!\currentdirection!\par
!\direction = RTL; Direction!\currentdirection!\par
!\direction = LTR; Direction!\currentdirection!\par
!\direction = RTL; Direction!\currentdirection!\par
!\direction = LTR; Direction!\currentdirection!\par
\smallskip
space before semicolon:\par
!\direction = RTL ;Direction!\currentdirection!\par
!\direction = LTR ;Direction!\currentdirection!\par
\def\MakeCurrentSemicolon#1{%
\expandafter\edef\csname#1\endcsname=##1##2##3;{%
\def\expandafter\noexpand\csname current#1\endcsname{%
##1##2##3}}}
\MakeCurrentSemicolon{direction}
\show\direction
!\direction = RTL ;Direction!\currentdirection!\par
!\direction = LTR ;Direction!\currentdirection!\par
Cheers,
Uwe.
More information about the texhax
mailing list