From: Hans Hagen via ntg-context <ntg-context@ntg.nl>
To: Henning Hraban Ramm <texml@fiee.net>,
mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Hans Hagen <j.hagen@freedom.nl>
Subject: [NTG-context] Re: defining macros
Date: Fri, 10 Jan 2025 19:45:35 +0100 [thread overview]
Message-ID: <ce185701-7719-4a1b-bbed-4c67010e382b@freedom.nl> (raw)
In-Reply-To: <d48d5348-490d-440a-b629-15f3e3888c50@fiee.net>
On 1/10/2025 12:55 PM, Henning Hraban Ramm wrote:
> Hi, I just recognized that I’m not sure how to define a macro with
> optional and mandatory arguments the best way.
>
> E.g. (oldfashioned)
>
> \def\doMyMacro[#1]#2%
> {Do something ... \iffirstargument #1\fi #2}
>
> \def\MyMacro%
> {\dosingleargument\doMyMacro}
\tolerant\def\MyMacro[#1]#:#2%
{\ifparameter#1\or
(#1)
\fi
/#2/}
\MyMacro[one]{two}
\MyMacro{two}
> Is this still the way to do it?
> Does it also work with \define?
>
> I have more questions like that:
>
> From Wolfgang’s presentation (article in progress…) I know all the cool
> stuff for modules (namespaces, setup helpers…), I also know the Lua way
> of interface.implement, but how to combine those?
>
> When should I use brackets or other characters in a definition, when not?
optionals normally have []
> Which docs should I read?
how about lowlevel-macros .. but haven't you read all of them by now ?
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 / 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:[~2025-01-10 18:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-10 11:55 [NTG-context] " Henning Hraban Ramm
2025-01-10 18:45 ` Hans Hagen via ntg-context [this message]
2025-01-10 22:04 ` [NTG-context] " Henning Hraban Ramm
2025-01-10 23:19 ` Hans Hagen
2025-01-11 9:21 ` Henning Hraban Ramm
2025-01-11 11:30 ` Hans Hagen via ntg-context
2025-01-14 17:50 ` Henning Hraban Ramm
2025-01-14 18:27 ` 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=ce185701-7719-4a1b-bbed-4c67010e382b@freedom.nl \
--to=ntg-context@ntg.nl \
--cc=j.hagen@freedom.nl \
--cc=texml@fiee.net \
/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).