summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-wrongpn.html
blob: 9acc7076e44205f45af6a30534170add3199f97d (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
<head>
<title>UK TeX FAQ -- question label wrongpn</title>
</head><body>
<h3>Page number is wrong at start of page</h3>
<p/>This is a long story, whose sources are deep inside the workings of
TeX itself; it all derives from the TeX&rsquo;s striving to generate
the best possible output.
<p/>The page number is conventionally stored in <code>\</code><code>count0</code>; LaTeX
users see this as the counter <code>page</code>, and may typeset its value
using <code>\</code><code>thepage</code>.
<p/>The number (that is to say, <code>\</code><code>count0</code>) is only updated when TeX
actually outputs a page.  TeX only even tries to do this when it
detects a hint that it may be a good thing to do.  From TeX&rsquo;s point
of view, the end of a paragraph is a good time to consider outputting
a page; it will output a page if it has <em>more</em> than a page&rsquo;s
worth of material to output.  (Ensuring it always has something in
hand makes some optimisations possible.)  As a result, <code>\</code><code>count0</code>
(<code>\</code><code>thepage</code>) is almost always wrong in the first paragraph of a
page (the exception is where the page number has been &ldquo;forcibly&rdquo;
changed, either by changing its value directly, or by breaking the
page where TeX wouldn&rsquo;t necessarily have chosen to break).
<p/>LaTeX provides a safe way of referring to the page number, by using
label references.  So, rather than writing:
<blockquote>
<pre>
Here is page \thepage{}.
</pre>
</blockquote><p>
you should write:
<blockquote>
<pre>
Here is page \pageref{here}\label{here}.
</pre>
</blockquote><p>
(note: no space between the <code>\</code><code>pageref</code> and the <code>\</code><code>label</code>, since
that could potentially end up as a page-break space itself, which
rather defeats the purpose of the exercise!).
<p/><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=wrongpn">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=wrongpn</a>
</body>