Questions tagged [counters]

{counters} is about macro writing involving counters. For general questions about numbering document elements, use {numbering}.

{counters} is about macro writing involving counters. For general questions about numbering document elements, use {numbering}.

There are some packages that deal with counters

  • aliascnt
  • chngcntr
  • totcounter
  • formatcnt
  • remreset
  • xassoccnt
1436 questions
50
votes
4 answers

How to display the final value of a counter at the beginning of a document?

At the beginning of my document, I have created a counter using \newcounter. Over the course of the document, this counter is increases using \stepcounter. How can I display the final value of the counter in a place prior to the the final occurrence…
Village
  • 13,603
  • 23
  • 116
  • 219
30
votes
3 answers

Check if counter exists

I've written a package that introduces a new environment: \newfloat{foo}{htb}{bar}[chapter] The package however can be used for articles, books, ... Since not all of these environments have the concept of chapter, on gets a No counter 'chapter'…
25
votes
2 answers

What is the proper method of accessing a counter?

It seems that there are different ways of accessing counters. I have been using \theMyCount as in this post about Using counters or macros, but noticed that the arrayjobx package uses \the\value{MyCount}. This post about LaTeX programming…
Peter Grill
  • 223,288
22
votes
2 answers

What is the maximum integer that can be saved in a LaTeX counter?

I am using counters to save positive integers, something like that: \setcounter{mycoutervalue}{59} Is there any limit in the value I can save in a counter, in this case mycountervalue? And what is the exact limit? Thanks! I do not want to get an…
21
votes
1 answer

Print counter value minus 1

I have defined a new counter that keeps increasing each time I call the macro that's using it. How can I print the counter value minus one? Something like \value{\theCounter-1} but formatted for…
Holene
  • 6,920
20
votes
2 answers

Displaying a later value of a counter

I have a counter which is used throughout my document. At the beginning of each chapter (right after the \chapter command), I want to print the value of the counter which is reached immediately before the next \chapter command. For e.g. At the…
Village
  • 13,603
  • 23
  • 116
  • 219
19
votes
1 answer

How to erase/delete a counter

I was wondering how does TeX manage counters. In particular, assuming I define a new counter in TeX by \newcount\mycounter and at some point I don't need it anymore, can I delete it and free the associated registry? This may be useful when one needs…
digital-Ink
  • 3,083
17
votes
1 answer

Computing a value inside \setcounter

I am using an enumerate list. I often want to decrement the counter of a list, to get output like this: 1. Some text here 2. Some more text here 2. This is a re-use of the number 3. The counter increments 3. Decrement the counter just before this…
nebffa
  • 873
12
votes
2 answers

Counter increase with new page

How can I increase my counter with every new page and reset to 0 again when it comes to a new chapter? I know that I can link my counter to a chapter so that it can be reset on every new chapter by: \newcounter{counter1}[chapter] but then I have no…
user25196
  • 399
  • 2
  • 15
12
votes
2 answers

Integer arithmetic in TeX

After many years of being merely a regular TeX (LaTeX lately) I started reading little bit more recently. I wrote a small program (very naive) which is suppose to illustrate doing integer arithmetic in TeX. \message{Please enter the first…
12
votes
2 answers

Hiding a counter if it is only displayed only one time

I have two macros on my document. \showcounter increases a counter, then displays it. \resetcounter sets the counter back to "0". \documentclass{article} \newcounter{counterone} \setcounter{counterone}{0} \newcommand{\showcounter}{ …
Village
  • 13,603
  • 23
  • 116
  • 219
12
votes
4 answers

How do I make a counter start with 1?

I defined a counter like this: \newcounter{my_steps}[subsubsection] and I would like to make it start with 1 instead of 0 after each subsubsection. How?
Michiel Borkent
  • 345
  • 4
  • 10
12
votes
5 answers

Slave duplicate counter

Is it possible to create a counter that is a "slave" to another (master) counter, but also an exact duplicate? The \@addtoreset{}{} resets whenever is incremented (similar functionality is offered by chngcntr), but I…
Werner
  • 603,163
12
votes
2 answers

How can I explicitly ask a \label{} command to refer to a given counter?

Question In a comment there, I learnt that The latest \refstepcounter before \label sets the counter for \label Is it possible to explicitly ask a \label{} command to refer to a given counter? I see two cases where this could be useful: there are…
Colas
  • 6,772
  • 4
  • 46
  • 96
11
votes
1 answer

increment a counter

As I understand it, a counter is supposed to increment automatically. However, when I try to use one all I get is zeros. Here is a MWE. \documentclass[12pt]{article} \usepackage{lipsum} \newcounter{mcounter} \begin{document} \themcounter…
Michael
  • 464
1
2 3
8 9