From: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
Pablo Rodriguez via ntg-context <ntg-context@ntg.nl>
Cc: Pablo Rodriguez <oinos@gmx.es>
Subject: [NTG-context] Re: wrong spacing after command with optional arguments
Date: Fri, 26 Apr 2024 19:50:38 +0200 [thread overview]
Message-ID: <f18b348d-bba4-6967-b659-7a70fbb805d8@gmail.com> (raw)
In-Reply-To: <64ba78d7-cb92-256d-460f-58d5e1eaedad@gmx.es>
Pablo Rodriguez via ntg-context schrieb am 26.04.2024 um 19:04:
> On 4/26/24 18:18, Wolfgang Schuster wrote:
>> Pablo Rodriguez via ntg-context schrieb am 26.04.2024 um 17:29:
>>> What is wrong in my definition above?
>>
>> There is nothing wrong, this is just a side effect of the scanner used
>> with the \do...groupempty commands. To have more control about this
>> behavior use the \tolerant modifier for \def to change it.
>
> Many thanks for your reply, Wolfgang.
>
> I tried this approach (I hope it isn’t wrong):
>
> \starttext
> \expanded\tolerant\def\MyCommand#_#,#_#,#_#,#_{%
> \doiftextelse{#4}%
> {#4}
> {\doiftextelse{#3}
> {#3}
> {#2}}}
The \expanded modifier is wrong (I guess you meant \unexpanded) but
which check for the number of arguments you use doesn't matter in a
document.
The LMTX version of the \iffourthargument etc. checks is the
\ifarguments commands where you use \or to set a case for the number of
argument passed.
\protected\tolerant\def\MyCommand#_#,#_#,#_#,#_%
{\ifarguments
% no arguments are passed
\or
#1% one argument is passed
\or
#2% two arguments are passed
\or
#3% three arguments are passed
\or
#4% four arguments are passed
\fi}
> \MyCommand{}{second}{third}{fourth},\\
> \MyCommand{}{second}{third}{fourth} e,\\
>
> \MyCommand{}{second}{third},\\
> \MyCommand{}{second}{third} e,\\
>
> \MyCommand{}{second},\\
> \MyCommand{}{second} e,\\
> \stoptext
>
> BTW, this is the first time I see #_ instead of #1.
>
> There is no way to search for "#_" in the wiki.
>
> Grepping the source, "#_" seems to be used for optional arguments
> (mainly in syst-aux.mkxl).
>
> But what are these "#_" (which don’t seem to come from TeX)?
Hans added many additions to command parameters in Luametatex and #_
means the argument to a commands has to be enclosed in braces while #1
allows you to pass text without it.
In the following example \CommandA take in the first case "a" as
argument while CommandB ignores it and would only accept "{a}" with
braces around it.
%%%% begin example
\def\CommandA#1{(#1)}
\tolerant\def\CommandB#_{(#1)}
\starttext
\CommandA abc\par
\CommandB abc\blank
\CommandA {ab}c\par
\CommandB {ab}c\blank
\stoptext
%%%% end example
You can find a list with all new command parameters in lowlevel-macros.pdf.
Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2024-04-26 17:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-26 15:29 [NTG-context] " Pablo Rodriguez via ntg-context
2024-04-26 16:18 ` [NTG-context] " Wolfgang Schuster
2024-04-26 17:04 ` Pablo Rodriguez via ntg-context
2024-04-26 17:50 ` Wolfgang Schuster [this message]
2024-04-26 18:59 ` Pablo Rodriguez via ntg-context
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=f18b348d-bba4-6967-b659-7a70fbb805d8@gmail.com \
--to=wolfgang.schuster.lists@gmail.com \
--cc=ntg-context@ntg.nl \
--cc=oinos@gmx.es \
/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).