LaTeX/Counters

From testwiki
Revision as of 15:48, 4 April 2020 by 87.239.207.1 (talk) (Counter manipulation: Fixed the name of the variable)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Template:LaTeX/Top

Counters are an essential part of LaTeX: they allow you to control the numbering mechanism of everything (sections, lists, captions, etc.). To that end each counter stores an integer value in the range of long integer, i.e., from 231 to 2311. [1]

Counter manipulation

In LaTeX it is fairly easy to create new counters and even counters that reset automatically when another counter is increased (think subsection in a section for example). With the command Template:LaTeX/Usage you create a new counter that is automatically set to zero. If you want the counter to be reset to zero every time another counter is increased, use: Template:LaTeX/Usage For example, if you want to enumerate the equations in each chapter independently, you can create something like an "equationschapter" counter that will be automatically reset at the begin of each section. Template:LaTeX/Usage


To add to an existing counter another counter causing a reset when increased, use: Template:LaTeX/Usage

If this doesn't work it might be because of an old LaTeX version, the following should work in that case: Template:LaTeX/Usage

To undo this effect one can use: Template:LaTeX/Usage

or: Template:LaTeX/Usage

To increase the counter, either use Template:LaTeX/Usage or Template:LaTeX/Usage or Template:LaTeX/Usage here the number can also be negative. For automatic resetting you need to use \stepcounter.

To set the counter value explicitly, use Template:LaTeX/Usage

Counter access

There are several ways to get access to a counter.

  • Template:LaTeX/LaTeX will print the formatted string related to the counter (note the "the" before the actual name of the counter).
  • Template:LaTeX/LaTeX will return the counter value which can be used by other counters or for calculations. It is not a formatted string, so it cannot be used in text.
  • Template:LaTeX/LaTeX will print the formatted counter using arabic numbers.

Note that Template:LaTeX/LaTeX may be used as a value too, but not the others.

Strangely enough, LaTeX counters are not introduced by a backslash in any case, even with the Template:LaTeX/LaTeX command. plainTeX equivalents Template:LaTeX/LaTeX and Template:LaTeX/LaTeX do abide by the backslash rule.

Counter style

The following internal LaTeX commands will convert numeric value of specified counter into printable string and insert string into document:

Template:LaTeX/LaTeX
Numbers from 231 to 2311 inclusive converted to strings «-2147483648», «-2147483647», …, «-1», «0», «1», …, «2147483646», «2147483647».
Example: 1, 2, 3, …
Template:LaTeX/LaTeX
Numbers from 1 to 26 inclusive converted to strings «a», «b», …, «z». Other numbers (negative numbers, zero, 27, 28, …, 2311) converted to empty string.
Example: a, b, c, …
Template:LaTeX/LaTeX
Same as Template:LaTeX/LaTeX, but upper case letters used.
Example: A, B, C, …
Template:LaTeX/LaTeX
Numbers from 1 to 4999 inclusive converted to strings «i» (1), «ii» (2), …, «mmmmcmxcix» (4999), where «i» — 1, «v» — 5, «x» — 10, «l» — 50, «c» — 100, «d» — 500, «m» — 1000. Numbers from 5000 to 2311 inclusive converted to strings «mmmmm» (5000), «mmmmmi» (5001), …. Other numbers (negative numbers, zero) converted to empty string.
Example: i, ii, iii, …
Template:LaTeX/LaTeX
Same as Template:LaTeX/LaTeX, but upper case letters used.
Example: I, II, III, …
Template:LaTeX/LaTeX
Aimed at footnotes; prints a sequence of symbols.
Number Symbol(s)
1
2
3
4 §
5
6
7 ∗∗
8 ††
9 ‡‡
Other numbers Empty string
Example: ∗, †, ‡, …

LaTeX default counters

  • part
  • chapter
  • section
  • subsection
  • subsubsection
  • paragraph
  • subparagraph
  • page
  • figure
  • table
  • footnote
  • mpfootnote

For the Template:LaTeX/Environment environment:

  • enumi
  • enumii
  • enumiii
  • enumiv

For the Template:LaTeX/Environment environment:

  • equation

Book with parts, sections, but no chapters

Here follows an example where we want to use parts and sections, but no chapters in the book class : Template:LaTeX/Usage

Custom enumerate

See the List Structures chapter.

Custom sectioning

Here is an example for recreating something similar to a section and subsection counter that already exist in LaTeX: Template:LaTeX/Usage


Template:LaTeX/Bottom