From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/112504 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: noib3 via ntg-context Newsgroups: gmane.comp.tex.context Subject: Using Lua to format lecture titles Date: Tue, 17 Aug 2021 16:43:43 +0200 Message-ID: Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1017903237517129738==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36729"; mail-complaints-to="usenet@ciao.gmane.io" Cc: noib3 To: ntg-context@ntg.nl Original-X-From: ntg-context-bounces@ntg.nl Tue Aug 17 16:44:22 2021 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mG0KE-0009Mm-Kw for gctc-ntg-context-518@m.gmane-mx.org; Tue, 17 Aug 2021 16:44:22 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id BC3B82863BF; Tue, 17 Aug 2021 16:43:59 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id m25yH4mujrUJ; Tue, 17 Aug 2021 16:43:58 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id E8950286902; Tue, 17 Aug 2021 16:43:57 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 6D2C72868F7 for ; Tue, 17 Aug 2021 16:43:56 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gU60kHeWqyKC for ; Tue, 17 Aug 2021 16:43:55 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.219.49; helo=mail-qv1-f49.google.com; envelope-from=riccardomazzarini8@gmail.com; receiver= Original-Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 648302868E0 for ; Tue, 17 Aug 2021 16:43:55 +0200 (CEST) Original-Received: by mail-qv1-f49.google.com with SMTP id m3so11324017qvu.0 for ; Tue, 17 Aug 2021 07:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=lRS6+8IAKkvFMEgf3N0nmDtCr0BjlXeCGoSRt5xFeSI=; b=ZYxK8+cWv43Ae8hpOoItpmjOJCOIoq/06XFqW5TRXTOQPCl+j8IUBC6rQMM46CglsX kkDGxjVw2PzU3yfhh79DaWj9Dz6Bb30QwOJ79O4rNWewMO4YIdd03Ty1YAX8vAd5/AJT NUQ2A7HY9S9g1TX2QgO0f16NAbORJrNfHwWE9bcdGm9RiYQfPcvOSj9gZjquc6R6NoBz wC0Qc6XOPgt9wJx7xjQ6ktnoEr9xd8/k5PUp9TGWbxql4kdncUKHKA9a0hrLwxwS86B9 g3IiknqQLRCxhJlP3kpam9XNpaSAjuCNuq6FyZrfInnSXNWyTNUmiVrw0xIhOPaLCI+l N4ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=lRS6+8IAKkvFMEgf3N0nmDtCr0BjlXeCGoSRt5xFeSI=; b=X7iX2yoMu4vB1MkwLdKmkAdTKg6cygYVwMkuCdIf59w6u+MXDEeZVWjCN+hQ/mZTwA XsI/wkRNM9ljokRogfDVjkhCFGHzrtxX4O3mjITVJjKni1+XVmv2OWkHumdePoyVpORr 6wJcqNDVPbUoxuTv4wPvEeywnn1f1gp5o0OrExF0XLGiWh9103bDwd1y9kksQxSIe+0G zsC9dLQs7/GtAoLWhyItCFRM3A0gzHYjHZto1aU2EX7gVL4EMi4fv3l3GRYe9IE6JGQ+ WltYIJikBOmpyaOSYuDIJdBYG1mjdxJN4Le7OTmNV1bKVwVMb3VQfIqYFEHTktf+96NI mpBA== X-Gm-Message-State: AOAM531c4clkoBuNqfZlUA1B9+UCy/5M7JdMz5qjmhvtdQ7pEIhNl7h/ NhPnRTRaMOXeuR1ZdioT2iLoPhqAtczQQ0qsYJhdChf0OFE= X-Google-Smtp-Source: ABdhPJw4B26FbqK73SFgPKE4r8fsc9VB5Z85UaTTs23kpJxm6tnX+xOBcZvkdhqpURhtipRUXnBzeKuOMd+nUIzN1x0= X-Received: by 2002:a05:6214:508c:: with SMTP id kk12mr3736711qvb.30.1629211433734; Tue, 17 Aug 2021 07:43:53 -0700 (PDT) X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:112504 Archived-At: --===============1017903237517129738== Content-Type: multipart/alternative; boundary="000000000000c597fc05c9c2583f" --000000000000c597fc05c9c2583f Content-Type: text/plain; charset="UTF-8" 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? --000000000000c597fc05c9c2583f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">I'm trying to create a new lecture environment startin= g from the base section.<br><br>I'd like its title to be `Lecture <n= umber>: <title>` if a title is provided, and `Lecture <number&g= t;` if it isn't. This title should also be reported in the left footer = and in the table of contents.<br><br>This is the code I have so far:<br><br= >```<br>\definehead<br>=C2=A0 [lecture]<br>=C2=A0 [section]<br><br>\setuphe= ad<br>=C2=A0 [lecture]<br>=C2=A0 [<br>=C2=A0 =C2=A0 command=3D\Lecture,<br>= =C2=A0 =C2=A0 style=3D\bfc,<br>=C2=A0 ]<br><br>\setuplabeltext<br>=C2=A0 [l= ecture=3D{Lecture}]<br><br>\define[2]\Lecture{\ctxlua{<br>=C2=A0 userdata.f= ormat_lecture_title({<br>=C2=A0 =C2=A0 label =3D context.labeltext('lec= ture'),<br>=C2=A0 =C2=A0 number =3D [=3D=3D[#1]=3D=3D],<br>=C2=A0 =C2= =A0 title =3D [=3D=3D[#2]=3D=3D],<br>=C2=A0 })<br>}}<br><br>\setupfootertex= ts<br>=C2=A0 [\ctxlua{<br>=C2=A0 =C2=A0 userdata.format_lecture_title({<br>= =C2=A0 =C2=A0 =C2=A0 label =3D context.labeltext('lecture'),<br>=C2= =A0 =C2=A0 =C2=A0 number =3D context.getmarking({'lecturenumber'}),= <br>=C2=A0 =C2=A0 =C2=A0 title =3D context.getmarking({'lecture'}),= <br>=C2=A0 =C2=A0 })<br>=C2=A0 }]<br>=C2=A0 [pagenumber]<br><br>\startluaco= de<br>=C2=A0 userdata =3D userdata or {}<br><br>=C2=A0 function userdata.fo= rmat_lecture_title(args)<br>=C2=A0 =C2=A0 if args.title and args.title ~=3D= '' then<br>=C2=A0 =C2=A0 =C2=A0 context('%s %s: %s', args.= label, args.number, args.title)<br>=C2=A0 =C2=A0 else<br>=C2=A0 =C2=A0 =C2= =A0 context('%s %s', args.label, args.number)<br>=C2=A0 =C2=A0 end<= br>=C2=A0 end<br>\stopluacode<br><br>\setupcombinedlist<br>=C2=A0 [content]= <br>=C2=A0 [list=3D{lecture}]<br><br>\setuplist<br>=C2=A0 [lecture]<br>=C2= =A0 [<br>=C2=A0 =C2=A0 alternative=3Dc,<br>=C2=A0 =C2=A0 command=3D\Lecture= , % this seems to have no effect?<br>=C2=A0 ]<br><br>\starttext<br><br>\com= pletecontent<br><br>% Both title and left footer should be 'Lecture 1: = Foo'<br>\startlecture [title=3D{Foo}]<br>Foo bar baz<br>\stoplecture<br= ><br>\page<br><br>% Both title and left footer should be 'Lecture 2'= ;<br>\startlecture []<br>Foo bar baz<br>\stoplecture<br><br>\stoptext<br>``= `<br><br>Unfortunately none of them are reported correctly. The title in th= e body is formatted simply as `Lecture`, the one in the left footer=C2=A0is= formatted as `Lecture<number><title>`, and the one in the tabl= e of contents isn't affected at all.<br><br>What am I doing wrong?<br><= /div> --000000000000c597fc05c9c2583f-- --===============1017903237517129738== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============1017903237517129738==--