![](https://secure.gravatar.com/avatar/a3a76177277476240dee1967f4b9a616.jpg?s=120&d=mm&r=g)
Hello: I am trying to print a list of names always followed by the same info (generated by a new command). At the moment, I have all the names followed by the command like so: Person Number One \mycommand Person Number Two \mycommand Person Number Three \mycommand Person Number Four \mycommand Person Number Five \mycommand . . . I'd rather have the list of people stored somewhere (a list? an array?) and loop through it and then inserting \mynewcommand at compilation time. That way, when I need to replace the list of people with a new one, I'd just do that instead of building the above structure again and again. Is it possible to do that with just ConTeXt or would I need to resort to Lua. I guess it should be possible both ways, but I haven't figure out how to do it. Any pointer, please? Thank you so much in advance. Cheers, Ángel
![](https://secure.gravatar.com/avatar/d0e94fb08d4620cfbd2f8f59a7868637.jpg?s=120&d=mm&r=g)
On 2/12/21 7:39 PM, Angel M Alganza wrote:
Is it possible to do that with just ConTeXt or would I need to resort to Lua. I guess it should be possible both ways, but I haven't figure out how to do it. Any pointer, please?
https://wiki.contextgarden.net/Processing_Lists which wasn't particularly difficult to find. Thomas
![](https://secure.gravatar.com/avatar/23c65792d6f3eb5f6194f6ec9eadc2ac.jpg?s=120&d=mm&r=g)
Hi, Ángel. Like this? \def\mylist{Fulano,Mengano,Sutano} \def\mycommand#1{#1\blank{\red Something here}\blank} \starttext \processcommacommand[\mylist]\mycommand \stoptext There are better ways to deal with data in ConTeXt, but it's basically that way, I think. Jairo El vie, 12 de feb. de 2021 a la(s) 13:44, Angel M Alganza (ama@ugr.es) escribió:
Hello:
I am trying to print a list of names always followed by the same info (generated by a new command). At the moment, I have all the names followed by the command like so:
Person Number One \mycommand Person Number Two \mycommand Person Number Three \mycommand Person Number Four \mycommand Person Number Five \mycommand . . .
I'd rather have the list of people stored somewhere (a list? an array?) and loop through it and then inserting \mynewcommand at compilation time. That way, when I need to replace the list of people with a new one, I'd just do that instead of building the above structure again and again.
Is it possible to do that with just ConTeXt or would I need to resort to Lua. I guess it should be possible both ways, but I haven't figure out how to do it. Any pointer, please?
Thank you so much in advance.
Cheers, Ángel
___________________________________________________________________________________ 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
___________________________________________________________________________________
![](https://secure.gravatar.com/avatar/23c65792d6f3eb5f6194f6ec9eadc2ac.jpg?s=120&d=mm&r=g)
Oops, it's "zutano". Sorry for the typo. Jairo :) El vie, 12 de feb. de 2021 a la(s) 13:50, Jairo A. del Rio ( jairoadelrio6@gmail.com) escribió:
Hi, Ángel. Like this?
\def\mylist{Fulano,Mengano,Sutano}
\def\mycommand#1{#1\blank{\red Something here}\blank}
\starttext
\processcommacommand[\mylist]\mycommand
\stoptext
There are better ways to deal with data in ConTeXt, but it's basically that way, I think.
Jairo
El vie, 12 de feb. de 2021 a la(s) 13:44, Angel M Alganza (ama@ugr.es) escribió:
Hello:
I am trying to print a list of names always followed by the same info (generated by a new command). At the moment, I have all the names followed by the command like so:
Person Number One \mycommand Person Number Two \mycommand Person Number Three \mycommand Person Number Four \mycommand Person Number Five \mycommand . . .
I'd rather have the list of people stored somewhere (a list? an array?) and loop through it and then inserting \mynewcommand at compilation time. That way, when I need to replace the list of people with a new one, I'd just do that instead of building the above structure again and again.
Is it possible to do that with just ConTeXt or would I need to resort to Lua. I guess it should be possible both ways, but I haven't figure out how to do it. Any pointer, please?
Thank you so much in advance.
Cheers, Ángel
___________________________________________________________________________________ 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
___________________________________________________________________________________
![](https://secure.gravatar.com/avatar/74d41c3215dcdd377343cdc47311757c.jpg?s=120&d=mm&r=g)
Jairo A. del Rio schrieb am 12.02.2021 um 19:50:
Hi, Ángel. Like this?
\def\mylist{Fulano,Mengano,Sutano}
\def\mycommand#1{#1\blank{\red Something here}\blank}
\starttext
\processcommacommand[\mylist]\mycommand
\stoptext
There are better ways to deal with data in ConTeXt, but it's basically that way, I think.
You can use the commalist environment: \starttext \startprocesscommalist[One,Two,Three,Four] Person Number \currentcommalistitem\par \stopprocesscommalist \blank \defineexpandable\NameList{One,Two,Three,Four} \startprocesscommacommand[\NameList] Person Number \currentcommalistitem\par \stopprocesscommacommand \stoptext Another way is to use the database module: \usemodule[database] \starttext \defineseparatedlist [namelist] [command=\NameEntry] \starttexdefinition unexpanded NameEntry #1 Person Number #1\par \stoptexdefinition \startseparatedlist[namelist] One Two Three Four \stopseparatedlist \stoptext Wolfgang
![](https://secure.gravatar.com/avatar/23c65792d6f3eb5f6194f6ec9eadc2ac.jpg?s=120&d=mm&r=g)
Oh, I knew about the environment form, but I didn't know about \currentcommalistitem. Useful to avoid to define ad hoc commands :) As always, thank you very much for the lesson. Best regards, Jairo El vie, 12 de feb. de 2021 a la(s) 14:25, Wolfgang Schuster ( wolfgang.schuster.lists@gmail.com) escribió:
Jairo A. del Rio schrieb am 12.02.2021 um 19:50:
Hi, Ángel. Like this?
\def\mylist{Fulano,Mengano,Sutano}
\def\mycommand#1{#1\blank{\red Something here}\blank}
\starttext
\processcommacommand[\mylist]\mycommand
\stoptext
There are better ways to deal with data in ConTeXt, but it's basically that way, I think.
You can use the commalist environment:
\starttext
\startprocesscommalist[One,Two,Three,Four] Person Number \currentcommalistitem\par \stopprocesscommalist
\blank
\defineexpandable\NameList{One,Two,Three,Four}
\startprocesscommacommand[\NameList] Person Number \currentcommalistitem\par \stopprocesscommacommand
\stoptext
Another way is to use the database module:
\usemodule[database]
\starttext
\defineseparatedlist [namelist] [command=\NameEntry]
\starttexdefinition unexpanded NameEntry #1 Person Number #1\par \stoptexdefinition
\startseparatedlist[namelist] One Two Three Four \stopseparatedlist
\stoptext
Wolfgang
![](https://secure.gravatar.com/avatar/a3a76177277476240dee1967f4b9a616.jpg?s=120&d=mm&r=g)
On Fri, Feb 12, 2021 at 02:48:23PM -0500, Jairo A. del Rio wrote:
Oh, I knew about the environment form, but I didn't know about
El vie, 12 de feb. de 2021 a la(s) 14:25, Wolfgang Schuster ( wolfgang.schuster.lists@gmail.com) escribió:
You can use the commalist environment:
Another way is to use the database module:
Thank you so much, Jairo and Wolfgang. All your solutions work fine! I had been looking for info on loops and some other ideas for a few days already. I never thought about "lists". :-) Cheers, Ángel
![](https://secure.gravatar.com/avatar/74d41c3215dcdd377343cdc47311757c.jpg?s=120&d=mm&r=g)
Angel M Alganza schrieb am 13.02.2021 um 11:42:
On Fri, Feb 12, 2021 at 02:48:23PM -0500, Jairo A. del Rio wrote:
Oh, I knew about the environment form, but I didn't know about
El vie, 12 de feb. de 2021 a la(s) 14:25, Wolfgang Schuster ( wolfgang.schuster.lists@gmail.com) escribió:
You can use the commalist environment:
Another way is to use the database module:
Thank you so much, Jairo and Wolfgang. All your solutions work fine!
I had been looking for info on loops and some other ideas for a few days already. I never thought about "lists". :-)
Below is another version. Using the \startsetups block to set the content for the loop/list makes it easier to strucuture (format) the text. With \recursestring you can print the value of the current loop entry. The list of entries for the loop can be moved from the argument itself to a macro. To make adding and removing (can be done by commenting entries with %) you can use the \starttexdefinition environment with each name on a separate line. %%%% begin example \starttext \startsetups [NameEntry] Person Number \recursestring\par \stopsetups \doloopoverlist{One,Two,Three,Four}{\directsetup{NameEntry}} \blank %\defineexpandable\NameList % {One, % Two, % Three, % Four} \starttexdefinition NameList One, Two, Three, Four \stoptexdefinition \doloopoverlist{\NameList}{\directsetup{NameEntry}} \stoptext %%%% end example Wolfgang
![](https://secure.gravatar.com/avatar/a3a76177277476240dee1967f4b9a616.jpg?s=120&d=mm&r=g)
On Sat, Feb 13, 2021 at 12:12:47PM +0100, Wolfgang Schuster wrote:
Using the \startsetups block to set the content for the loop/list makes it easier to strucuture (format) the text. With \recursestring you can print the value of the current loop entry.
Very nice and easy to maintain the list of names. Thank you so much! Cheers, Ángel
![](https://secure.gravatar.com/avatar/46562c7d27388490d62e8d7a5bc960dd.jpg?s=120&d=mm&r=g)
On 2/13/2021 2:23 PM, Angel M Alganza wrote:
On Sat, Feb 13, 2021 at 12:12:47PM +0100, Wolfgang Schuster wrote:
Using the \startsetups block to set the content for the loop/list makes it easier to strucuture (format) the text. With \recursestring you can print the value of the current loop entry.
Very nice and easy to maintain the list of names. You have to wikify all the answers ... here's another one:
\doloopovermatch {([^\letterpercent s,]+)} {aa, bb, cc, dd} {/#1/} or more complex matching: \doloopovermatch {(\letterpercent w+) *(\letterpercent w*)} {aa bb cc dd} { [ \doloopovermatch{(\letterpercent w)(\letterpercent w)} {#1} {(##1 ##2)} \doloopovermatch{(\letterpercent w)(\letterpercent w)} {#2} {(##1 ##2)} ] } 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 -----------------------------------------------------------------
![](https://secure.gravatar.com/avatar/a3a76177277476240dee1967f4b9a616.jpg?s=120&d=mm&r=g)
Hi Jairo: On Fri, Feb 12, 2021 at 01:50:58PM -0500, Jairo A. del Rio wrote:
Hi, Ángel. Like this?
\def\mylist{Fulano,Mengano,Sutano} \def\mycommand#1{#1\blank{\red Something here}\blank} \starttext \processcommacommand[\mylist]\mycommand \stoptext
Yes, exactly like this, thank you. Now, I have the names writen like: Family Name, Name So, is it possible to use a list separatd by something else than a comma? A semicolon, for example? To test I've replaced those commas by a colon and it works fine, but I'd rather have a comma, if possible. Again, thank you so much! Cheers, Ángel
![](https://secure.gravatar.com/avatar/23c65792d6f3eb5f6194f6ec9eadc2ac.jpg?s=120&d=mm&r=g)
There's \processseparatedlist[<list>][<separator>]\command with an arbitrary <separator> other than a comma... You should take a look at syst-aux.mkiv and syst-aux.mkxl to see more helpers: https://source.contextgarden.net/tex/context/base/mkiv/syst-aux.mkxl El vie, 12 de feb. de 2021 a la(s) 14:49, Angel M Alganza (ama@ugr.es) escribió:
Hi Jairo:
On Fri, Feb 12, 2021 at 01:50:58PM -0500, Jairo A. del Rio wrote:
Hi, Ángel. Like this?
\def\mylist{Fulano,Mengano,Sutano} \def\mycommand#1{#1\blank{\red Something here}\blank} \starttext \processcommacommand[\mylist]\mycommand \stoptext
Yes, exactly like this, thank you. Now, I have the names writen like:
Family Name, Name
So, is it possible to use a list separatd by something else than a comma? A semicolon, for example? To test I've replaced those commas by a colon and it works fine, but I'd rather have a comma, if possible.
Again, thank you so much!
Cheers, Ángel
___________________________________________________________________________________ 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
___________________________________________________________________________________
participants (5)
-
Angel M Alganza
-
Hans Hagen
-
Jairo A. del Rio
-
Thomas A. Schmitz
-
Wolfgang Schuster