3

I have a book containing hundreds of activities for teachers. Each activity is designated with \section{Activity title}. \section is never used for anything else.

I need some way to count how many times \section appears in the document. Is there some built-in counter or some other way to get this value?

6

When your goal is to show the value of the last section you can use the \headnumber command but when you're interested in the number of sections use the \someheadnumber command instead.

\setuphead
  [section]
  [conversion=r]

\startbuffer[headnumber]
    \starttabulate
    \NC first   \EQ \headnumber          [section] [first]   \NC\NR
    \NC current \EQ \headnumber          [section] [current] \NC\NR
    \NC last    \EQ \headnumber          [section] [last]    \NC\NR
    \TB
    \NC first   \EQ \somenamedheadnumber {section} {first}   \NC\NR
    \NC current \EQ \somenamedheadnumber {section} {current} \NC\NR
    \NC last    \EQ \somenamedheadnumber {section} {last}    \NC\NR
    \stoptabulate
\stopbuffer

\starttext

\dorecurse{3}
  {\expanded{\section{Section \recurselevel}}
   \getbuffer[headnumber]}

\stoptext

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.