I am using serupheadertexts to define the headers in my document:

\setuphead[chapter]                     [number=yes]


I want to access the chapter number, but it is not displaying.

I tried this:

\setupheadertexts[{\getnumber[chapter] \getmarking[chapter]}][][][]

It does not display any number there.

How can I display the chapter number in the headers in ConTeXt?

  • Untested: \getmarking[chapternumber] should work. – Aditya Jun 20 '13 at 11:58

You can access the first, present, and final values of section counters for the currently active structure component by their name using the command \somenamedheadnumber.

\somenamedheadnumber takes two mandatory arguments:

  1. the name of a structure element, e.~g. section, chapter, and
  2. one of the identifiers first, current, last that determine the value to be retrieved.


%% the initial value of the chapter counter

%% the number of the final section in the current chapter

%% the number of the currently active subsubsection;
%% in the page header this will retrieve the number of the
%% structural last active on the current page

As a shorthand, \namedheadnumber{<name>} is equivalent to \somenamedheadnumber{<name>}{current}.

A more extensive example showing the various getters for structure counters in action:

\setuppagenumbering [location=footer,alternative=doublesided]

\startsetups header.outer
  \space of \space
  \space --- \space

\startsetups header.inner
  \space of \space
  \space --- \space


      \input knuth
          \input ward\par\input dawkins
  • Any reason you are using the low-level \namedheadnumber instead of \getmarking[chapternumber]? The former is useful if you want to do some processing with the number, but for simply typesetting the result, \getmarking[...] is sufficient. – Aditya Jul 3 '13 at 22:40
  • @Aditya I had issues with \getmarking, iirc it did not yield the intended result. – Philipp Gesang Jul 11 '13 at 19:12
  • see my answer below. – Aditya Jul 11 '13 at 21:44

The normal way to get the chapter number in the headers is to use \getmarking[chapternumber].



\startchapter[title={First chapter}, marking={Mark for first chapter}]
  \input knuth

\startchapter[title={Second chapter}, marking={Mark for second chapter}]
  \input knuth


which gives

enter image description here

  • getnumber[chapternumber] or getmarking[chapternumber]. Revise your example please. It's incongruent with first paragraph – somenxavier Oct 18 '16 at 12:14
  • @somenxavier: Thanks for pointing that out. Corrected. – Aditya Oct 18 '16 at 17:39
  • You're welcome. Is it a way of getting whole number and name? Because if you have no Chapter yet, you get '0' but name ''. Can we get '' if Chapter is not set yet? – somenxavier Oct 20 '16 at 11:00

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.