From Wiki
Jump to navigation Jump to search

< Main Page | Inside ConTeXt >

ConTeXt provides a higher layer of API to access various counters. For example, to set the page number to a certain value use


Other useful commands for working with counters are

    \resetcounter    [page]
    \savecounter     [page]
    \restorecounter  [page]
    %\getcounter     [page]
    \rawcountervalue [page]

Names of Commonly Used Counters

  • userpage for visible pagenumbers
  • page for internal pagenumbers
  • formula for formula numbers
  • table for table numbers
  • figure for figure numbers

Testing the Value of a Counter

If you need to test the value of a counter, use \rawcountervalue, not \getcounter:

 Strange, \type{\getcounter} worked.
 Using \type{\getcounter} does not work.

 Ok, the test with \type{\rawcountervalue} worked.
 Strange, \type{\rawcountervalue} failed.

results in:

In LMTX, \getcounter seems to be generally defunct.

Coupling Counters

Two counters can be coupled by


For example


Default value of counter one: \rawcountervalue[one]

We increment counter two

New value of counter one: \rawcountervalue[one]

By default counters are reset with each new chapter. To have a counter which isn’t reset you need way=bytext, and to remove the chapter number from the \getcounter result you have to add prefix=no.

Example definition:


Outdated information

Forcing the Reset of a Counter

In 2015, there was a bug that counters were reset (by chapter, page, etc.) only when they were incremented.

To force the reset, you can increment and then decrement a counter before using it.

\page                       % new page, mycounter should be reset
\rawcountervalue[mycounter] % no, it's not reset: you still get '10'

\rawcountervalue[mycounter] % now you should get '0' because it has been reset

\definenumber or \definecounter ?

\definenumber etc. are obsolete aliases for \definecounter etc.