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