From: Denis Maier via ntg-context <ntg-context@ntg.nl>
To: <ntg-context@ntg.nl>
Cc: denis.maier@unibe.ch
Subject: Re: process list items differently depending on position in list
Date: Mon, 2 May 2022 11:50:15 +0000 [thread overview]
Message-ID: <6c45efbd20d24aaeb625cd47cf7f65de@unibe.ch> (raw)
In-Reply-To: <1b7b005a-ee40-d581-aebb-c9697f6d7749@xs4all.nl>
> -----Ursprüngliche Nachricht-----
> Von: ntg-context <ntg-context-bounces@ntg.nl> Im Auftrag von Hans Hagen
> via ntg-context
> Gesendet: Montag, 2. Mai 2022 12:34
> An: Denis Maier via ntg-context <ntg-context@ntg.nl>
> Cc: Hans Hagen <j.hagen@xs4all.nl>
> Betreff: Re: [NTG-context] process list items differently depending on
> position in list
>
> On 5/2/2022 12:09 PM, Denis Maier via ntg-context wrote:
>
> > But, it’d still love to hear whether there is a solution on the tex side.
> \processtokens {[before]} {[between]} {[after]} {[space]} {{one}{two}{three}}
>
> \def\whatever{a,b,c,d}
>
> \getcommacommandsize[\whatever]
> \scratchcounterone \zerocount
> \scratchcountertwo \commalistsize
>
> \processcommacommand[\whatever]
> {\advance\scratchcounterone\plusone
> \ifnum\scratchcounterone=\scratchcountertwo
> \space and\space
> \orelse\ifnum\scratchcounterone>\plusone
> ,\space
> \fi
> \commalistelement}
Thanks.
>
> but ... there's also:
>
> \startlines
> \commalistsentence[aap,noot,mies]
> \commalistsentence[aap,noot]
> \commalistsentence[aap]
> \commalistsentence[a,b,c]
> \commalistsentence[a,b,c][{ \& },{ and }] \commalistsentence[a,b,c][+,-]
> \stoplines
>
> which uses presets like
>
> \setuplabeltext [nl] [and-1={{, }}, and-2={{ en }}] % 1, 2 en 3
> \setuplabeltext [en] [and-1={{, }}, and-2={{, }}] % 1, 2, 3
> \setuplabeltext [de] [and-1={{, }}, and-2={{ und }}] % 1, 2 und 3
> \setuplabeltext [hr] [and-1={{, }}, and-2={{ i }}] % 1, 2 i 3
>
> maybe wikify
I've just checked, \commalistsentence is already on the wiki, but you have to know it exists. (I'll check whether I can link to that page from somewhere.)
But there's no (high-level) way to apply certain commands to this list elements, right?
Background: My real use case is a bit more complex. I use comma separated lists to store author lists, but the authors themselves are saved in structured variables. So, I'll need to reassemble the different name parts first.
So, nothing like
\commalistprocessandmakesentence[a,b,c]\commandforfirst\commandforinbetween\commandforlast
Probably to specific, right?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\startbuffer[test]
<?xml version='1.0' standalone='yes?>
<document>
<title>This is the title</title>
<author>
<family-name>Doe</family-name>
<given-name>John</given-name>
</author>
<author>
<family-name>Smith</family-name>
<given-name>Jane</given-name>
</author>
<p>This is a first sentence</p>
</document>
\stopbuffer
\startxmlsetups xml:setup
\xmlsetsetup{\xmldocument}{*}{-}
\xmlsetsetup{\xmldocument}{document|p}{xml:*}
\stopxmlsetups
\xmlregistersetup{xml:setup}
\startxmlsetups xml:document
\xmlfilter{#1}{/title/command(xml:title)}
\xmlfilter{#1}{/author/command(xml:author)}
\startdocument
\xmlflush{#1}
\stopdocument
\stopxmlsetups
\startxmlsetups xml:title
\setupdocument[title={\xmlflush{#1}},author={\AuthorList}]
\stopxmlsetups
\startxmlsetups xml:author:family-name
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:author:given-name
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:author
\defineauthor[\xmlfilter{#1}{/family-name/command(xml:author:family-name)}\xmlfilter{#1}{/given-name/command(xml:author:given-name)}][family-name={\xmlfilter{#1}{/family-name/command(xml:author:family-name)}},given-name={\xmlfilter{#1}{/given-name/command(xml:author:given-name)}}]
\addtocommalist {\xmlfilter{#1}{/family-name/command(xml:author:family-name)}\xmlfilter{#1}{/given-name/command(xml:author:given-name)}} \AuthorList
\stopxmlsetups
\startxmlsetups xml:p
\xmlflush{#1}\par
\stopxmlsetups
\definenamespace
[documentauthor] % name of internal varialbles
[type=module,
name=author,
command=yes, % Create \defineauthor
style=yes, % Create \useauthorstyleandcolor
setup=list, % Create \setupauthor
parent=documentauthor,
]
\def\AuthorList{}
\define[1]\useauthor
{\edef\currentauthor{#1}%
{\authorparameter{given-name}
\space
\authorparameter{family-name}}}
\startsetups document:start
\documentvariable{title}\endgraf
\blank[medium]
\processcommacommand[\documentvariable{author}]\useauthor
\endgraf
\stopsetups
\xmlprocessbuffer{main}{test}{}
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
prev parent reply other threads:[~2022-05-02 11:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-02 7:14 Denis Maier via ntg-context
2022-05-02 10:09 ` Denis Maier via ntg-context
2022-05-02 10:33 ` Hans Hagen via ntg-context
2022-05-02 11:50 ` Denis Maier via ntg-context [this message]
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=6c45efbd20d24aaeb625cd47cf7f65de@unibe.ch \
--to=ntg-context@ntg.nl \
--cc=denis.maier@unibe.ch \
/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).