ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Rik Kabel <ConTeXt@rik.users.panix.com>
To: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com>,
	mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: LMTX MkIV difference in expansion
Date: Sat, 21 Nov 2020 10:25:41 -0500	[thread overview]
Message-ID: <c8ee764a-9b8d-541d-79ba-eca4a1dc67e4@rik.users.panix.com> (raw)
In-Reply-To: <8c0905ee-8c0f-02f8-cc46-e9712afb137e@gmail.com>


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

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

      reply	other threads:[~2020-11-21 15:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-19 20:20 Rik Kabel
2020-11-19 20:41 ` Wolfgang Schuster
2020-11-19 22:03   ` Hans Hagen
2020-11-19 23:18     ` Rik Kabel
2020-11-20  7:53       ` Hans Hagen
2020-11-21 15:05       ` Wolfgang Schuster
2020-11-21 15:25         ` Rik Kabel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c8ee764a-9b8d-541d-79ba-eca4a1dc67e4@rik.users.panix.com \
    --to=context@rik.users.panix.com \
    --cc=ntg-context@ntg.nl \
    --cc=wolfgang.schuster.lists@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).