Thank you Wolfgang, This was extremely helpful!
Matthias > On Mar 14, 2026, at 2:42 AM, Wolfgang Schuster > <[email protected]> wrote: > > Am 13.03.2026 um 22:25 schrieb Matthias Weber: >> Hello, >> I have a document with ~30 chapters, one for each date of a certain day that >> changes from year to year. >> So I wanted to put the list of dates at the top of the document, where I can >> locate and update them easily, >> and process the list using a little Lua, like so: >> \setupheadertexts[\getmarking[section]] >> >> \def \day{\ctxlua{tex.print(classdates[i]) i=i+1}} >> %\def\day{} >> \ctxlua >> { classdates = {"May 12", "May 13", "May 14", "May 15"} >> i=1} >> \completecontent >> \starttext >> \section{Math (\day)} >> \section{More Math (\day)} >> \section{The End (\day)} >> \stoptext >> Unfortunately, the Lua code is already processed for the table of contents, >> so I ran out of dates in the \section commands. >> A simple hack could be to let Lua go through the list twice — but this >> doesn’t help, as I am also using the name of a section in the header, where >> the counter is being increased >> an undetermined number of times, once for each new page. >> Is there a way to fix this? > > You have to expand the section argument before it is stored to be reused in > the table of content, this can be done with the following setup: > > \setuphead[section][expansion=yes] > > Before you do this you should fix a few of your other problems. > > 1. \complecontent has to be moved after \starttext to ensure it uses the > document font. > > 2. You need a different command for your day entry because \day is a TeX > primitive which holds the value of the current day. > > 3. Don't create global names for you Lua table, functions etc. ConTeXt > provides the documentdata namespace for this. > > %%%% begin example > \startluacode > > documentdata.ClassdatesData = { > "May 12", > "May 13", > "May 14", > "May 15" > } > > documentdata.ClassdatesIndex = 1 > > function documentdata.ClassdatesPrint() > context(documentdata.ClassdatesData[documentdata.ClassdatesIndex]) > documentdata.ClassdatesIndex = documentdata.ClassdatesIndex + 1 > end > > \stopluacode > > %\defineexpandable\Day > % {\ctxlua{ > % context(documentdata.ClassdatesData[documentdata.ClassdatesIndex]) > % documentdata.ClassdatesIndex = documentdata.ClassdatesIndex + 1 > % }} > > \defineexpandable\Classdate > {\ctxlua{documentdata.ClassdatesPrint()}} > > \setupheadertexts > [section] > > \setuphead > [section] > [expansion=yes] > > \starttext > > \completecontent > > \section{Math (\Classdate)} > \section{More Math (\Classdate)} > \section{The End (\Classdate)} > > \stoptext > %%%% end example > > Wolfgang > > ___________________________________________________________________________________ > If your question is of interest to others as well, please add an entry to the > Wiki! > > maillist : [email protected] <mailto:[email protected]> / > https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl > webpage : https://www.pragma-ade.nl <https://www.pragma-ade.nl/> / > https://context.aanhet.net <https://context.aanhet.net/> (mirror) > archive : https://github.com/contextgarden/context > wiki : https://wiki.contextgarden.net <https://wiki.contextgarden.net/> > ___________________________________________________________________________________
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : [email protected] / 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 ___________________________________________________________________________________
