ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Using Lua to format lecture titles
@ 2021-08-17 14:43 noib3 via ntg-context
  2021-08-17 15:32 ` Wolfgang Schuster via ntg-context
  0 siblings, 1 reply; 2+ messages in thread
From: noib3 via ntg-context @ 2021-08-17 14:43 UTC (permalink / raw)
  To: ntg-context; +Cc: noib3


[-- Attachment #1.1: Type: text/plain, Size: 1817 bytes --]

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:

```
\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?

[-- Attachment #1.2: Type: text/html, Size: 2269 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Using Lua to format lecture titles
  2021-08-17 14:43 Using Lua to format lecture titles noib3 via ntg-context
@ 2021-08-17 15:32 ` Wolfgang Schuster via ntg-context
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Schuster via ntg-context @ 2021-08-17 15:32 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Wolfgang Schuster

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
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-17 15:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-17 14:43 Using Lua to format lecture titles noib3 via ntg-context
2021-08-17 15:32 ` Wolfgang Schuster via ntg-context

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).