From: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
Joel via ntg-context <ntg-context@ntg.nl>
Subject: [NTG-context] Re: How can a macro check how many items are in a list?
Date: Sun, 3 Nov 2024 08:19:00 +0100 [thread overview]
Message-ID: <6e210335-ab71-2a6e-b80d-2b13b1559e33@gmail.com> (raw)
In-Reply-To: <692582251.5119511.1730577725919@mail.yahoo.com>
Joel via ntg-context schrieb am 02.11.2024 um 21:02:
> Suppose I have a macro like this:
>
>
> \define[1]\thisismylist{
>
> This list has n items.
>
> \startitemize
> #1
> \stopitemize
>
> }
>
> And in the document it might have this:
>
> \thisismylist{
> \item cat
> \item dog
> \item tree
> }
>
> How can I make n display three, as there are three items?
>
> "This list has 3 items:
>
> 1. cat
> 2. dog
> 3. tree
>
> I will use this as a means to check if the description before a list
> needs a plural or not:
>
> Read the prompts below:
>
> - Do you think cats should be banned from university dormitories?
> - Should public schools provide free breakfast?
>
> And that way, if there is only one prompt, it changes the instructions
> to be:
>
> Read the prompt below:
>
> - Do you think cats should be banned from university dormitories?
When you pass your itemize entries as comma separated list you can use
the \getcommalistsize command to count the list entries.
Afterwards use \doloopoverlist to create an itemize entry for each text
in the comma separated list.
%%%% begin example
\starttexdefinition protected thisiymylist [#1]
\getcommalistsize[#1]
\doifelse{\commalistsize}{1}
{Read the prompt below:\par}
{Read the prompts below:\par}
\startitemize
\doloopoverlist{#1}{\startitem\recursestring\stopitem}
\stopitemize
\stoptexdefinition
\starttext
\thisiymylist
[Do you think cats should be banned from university dormitories?,
Should public schools provide free breakfast?]
\thisiymylist
[Do you think cats should be banned from university dormitories?]
\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
___________________________________________________________________________________
next prev parent reply other threads:[~2024-11-03 7:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <692582251.5119511.1730577725919.ref@mail.yahoo.com>
2024-11-02 20:02 ` [NTG-context] " Joel via ntg-context
2024-11-03 7:19 ` Wolfgang Schuster [this message]
2024-11-03 11:04 ` [NTG-context] " vm via ntg-context
2024-11-03 16:53 ` Bruce Horrocks
2024-11-04 17:52 ` Hans Hagen via ntg-context
2024-11-05 18:21 ` Bruce Horrocks
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=6e210335-ab71-2a6e-b80d-2b13b1559e33@gmail.com \
--to=wolfgang.schuster.lists@gmail.com \
--cc=ntg-context@ntg.nl \
/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).