3

For total number of pages, one can use \lastcounter[userpage] to get the total number of pages in the document. Actually it gives the number on the last page (which is more interesting). Similar commands work for the total number of formulas, figures, etc. in the document.

How can I get the number of chapters? Inspecting structures.counters in Lua doesn't show a counter associated with chapter numbering.

Here is my use case in particular: I have sections and subsections and I have arranged for the numbering of the latter not to get reset at each new section. I want to have the total number of subsections in my document: "5" in the example below.

Section 1
  Subsection 1
  Subsection 2
Section 2
  Subsection 3
  Subsection 4
  Subsection 5

The command \somenamedheadnumber{subsection}{last} provides the last subsection number within the currently active structure (current section in my case), but I could not find a way to get the very last value for the entire document.

In TeX/LaTeX I would add a hook to \subsection to log the counter value to a file and then read that file at the beginning of the document to compute the final value. (This simplifies a bit if one uses \AtEndDocument in LaTeX.) I'm sure there is a simple way to do this in CONTEXT but I could not find it.

  • 1
    \AtEndDocument is for LaTeX. My question is about ConTeXt. I'm looking for a simple way to achieve this in ConTeXt. – MHB May 5 '16 at 4:13
2

You can use the command \determinelistcharacteristics and then \structurelistsize to access the value. Example:

\starttext

\determinelistcharacteristics
  [chapter]
  [criterium=text]

number of chapters: \structurelistsize

\startsectionlevel [title=Foo]
  \startsectionlevel [title=title 1] section 1 \stopsectionlevel
  \startsectionlevel [title=title 2] section 2 \stopsectionlevel
\stopsectionlevel

\startsectionlevel [title=Bar]
  \startsectionlevel [title=title 3] section 3 \stopsectionlevel
  \startsectionlevel [title=title 4] section 4 \stopsectionlevel
\stopsectionlevel

\stoptext

Replace the first argument of \determinelistcharacteristics with section, subsection or any other section level to obtain the other section levels' counters.

The criterium=text is required in case the \determinelistcharacteristics command follows the sections instead of preceding them. Without setting the criterium, the value of \structurelistsize would be wrong.

| improve this answer | |
  • What is the purpose of the "criterium= text" in your example? – Ulrike Fischer May 5 '16 at 8:37
  • @UlrikeFischer To obtain correct values for \structurelistsize in case the \determinelistcharacteristics is placed after the sections. See edit. – Marco May 5 '16 at 9:20
  • I'm not getting it. If I move the \determinlistcharacteristics behind a \startsection.. I get the wrong number of chapter (0) with and without the criterium. Also what does "text" mean? The part between \starttext and \stoptext? – Ulrike Fischer May 5 '16 at 13:27
  • How efficient is the macro \determinelistcharacteristics? Should I use it as part of setting the footers in my presentation or is it better to use an \xdef? Though the latter works with your code snippet, it produces a value of zero in my presentation. I will try to create a minimal non-working example when I get a chance. – MHB May 5 '16 at 15:12
  • @UlrikeFischer See the example of how the text key affects the output. text is a standard key for criterium, I don't know why it was chosen and what it refers to. – Marco May 5 '16 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.