ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
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 18:18:59 +0200	[thread overview]
Message-ID: <e8277369-cacf-0803-6e62-be82b13261fe@gmail.com> (raw)
In-Reply-To: <004133e9-9a24-6efc-8081-fe4f14c5369a@gmx.es>

Pablo Rodriguez via ntg-context schrieb am 26.04.2024 um 17:29:
> Dear list,
> 
> I have the following sample:
> 
>    \starttext
>    \def\MyCommand{\doquadruplegroupempty\doMyCommand}
> 
>    \def\doMyCommand#1#2#3#4{%
>      \iffourthargument
>        #4%
>      \orelse\ifthirdargument
>        #3%
>      \else
>        #2%
>      \fi}
> 
>    \MyCommand{}{second}{third}{fourth},\\
>    \MyCommand{}{second}{third}{fourth} e,\\
> 
>    \MyCommand{}{second}{third},\\
>    \MyCommand{}{second}{third} e,\\
> 
>    \MyCommand{}{second},\\
>    \MyCommand{}{second} e,\\
>    \stoptext
> 
> I don‘t know why only the command gets the space after right only when
> the four arguments are provided.
> 
> 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.

%%%% begin example
\tolerant\def\CommandA#_#*#_#*#_#*#_{(#1)(#2)(#3)(#4)}
\tolerant\def\CommandB#_#,#_#,#_#,#_{(#1)(#2)(#3)(#4)}
	
\starttext

A: \CommandA{a}          xxx\par
B: \CommandB{a}          xxx\blank

A: \CommandA{a}{b}       xxx\par
B: \CommandB{a}{b}       xxx\blank

A: \CommandA{a}{b}{c}    xxx\par
B: \CommandB{a}{b}{c}    xxx\blank

A: \CommandA{a}{b}{c}{d} xxx\par
B: \CommandB{a}{b}{c}{d} xxx\blank

\stoptext
%%%% end example

Another way to avoid this is to create a command with a key-value list.

%%%% begin example
\tolerant\def\Command[#1]%
   {\begingroup
    \getdummyparameters[#1]%
    \doifsomething{\dummyparameter{a}}{(\dummyparameter{a})}%
    \doifsomething{\dummyparameter{b}}{(\dummyparameter{b})}%
    \doifsomething{\dummyparameter{c}}{(\dummyparameter{c})}%
    \doifsomething{\dummyparameter{d}}{(\dummyparameter{d})}%
    \endgroup}

\starttext

\Command[a=1,b=2,c=3,d=4] xxx\par
\Command[a=1,c=3] xxx\par

\stoptext
%%%% end example
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
___________________________________________________________________________________

  reply	other threads:[~2024-04-26 16:21 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 ` Wolfgang Schuster [this message]
2024-04-26 17:04   ` [NTG-context] " Pablo Rodriguez via ntg-context
2024-04-26 17:50     ` Wolfgang Schuster
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=e8277369-cacf-0803-6e62-be82b13261fe@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).