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
___________________________________________________________________________________