ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
	"Jairo A. del Rio" <jairoadelrio6@gmail.com>
Subject: Re: Commands with arguments before in ConTeXt
Date: Mon, 29 Jun 2020 09:28:27 +0200	[thread overview]
Message-ID: <64d592a1-149a-d2ec-5979-b000e5096c26@xs4all.nl> (raw)
In-Reply-To: <CAKyqqaZqKKosuNQL2WtJBFqdYEusetLyPQe0YxU=Bg+HMPAUkg@mail.gmail.com>

On 6/28/2020 10:48 PM, Jairo A. del Rio wrote:
> I've read the following is not possible in TeX
> 
> \def#1\macro{blabla#1}
> 
> where arguments come before. The only partial exceptions are commands 
> like \atop or \over, which are in fact primitives. Is there a way to do 
> this in ConTeXt?
> 
> Could it be a feature request for LuaMetaTeX? I've seen Hans 
> experimenting a lot with new primitives and new possibilities for 
> arguments, like #0 and co., so I ask in case it's not too nonsensical to 
> propose it. Regards
Every \foo will be looked up, so by the time \macro in:

   bla bla {\bf xxx}\macro{xxx}

is seen, the {\bf xxx} is already passed and processed. TeX never looks 
back, which actually would make for a pretty complex multipass parsing 
and expansion management (forward control and backward: \expandafter 
would then also have an \expandbefore companion). Even in the simple 
case: should it keep track of quantities done (grouped, single token, 
box, etc.) and then in retrospect see it as #1 (them being nodes by now 
and not tokens)?

So, why in math but not in text? The \atop and \over (those are 
basically all the same command but with a different treatment 
afterwards) are an exception: (1) tex knows that is is in math mode, and 
in math mode the { } are not really arguments but defines some stuff 
handled together. Much processing (not all) is delayed to a second pass, 
so {1}\over{2} internally becomes \over{1}{2} and even that is kind of 
tricky because there are math styles involved (which makes for some hard 
coded behaviour that in the perspective of luametatex i try to get more 
grip on). Now, in order to handle this one (!) exception to lookahead 
parsing, special tracking happens in math mode, the previous math 
grouped stuff is registered and adapted to the \over when seen, 
otherwise it stays as is. This exception also maked the code somewhat 
messier because there are several spots where it has to be dealt with 
(also think of saving and restoring states). Just imagine that there 
were more such commands. Believe me, you really don't want to know the 
details.

So the answer is "Can't be done without overhauling the whole concept".

Now, I know that the narrative is that context is a moving target 
(contrary to other macro packages that don't / can't change because 
users / publishers expect them to behave the same forever) so one can 
argue that for context we can follow a drastic different route, but even 
then, we can't shoot ourselves in the foot too often. I know that some 
people (read: Alan) love these {{}\foo{}} syntaxes but live would have 
been simpler if even \over has not be in there with prefix notation 
(there is a reason why macro package have \frac like variants).

Hans



-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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-06-29  7:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-28 20:48 Jairo A. del Rio
2020-06-29  7:28 ` Hans Hagen [this message]
2020-06-29 10:15   ` Jairo A. del Rio
2020-06-29 10:36     ` Taco Hoekwater
2020-06-29 11:06       ` Taco Hoekwater
2020-06-29 13:21         ` Hans Hagen
2020-06-30  0:18       ` Jairo A. del Rio
2020-06-29  7:50 ` luigi scarso
2020-06-29 10:21   ` Jairo A. del Rio
2020-06-29 13:27     ` Hans Hagen
2020-06-29 13:48       ` Jairo A. del Rio
2020-06-29 14:45         ` Hans Hagen

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=64d592a1-149a-d2ec-5979-b000e5096c26@xs4all.nl \
    --to=j.hagen@xs4all.nl \
    --cc=jairoadelrio6@gmail.com \
    --cc=ntg-context@ntg.nl \
    /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).