10

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

\setuphead[chapter]                     [number=yes]

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

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?

1
  • Untested: \getmarking[chapternumber] should work.
    – Aditya
    Jun 20, 2013 at 11:58

2 Answers 2

6

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.

Examples:

%% the initial value of the chapter counter
\somenamedheadnumber{chapter}{first}

%% the number of the final section in the current chapter
\somenamedheadnumber{section}{last}

%% 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
\somenamedheadnumber{subsubsection}{current}

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
  Chapter
  \space
  \namedheadnumber{chapter}
  \space of \space
  \somenamedheadnumber{chapter}{last}
  \space --- \space
  {\cap\getmarking[chapter]}
\stopsetups

\startsetups header.inner
  Section
  \space
  \namedheadnumber{section}
  \space of \space
  \somenamedheadnumber{section}{last}
  \space --- \space
  {\italic\getmarking[section]}
\stopsetups

\setupheadertexts
  [\setups{header.outer}]
  [\setups{header.inner}]

\starttext
  \getrandomnumber\i25
  \completecontent\page
  \dorecurse{\i}{
    \getrandomnumber\j27
    \startchapter[title=foo]
      \input knuth
      \dorecurse{\j}{
        \startsection[title=bar]
          \input ward\par\input dawkins
        \stopsection
      }
    \stopchapter
  }
\stoptext
3
  • 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, 2013 at 22:40
  • @Aditya I had issues with \getmarking, iirc it did not yield the intended result. Jul 11, 2013 at 19:12
  • see my answer below.
    – Aditya
    Jul 11, 2013 at 21:44
8

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

\setupheadertexts[{\getmarking[chapternumber]--\getmarking[chapter]}]

\starttext

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

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

\stoptext

which gives

enter image description here

3
  • getnumber[chapternumber] or getmarking[chapternumber]. Revise your example please. It's incongruent with first paragraph Oct 18, 2016 at 12:14
  • @somenxavier: Thanks for pointing that out. Corrected.
    – Aditya
    Oct 18, 2016 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? Oct 20, 2016 at 11:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .