[NTG-context] process list items differently depending on position in list

denis.maier at unibe.ch denis.maier at unibe.ch
Mon May 2 13:50:15 CEST 2022


> -----Ursprüngliche Nachricht-----
> Von: ntg-context <ntg-context-bounces at 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 at ntg.nl>
> Cc: Hans Hagen <j.hagen at 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}{}






More information about the ntg-context mailing list