[NTG-context] LMTX MkIV difference in expansion

Rik Kabel ConTeXt at rik.users.panix.com
Sat Nov 21 16:25:41 CET 2020


On 11/21/2020 10:05, Wolfgang Schuster wrote:
> Rik Kabel schrieb am 20.11.2020 um 00:18:
>
>> You are right about not quite understand.
>
> There are cases where you want to pass a command to another command as 
> it is without replacing it with its content, e.g. when you store the 
> \TeX logo in the table of content the \TeX command should be written 
> in the register and not the content of the command.
>
> In the following example the first line prints the definition of the 
> \TeX logo but in many cases you ant to preserve the command as in the 
> second line.
>
> \starttext
>
> \tex{TeX} = \detokenize\expandafter{\TeX}
>
> \blank
>
> \tex{TeX} = \detokenize{\TeX}
>
> \stoptext
>
>
> To make it easier to keep the command eTeX added a new command 
> \protected which can be used before \def to achieve this (ConTeXt 
> provides the same thing under the name \unexpanded).
>
> The following example shows how you can use \protected\def to keep 
> always the current meaning of \foo when you print the content of \bar.
>
> \starttext
>
> \def\foo{foo}
>
> \edef\bar{\foo}
>
> \def\foo{bar}
>
> \startlines
> bar=\bar
> foo=\foo
> \stoplines
>
> \blank
>
> \protected\def\foo{foo}
>
> \edef\bar{\foo}
>
> \protected\def\foo{bar}
>
> \startlines
> bar=\bar
> foo=\foo
> \stoplines
>
> \stoptext
>
>
> A problem in older TeX engines is that \csname ...\endcsname didn't 
> respect this protection and replaced the protected command with its 
> content, recently Hans changed this behavior in LMTX which lead to the 
> error message in your document.
>
>
>> Does this mean that I can have the same definitions in MkIV and LMTX 
>> (after some future update), or should I hunt down the \defines in 
>> both, or that I should fork (or mode test) my source environment 
>> files, one set for LMTX and one for MkIV?
>
>
> When you use \define to store arguments which are passed as arguments 
> to other command you have to change this to \defineexpandable but its 
> best to do this in MkIV and LMTX because protected commands are the 
> wrong thing in this case. Even though it would work in MkIV in some 
> cases you run into problems when you pass argument to Lua.
>
> Wolfgang

Thank you, Wolfgang, for the explanation and examples.

I have in fact already gone through and replaced the impacted 
occurrences of \define with \defineexpandable. LMTX made it easy to 
identify them.

-- 
Rik



More information about the ntg-context mailing list