[NTG-context] Omitting part number in chapter numbers

Wolfgang Schuster wolfgang.schuster.lists at gmail.com
Wed Feb 20 17:27:45 CET 2019


Simon Collier schrieb am 20.02.19 um 02:01:
> Dear list.
> 
> 
> I would like to have a TOC that looks basically as follows when stripped 
> down to the essentials:
> 
> 1 Part1
> 1 Chapter1
> 2 Chapter2
> 
> 2 Part2
> 3 Chapter3
> 
> I don't want the part number to be "part" of the chapter number (no 2.1, 
> just 1, for example).
> This behaviour should apply both to the titles in the text and in the TOC..
> 
> With the code:
> 
> \definestructureresetset[default][1,0,1][1] % reset part and section, 
> but not chapter, from wiki
> \setuphead[sectionresetset=default]
> 
> \setuphead[part]
> [placehead=yes,
> number=yes,]
> \setuplist [part]
>    [number=yes,]
> 
> \setuphead [chapter]
>    [number=yes,]
> \setuplist [chapter]
>    [number=yes,]
> 
> \starttext
> \completecontent
> 
> \startpart[title={Part1}]
> \startchapter[title={Chapter3}]
> \input knuth
> \stopchapter
> \startchapter[title={Chapter2}]
> \input tufte
> \stopchapter
> \stoppart
> 
> \startpart[title={Part2}]
> \startchapter[title={Chapter3}]
> \input knuth
> \stopchapter
> \stoppart
> 
> \stoptext
> 
> 
> I can make chapter numbers flow independently of parts, which is nice.
> But the numbering for chapters is like 1.1, 1.2, and 2.3, which is a 
> good default, but not what I want.
> Is there any way to omit part number and get only the chapter number 
> displayed?
> 
> In wiki there is something that is almost suitable, namely setting:
> numbercommand={\determineheadnumber[chapter]\currentheadnumber\gobbleoneargument}]
> But this does not work for TOC, returning just zeros (and seems like 
> also an extra zero is spilled on TOC, overall pretty hackish solution).
> 
> When nothing seemed to work, I also tried to use an ugly macro that uses 
> lua to format the argument #1 in the numbercommand nicely with the help 
> of string functions,
> but it turned out the actual parameter #1 in numbercommand is something 
> other than just a string with numbers and dots.
> If someone knows what it is, or how to find out, please point me to the 
> right direction to better understand the system. Currently I'm unable to 
> even print it to the terminal in order to see what actual characters are 
> there, the following code outputting the length (seems to be 19 at least 
> for me) works just fine as well as printing the string itself to the 
> document.
> 
> \startluacode  
>      userdata = userdata or{}
> 
>      function userdata.numberfun(str)
>              context(tostring(#str))
>      end
> \stopluacode
> 
> \def\mync#1%
>      {\ctxlua{userdata.numberfun([==[#1]==])}}
> 
> 
> The idea seemed pretty standard and is used in many books, so maybe I've 
> just completely missed the right way to approach this.

You have to use the “sectionsegemnts” key.

\setuphead
   [part]
   [placehead=yes]

\setuphead
   [chapter]
   [sectionsegments=chapter]

\starttext

\completecontent

\part{Part 1}

\chapter{Chapter 1}

\chapter{Chapter 2}

\part{Part 2}

\chapter{Chapter 3}

\stoptext

Wolfgang



More information about the ntg-context mailing list