From riccardomazzarini8@gmail.com Tue Aug 17 16:43:56 2021 From: noib3 To: ntg-context@ntg.nl Subject: [NTG-context] Using Lua to format lecture titles Date: Tue, 17 Aug 2021 16:43:43 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6623604750004995216==" --===============6623604750004995216== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit I'm trying to create a new lecture environment starting from the base section. I'd like its title to be `Lecture : ` if a title is provided, and `Lecture <number>` if it isn't. This title should also be reported in the left footer and in the table of contents. This is the code I have so far: ``` \definehead [lecture] [section] \setuphead [lecture] [ command=\Lecture, style=\bfc, ] \setuplabeltext [lecture={Lecture}] \define[2]\Lecture{\ctxlua{ userdata.format_lecture_title({ label = context.labeltext('lecture'), number = [==[#1]==], title = [==[#2]==], }) }} \setupfootertexts [\ctxlua{ userdata.format_lecture_title({ label = context.labeltext('lecture'), number = context.getmarking({'lecturenumber'}), title = context.getmarking({'lecture'}), }) }] [pagenumber] \startluacode userdata = userdata or {} function userdata.format_lecture_title(args) if args.title and args.title ~= '' then context('%s %s: %s', args.label, args.number, args.title) else context('%s %s', args.label, args.number) end end \stopluacode \setupcombinedlist [content] [list={lecture}] \setuplist [lecture] [ alternative=c, command=\Lecture, % this seems to have no effect? ] \starttext \completecontent % Both title and left footer should be 'Lecture 1: Foo' \startlecture [title={Foo}] Foo bar baz \stoplecture \page % Both title and left footer should be 'Lecture 2' \startlecture [] Foo bar baz \stoplecture \stoptext ``` Unfortunately none of them are reported correctly. The title in the body is formatted simply as `Lecture`, the one in the left footer is formatted as `Lecture<number><title>`, and the one in the table of contents isn't affected at all. What am I doing wrong? --===============6623604750004995216== Content-Type: text/html Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="attachment.html" MIME-Version: 1.0 PGRpdiBkaXI9Imx0ciI+SSYjMzk7bSB0cnlpbmcgdG8gY3JlYXRlIGEgbmV3IGxlY3R1cmUgZW52 aXJvbm1lbnQgc3RhcnRpbmcgZnJvb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29tcGxldGVjb250ZW50PGJyPjxicj4lIEJvdGggdGl0bGUgYW5kIGxlZnQg Zm9vdGVyIHNob3VsZCBiZSAmIzM5O0xlY3R1cmUgMTogRm9vJiMzOTs8YnI+XHN0YXJ0bGVjdHVy ZSBbdGl0bGU9e0Zvb31dPGJyPkZvbyBiYXIgYmF6PGJyPlxzdG9wbGVjdHVyZTxicj48YnI+XHBh Z2U8YnI+PGJyPiUgQm90aCB0aXRsZSBhbmQgbGVmdCBmb290ZXIgc2hvdWxkIGJlICYjMzk7TGVj dHVyZSAyJiMzOTs8YnI+XHN0YXJ0bGVjdHVyZSBbXTxicj5Gb28gYmFyIGJhejxicj5cc3RvcGxl Y3R1cmU8YnI+PGJyPlxzdG9wdGV4dDxicj5gYGA8YnI+PGJyPlVuZm9ydHVuYXRlbHkgbm9uZSBv ZiB0aGVtIGFyZSByZXBvcnRlZCBjb3JyZWN0bHkuIFRoZSB0aXRsZSBpbiB0aGUgYm9keSBpcyBm b3JtYXR0ZWQgc2ltcGx5IGFzIGBMZWN0dXJlYCwgdGhlIG9uZSBpbiB0aGUgbGVmdCBmb290ZXLC oGlzIGZvcm1hdHRlZCBhcyBgTGVjdHVyZSZsdDtudW1iZXImZ3Q7Jmx0O3RpdGxlJmd0O2AsIGFu ZCB0aGUgb25lIGluIHRoZSB0YWJsZSBvZiBjb250ZW50cyBpc24mIzM5O3QgYWZmZWN0ZWQgYXQg YWxsLjxicj48YnI+V2hhdCBhbSBJIGRvaW5nIHdyb25nPzxicj48L2Rpdj4K --===============6623604750004995216==-- From wolfgang.schuster.lists@gmail.com Tue Aug 17 17:32:08 2021 From: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com> To: ntg-context@ntg.nl Subject: Re: [NTG-context] Using Lua to format lecture titles Date: Tue, 17 Aug 2021 17:32:04 +0200 Message-ID: <22e74d17-f9e8-cf45-59a8-155f3a47e422@gmail.com> In-Reply-To: <CAPj2zL4ne2mUzZE8LxsgE9KbNfQG4-3fcnL1mFCrikSyKXs2+Q@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8147647583050730965==" --===============8147647583050730965== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit noib3 via ntg-context schrieb am 17.08.2021 um 16:43: > I'm trying to create a new lecture environment starting from the base > section. > > I'd like its title to be `Lecture <number>: <title>` if a title is > provided, and `Lecture <number>` if it isn't. This title should also be > reported in the left footer and in the table of contents. > > This is the code I have so far: > > [...] > > Unfortunately none of them are reported correctly. The title in the body > is formatted simply as `Lecture`, the one in the left footer is > formatted as `Lecture<number><title>`, and the one in the table of > contents isn't affected at all. Why do you need Lua to format the list entries and section titles? \definehead [lecture] [section] \define[1]\LectureTextCommand {\doiftext{#1}{: #1}} \setuphead [lecture] [bodypartlabel=lecture, distance=0pt, textcommand=\LectureTextCommand, style=\bfc] \setuplabeltext [en] [lecture={Lecture }] \setupcombinedlist [content] [list={lecture}] \define[3]\LectureListCommand {\labeltext{lecture}#1\doiftext{#2}{: #2}\filler[dotfill]#3\par} \setuplist [lecture] [alternative=command, command=\LectureListCommand] \startsetups [footer:left] \labeltext{lecture} \getmarking[lecturenumber] \doiftext{\getmarking[lecture]}{: \getmarking[lecture]} \stopsetups \setupfootertexts [\directsetup{footer:left}] [] \starttext \completecontent \startlecture [title={Foo}] Foo bar baz \stoplecture \page \startlecture Foo bar baz \stoplecture \stoptext Wolfgang --===============8147647583050730965==--