Re: [NTG-context] Defining command with optional and mandatory arguments
On Wed, 23 May 2018 17:54:39 +0200, Henning Hraban Ramm
Date: Wed, 23 May 2018 17:54:39 +0200 From: Henning Hraban Ramm
To: mailing list for ConTeXt users Subject: Re: [NTG-context] Defining command with optional and mandatory arguments Message-ID: Content-Type: text/plain; charset=windows-1252 Am 2018-05-23 um 16:01 schrieb Hans Hagen
: On 5/23/2018 3:39 PM, Christoph Reller wrote:
Hi, What is the right way to define a command with both mandatory and optional arguments, e.g: i'm not sure wht happens at your end but this is the best way:
Also, there’s documentation at http://wiki.contextgarden.net/Commands_with_optional_arguments
If there’s something wrong, please fix it yourself or come back to this list ;)
Thank you Hraban for pointing me to the wiki. I was aware of this page but it contains only the case of mandatory arguments in curly braces {} not in brackets []. Cheers, Christoph
Am 2018-05-24 um 11:24 schrieb Christoph Reller
On Wed, 23 May 2018 17:54:39 +0200, Henning Hraban Ramm
wrote: What is the right way to define a command with both mandatory and optional arguments, e.g: i'm not sure wht happens at your end but this is the best way:
Also, there’s documentation at http://wiki.contextgarden.net/Commands_with_optional_arguments If there’s something wrong, please fix it yourself or come back to this list ;)
Thank you Hraban for pointing me to the wiki. I was aware of this page but it contains only the case of mandatory arguments in curly braces {} not in brackets [].
Arguments in brackets are always optional (if I don’t misunderstand), depending on your own logic (\if*argument, \ifempty etc.) see also http://wiki.contextgarden.net/System_Macros : http://wiki.contextgarden.net/System_Macros/Handling_Arguments http://wiki.contextgarden.net/System_Macros/Branches_and_Decisions etc. I need to read these more often myself... Greetlings, Hraban --- https://www.fiee.net http://wiki.contextgarden.net https://www.dreiviertelhaus.de GPG Key ID 1C9B22FD
Hi,
Arguments in brackets are always optional (if I don’t misunderstand), depending on your own logic (\if*argument, \ifempty etc.)
The original intent was for user-level commands to have square brackets for arguments setting things up, and curly braces for arguments that are actually typeset. That is where commands like \in come from, where the braced part is optional and the bracketed part required. Internal low-level commands tended to use braces more often because of efficiency considerations. (also, at the primitive level, TeX syntax is inconsistent anyway, with various primitives having quite different syntactical conventions). Nowadays, this is less relevant, with lots of stuff handled by lua instead. Best wishes, Taco
On Thu, 24 May 2018 11:24:34 +0200
Christoph Reller
Thank you Hraban for pointing me to the wiki. I was aware of this page but it contains only the case of mandatory arguments in curly braces {} not in brackets [].
One must *not* confuse with the LaTeX convention where "mandatory"
arguments are contained in curly braces and brackets indicate
"optional" arguments.
As Taco states below, curly braces not only give grouping but generally
are used for objects to be typeset, as for \in{Figure}{a} [fig:ref].
For new users, it is worth repeating here that arguments within braces
can be either a comma-separated list of words OR a comma-separated
list of keyword=value pairs, BUT NOT A MIXTURE OF BOTH. Generally, a
keyword=value exists for all words, for example \cite[authoryear][ref]
and \cite[alternative=authoryear,reference=ref]
values can be grouped using curly braces, as in
\cite[alternative=authoryear,lefttext={{see },}][ref1,ref2] where the
lefttext is associated with the first cite reference (and none with the
second). This can be tricky but is in fact rather straight-forward.
Alan
P.S. The wiki is only as good as users make it; some pages have not
been changed since mkii...
On Thu, 24 May 2018 15:43:27 +0200
Taco Hoekwater
The original intent was for user-level commands to have square brackets for arguments setting things up, and curly braces for arguments that are actually typeset. That is where commands like \in come from, where the braced part is optional and the bracketed part required.
participants (4)
-
Alan Braslau
-
Christoph Reller
-
Henning Hraban Ramm
-
Taco Hoekwater