summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-addtoreset.html
blob: 70e1fd1fc29ff878f51ce5dc6277fa17ab04d5f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<head>
<title>UK TeX FAQ -- question label addtoreset</title>
</head><body>
<h3>Master and slave counters</h3>
<p/>It&#8217;s common to have things numbered &#8220;per chapter&#8221; (for example, in
the standard <i>book</i> and <i>report</i> classes, figures, tables
and footnotes are all numbered thus).  The process of resetting is
done automatically, when the &#8220;master&#8221; counter is stepped (when the
<code>\</code><code>chapter</code> command that starts chapter &lt;<i>n</i>&gt; happens, the
<code>chapter</code> counter is stepped, and all the dependent counters are set
to zero).
<p/>How would you do that for yourself?  You might want to number
algorithms per section, or corollaries per theorem, for example.  If
you&#8217;re defining these things by hand, you declare the relationship
when you define the counter in the first place:
<blockquote>
<code>\</code><code>newcounter{</code><em>new-name</em><code>}[</code><em>master</em><code>]</code>
</blockquote><p>
says that every time counter &lt;<i>master</i>&gt; is stepped, counter
&lt;<i>new-name</i>&gt; will be reset.
<p/>But what if you have an uncooperative package, that defines the
objects for you, but doesn&#8217;t provide a programmer interface to make
the counters behave as you want?
<p/>The <code>\</code><code>newcounter</code> command uses a LaTeX internal command, and you
can also use it:
<blockquote>
<code>\</code><code>@addtoreset{</code><em>new-name</em><code>}{</code><em>master</em><code>}</code>
</blockquote><p>
(but remember that it needs to be between <code>\</code><code>makeatletter</code> and
<code>\</code><code>makeatother</code>, or in a package of your own).
<p/>The <i>chngcntr</i> package encapsulates the <code>\</code><code>@addtoreset</code>
command into a command <code>\</code><code>counterwithin</code>.  So:
<blockquote>
<pre>
\counterwithin*{corrollary}{theorem}
</pre>
</blockquote><p>
will make the corollary counter slave to theorem counters.  The
command without its asterisk:
<blockquote>
<pre>
\counterwithin{corrollary}{theorem}
</pre>
</blockquote><p>
will do the same, and also redefine <code>\</code><code>thecorollary</code> as 
&lt;<i>theorem number</i>&gt;.&lt;<i>corollary number</i>&gt;, which is a good scheme
if you ever want to refer to the corollaries &#8212; there are potentially
many &#8220;corollary 1&#8221; in any document, so it&#8217;s as well to tie its number
to the counter of the theorem it belongs to.  This is true of pretty
much any such counter-within-another; if you&#8217;re not using the
<i>chngcntr</i>, refer to the answer to 
<a href="FAQ-the-commands.html">redefining counters&#8217; <code>\</code><code>the-</code>commands</a> for
the necessary techniques.
<p/>Note that the technique doesn&#8217;t work if the master counter is <code>page</code>,
the number of the current page.  The <code>page</code> counter is stepped deep
inside the output routine, which usually gets called some time after
the text for the new page has started to appear: so special
techniques are required to deal with that.  One special case is dealt
with elsewhere: <a href="FAQ-footnpp.html">footnotes numbered per page</a>.  One
of the techniques described there, using package <i>perpage</i>,
may be applied to any counter.  The command:
<blockquote>
<code>\</code><code>MakePerPage{</code><em>counter</em><code>}</code>
</blockquote><p>
will cause &lt;<i>counter</i>&gt; to be reset for each page.  The package uses
a label-like mechanism, and may require more than one run of LaTeX
to stabilise counter values &#8212; LaTeX will generate the usual
warnings about labels changing.
<dl>
<dt><tt><i>chngcntr.sty</i></tt><dd><a href="http://mirror.ctan.org/macros/latex/contrib/chngcntr.zip">macros/latex/contrib/chngcntr</a> (or <a href="http://mirror.ctan.org/macros/latex/contrib/chngcntr/">browse the directory</a>); <a href="http://mirror.ctan.org/help/Catalogue/entries/chngcntr.html">catalogue entry</a>
<dt><tt><i>perpage.sty</i></tt><dd>Distributed as part <a href="http://mirror.ctan.org/macros/latex/contrib/bigfoot.zip">macros/latex/contrib/bigfoot</a> (or <a href="http://mirror.ctan.org/macros/latex/contrib/bigfoot/">browse the directory</a>); <a href="http://mirror.ctan.org/help/Catalogue/entries/perpage.html">catalogue entry</a>
</dl>
<p/><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=addtoreset">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=addtoreset</a>
</body>