On 11/3/2024 5:53 PM, Bruce Horrocks wrote:
\definecounter [MyItemsCounter] \definecounter [MyItemsUniqueID] [way=bytext] \setcounter [MyItemsUniqueID] [1]
\definedataset [MyItems] [delay=yes]
\defineitemgroup [MyItems] \setupitemgroup [MyItems] [ before={\setcounter[MyItemsCounter][1]}, inbetween={\incrementcounter[MyItemsCounter]}, after={\setdataset[MyItems][\rawcountervalue[MyItemsUniqueID]][count=\rawcountervalue[MyItemsCounter]]% \incrementcounter[MyItemsUniqueID]}, ]
\define\listLen{\datasetvariable{MyItems}{\rawcountervalue[MyItemsUniqueID]}{count}} \define\itemOrItems{\doifelse{\datasetvariable{MyItems}{\rawcountervalue[MyItemsUniqueID]}{count}}{1}{item}{items}}
\starttext
This list has \listLen\ \itemOrItems. \startMyItems \item cat \item dog \item tree \stopMyItems
\blank
This list has \listLen\ \itemOrItems. \startMyItems \item cow \stopMyItems
\stoptext
There is actually some info when you are in an itemize: \currentitemindex \currentnofitems So it's not too hard to get the upcoming value of \currentnofitems: (1) an extra helper in strc-itm.mkxl \permanent\tolerant\protected\def\upcomingnofitems[#1]% {\the\numexpr \clf_analyzeupcomingitemgroup {\ifempty{#1}\v!itemize\else#1\fi}% \numexpr\c_strc_itemgroups_nesting+\plusone\relax \c_strc_itemgroups_max_items \relax} (2) a few line patch in strc-itm.lmt local function analyzeitemgroup(name,level,upcoming) local n = counts[name] local u = false if level == 1 then n = n + 1 counts[name] = n u = upcoming and true end local items = 0 local width = 0 local itemgroup = collected[name] if itemgroup then local entry = itemgroup[n] if entry then local l = entry[level] if l then items = l[1] or 0 width = l[2] or 0 end end end if u then counts[name] = n - 1 end texsetcount(c_strc_itemgroups_max_items,items) texsetdimen(d_strc_itemgroups_max_width,width) end plus extra: implement { name = "analyzeupcomingitemgroup", actions = analyzeitemgroup, arguments = { "string", "integer", true } } And then for Bruce to come up with the singular / plural variant for This list has \upcomingnofitems[MyItems] entries \startMyItems \item cat \item dog \item tree \stopMyItems This list has \upcomingnofitems\ entries \startitemize \item cat \item dog \item tree \stopitemize 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 -----------------------------------------------------------------