From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: from cgl.ntg.nl (Cgl.ntg.nl [5.39.185.202]) by inbox.vuxu.org (Postfix) with ESMTP id 6D40C29373 for ; Mon, 4 Nov 2024 18:57:21 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 1331E484BF9 for ; Mon, 4 Nov 2024 18:54:34 +0100 (CET) Authentication-Results: cgl.ntg.nl (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=ntg.nl DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ntg.nl; h= content-transfer-encoding:content-type:content-type:from:from :list-unsubscribe:list-subscribe:list-post:list-owner:list-help :list-archive:archived-at:list-id:subject:subject:reply-to :precedence:in-reply-to:references:content-language:mime-version :date:date:message-id:received:received:received:received :received:received:received; s=cgl; t=1730742873; x=1733334874; bh=s3ujl9TA3PESyAaJiIyiXXyJ0i75ew/V9hM/hMX5Hnk=; b=YLP5Q6aj2Buv C3/NxShxKN4MITnTXe5Hqw9LnLPxGV2ZGdN13rYiJhu+3Y+I4pVEsFHKhyGHULBU h0Yjw8remQiFYFWWEXPBOtELcDzXZr7XBzhXxq5/YFQ4GzOA2rT1fA1iy8V1LGzM MLhboVpOMe23ccFO78F57+9DEzl1tmY= X-Virus-Scanned: Debian amavisd-new at cgl.ntg.nl Authentication-Results: cgl.ntg.nl (amavisd-new); dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=freedom.nl header.b="rEqdrUup"; dkim=fail (2048-bit key) reason="fail (message has been altered)" header.d=freedom.nl header.b="PFNseWzn" Received: from cgl.ntg.nl ([127.0.0.1]) by localhost (cgl.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rlttD6T5XJYN for ; Mon, 4 Nov 2024 18:54:33 +0100 (CET) Received: from cgl.ntg.nl (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 2D749484E8C for ; Mon, 4 Nov 2024 18:53:28 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 4F3F9484776 for ; Mon, 4 Nov 2024 18:52:45 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at cgl.ntg.nl Received: from cgl.ntg.nl ([127.0.0.1]) by localhost (cgl.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jPvxMTRuJOGK for ; Mon, 4 Nov 2024 18:52:44 +0100 (CET) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=185.233.34.18; helo=outbound.soverin.net; envelope-from=j.hagen@freedom.nl; receiver= Received: from outbound.soverin.net (outbound.soverin.net [185.233.34.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cgl.ntg.nl (Postfix) with ESMTPS id D8851484732 for ; Mon, 4 Nov 2024 18:52:44 +0100 (CET) Received: from smtp.freedom.nl (unknown [10.10.4.108]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 4XhzZh3Bvfz3p for ; Mon, 4 Nov 2024 17:52:44 +0000 (UTC) Received: from smtp.freedom.nl (smtp.freedom.nl [10.10.4.108]) by freedom.nl (Postfix) with ESMTPSA id 4XhzZg6Q3gz2xM3 for ; Mon, 4 Nov 2024 17:52:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=freedom.nl; s=default; t=1730742764; bh=bY0jTjGJbil890qNzUoB3BKbBCPa2a4whEtPVwLQ4Ic=; h=Date:Subject:To:References:From:In-Reply-To:From; b=rEqdrUup3GOp4JOht7WWHC1R/8+48hGV4DWMS3kS52pwnwtQbezKgHpF0D/HiO8H+ Uv7rfxLQToSstz8kcqBVPmuJfbsqouDWYvcZ+VtSsGd5NsuGvhBUiQGPP3io7+SUE1 +FXxyq9ePxs3eyiJE46BLtX2ciVWkeIZQF/pShHI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freedom.nl; s=soverin1; t=1730742764; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fyfMlf2uHlSqF44BeF6Am1pBAPsgUVrBiEKellyhp8I=; b=PFNseWznbFXpjUfeqkukxatL6b/xwpTOYM1V/uXI6V4jCxuSocbezSfS6LhkJALZmsgl8E XFHcfR6YM9DdtuNnhulI4iKK1pPwFjrI3IVskZspB55c5NAWw9qN0DxgLFZMN9DDo4mHlu NKPWvrZoeI8R7J50qpTV1vaUWhNk3oxDf6Al/FTwjwPOPYk9ctTULPSoY4hTFx1iYBe9go Mpy+V3o8iwHdMvR9sYwNv06jyRBHTuQKzTgQ00Br927HwjLI2JDbWmD8KdzkBmhe1F5bfg ocw68/r1WSEjRdtGZxPe5fDtXoxGvv0TQdVmw6TEN6UeK2LUVHOAnYiLDtpnPg== ARC-Seal: i=1; s=default; d=freedom.nl; t=1730742764; a=rsa-sha256; cv=none; b=HLNZpPrm/cagnhKHQYkdNDyFVbCuzAZFeXlOK8weTi5pnQtWZsFYFpXjKiXTuEGCti4fmY VX9UnuyVCQbNbNdDDwNYKV9/X39vD9RPPEeEkb/IE+/d9+UQpkhzsH4iympMsiTjMZcXps vxC9GnGx694h8JVzqxBpwBJHjUMVLTI= ARC-Authentication-Results: i=1; smtp.freedom.nl; auth=pass smtp.mailfrom=j.hagen@freedom.nl ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freedom.nl; s=default; t=1730742764; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fyfMlf2uHlSqF44BeF6Am1pBAPsgUVrBiEKellyhp8I=; b=hAFJhwhVkPFVMhd62ssvwyiVMguxsxhKsI7UjTYNEKsd5zo2rA1Or4BQM2Ty7uLqL3/IbQ RhY5NvL7PpQUmvTsfoBql1fyE1I16eDwaDMMUsoY5775X8v+58XdtHLAo9OZPCMDU5hzBa zl2Evp/x66LPNrRTOGkJiEbb3deYp98= Message-ID: <9ce0b651-44c8-4c34-beec-5da7de645d53@freedom.nl> Date: Mon, 4 Nov 2024 18:52:43 +0100 MIME-Version: 1.0 Content-Language: nl To: ntg-context@ntg.nl References: <692582251.5119511.1730577725919.ref@mail.yahoo.com> <692582251.5119511.1730577725919@mail.yahoo.com> <544F4782-4007-4CBC-8F2F-30299E93B906@scorecrow.com> In-Reply-To: <544F4782-4007-4CBC-8F2F-30299E93B906@scorecrow.com> X-Spampanel-Class: ham Message-ID-Hash: 4FLOCQOKN6TQXIDJI6NSX46F2IA45TU7 X-Message-ID-Hash: 4FLOCQOKN6TQXIDJI6NSX46F2IA45TU7 X-MailFrom: j.hagen@freedom.nl X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list Reply-To: mailing list for ConTeXt users Subject: [NTG-context] Re: How can a macro check how many items are in a list? List-Id: mailing list for ConTeXt users Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Hans Hagen via ntg-context Cc: Hans Hagen Content-Type: text/plain; charset="us-ascii"; format="flowed" Content-Transfer-Encoding: 7bit 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 ----------------------------------------------------------------- ___________________________________________________________________________________ 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 ___________________________________________________________________________________