The count1to package^{∗}

Martin Schröder

Crüsemannallee 3 D-28213 Bremen MS@Dream.HB.North.DE (INTERNET)

1997/03/09

Abstract

This package sets \count1 to \count8 with the values of page to subparagraph. \count9 is used to flag odd pages. The values of these counters are displayed and written in the .dvi file by TEX and can later be used to select the pages of certain parts of the document for printing if the device driver supports this.

Contents

1 Introduction 1

2 Options 2

3 Required packages 2 4 The implementation 3

5 Acknowledgements 4

1 Introduction

Most of the time users want to print only certain parts of a document; but these can only be selected by using the page numbers of these parts with most device drivers. This can be difficult or impossible if pages in different parts of the document have the same number—e. g. in the frontmatter and the first text pages (iii vs. 3).

TEX provides an easy solution to this problem: whenever a page is completed by the output routine and shipped out via \shipout, it displayes the values of \count0 to \count9 on the display (e. g. [1]) and writes them to the .dvi file.

“The first ten \count registers, \count0 to \count9, are reserved for a special purpose: TEX displays these ten counts on your terminal whenever ouputting a page, and it transmits them to the output file as an identification of that page. The counts are separated by decimal points on your terminal, with trailing ‘.0’ patterns suppressed. Thus, for example, if \count0=5 and \count2=7 when a page is shipped out to the dvi file, and if the other counters are zero, TEX will type ‘[5.0.7]’. Plain TEX uses \count0 for the page number, and it keeps \count1 through \count9 equal to zero; that is why you see ‘[1]’ when page 1 is being output. In more complex applications the page numbers can have further structure; ten counts are shipped out so that there will be plenty of identification.”[1, p. 119]

∗The version umber of this file is v1.03, last revised 1997/03/09.

The name count1to is a tribute to the 8+3 file-naming convention of certain “operating systems”; strictly speaking it should be count1to9.

Surprinsingly, until recently there existed no package for L^{A}TEX that used these \counters although some drivers allow the selection of pages based on other \counts then \count0 (e. g. emTEX).

This package is the solution: It uses the everyshi package to set \count1 to \count9 before each \shipout with these values:

         \count value

0  relative page number (set by L^{A}TEX)
1  absolute page number
2  number of current \part
3  number of current \chapter (0 with article class)
4  number of current \section
5  number of current \subsection
6  number of current \subsubsection
7  number of current \paragraph
8  number of current \subparagraph
9  1 on odd pages, 0 on even pages^{1}

count1to also works with classes that do not define some or all of the sectioning commands and their counters, like letter. Although it is of somewhat little use then :-).

A note for users of this package: When you select the pages of some part of your document with a lower structure than \chapter, remember that only \parts and \chapters start on a new page; if you want to print a complete \section, you should also select the first page of the next \section. Also note that TEX ships out the values of the counters instead of their visual representation (produced with \thecounter), so appendix A sets \count4 to 1 in the article class.

A note for developers of device drivers: Please add support for \count1 to 9 to your programs. It would also be nice if users could easily select the next page(s) after a certain count (something like “*.*.*.*.2+1.*” should be possible for selecting all pages with \count4 ↦ section = 2 plus the first page of section 3).

2 Options

The package has no options.

3 Required packages

The package requires the everyshi package.

1If you have a better application for \count9, let me know.

4 THE IMPLEMENTATION 3

4 The implementation

1 ⟨∗package⟩

We need the everyshi package.

 2 \RequirePackage{everyshi}[1994/12/09]

We need various \ifs to check if the used counters are defined.

 3 \newif\if@have@part
 4 \newif\if@have@chapter
 5 \newif\if@have@section
 6 \newif\if@have@subsection
 7 \newif\if@have@subsubsection
 8 \newif\if@have@paragraph
 9 \newif\if@have@subparagraph
\@countItoIX@ifs  \@countItoIX@ifs is used to set all these \ifs at \begin{document}. It is un-

defined after use to save some space.

10 \newcommand*{\@countItoIX@ifs}{
11 \@ifundefined{c@part}           {}{\@have@parttrue}
12 \@ifundefined{c@chapter}        {}{\@have@chaptertrue}
13 \@ifundefined{c@section}        {}{\@have@sectiontrue}
14 \@ifundefined{c@subsection}     {}{\@have@subsectiontrue}
15 \@ifundefined{c@subsubsection}  {}{\@have@subsubsectiontrue}
16 \@ifundefined{c@paragraph}      {}{\@have@paragraphtrue}
17 \@ifundefined{c@subparagraph}   {}{\@have@subparagraphtrue}

18 }

19 \AtBeginDocument{\@countItoIX@ifs\let\@countItoIX@ifs\undefined}

\@countItoIX@bugfix The current version of L^{A}TEX has the “feature” that only the first level of counters associated with a counter via the optional argument of \newcounter is reset when the counter is stepped; so when you start a new chapter, the number for the subsection is not reset. This is normally no problem, but with this package, it is: If this bug is not fixed or worked-around, then whenever you use \subparagraph or some other lower sectioning command, and after that a sectioning command that is at least two levels higher (e. g. \subsubsection), the value of subparagraph would not be reset and would still be displayed and shipped out. So we have to associate all lower-level sectioning commands with the higher levels. This is done

via \@addtoreset at \begin{document}. \@countItoIX@bugfix is undefined af-

ter use to save some space.

20 \newcommand*{\@countItoIX@bugfix}{
21 \if@have@part
22  \@addtoreset{section}      {part}
23  \@addtoreset{subsection}   {part}
24  \@addtoreset{subsubsection}{part}
25  \@addtoreset{paragraph}    {part}
26  \@addtoreset{subparagraph} {part}
27 \fi
28 \if@have@chapter
29  \@addtoreset{subsection}   {chapter}
30  \@addtoreset{subsubsection}{chapter}
31  \@addtoreset{paragraph}    {chapter}
32  \@addtoreset{subparagraph} {chapter}
33 \fi

5 ACKNOWLEDGEMENTS 4

34 \if@have@section
35  \@addtoreset{subsubsection}{section}
36  \@addtoreset{paragraph}    {section}
37  \@addtoreset{subparagraph} {section}
38 \fi
39 \if@have@subsection
40  \@addtoreset{paragraph}    {subsection}
41  \@addtoreset{subparagraph} {subsection}
42 \fi
43 \if@have@subsubsection
44  \@addtoreset{subparagraph} {subsubsection}
45 \fi

46 }

47 \AtBeginDocument{\@countItoIX@bugfix\let\@countItoIX@bugfix\undefined}
\@countItoIX@shipout  \@countItoIX@shipout is used for setting \count1 to \count9 at each \shipout.
48 \newcommand*{\@countItoIX@shipout}{

\count1 is the absolute page number, which we have to maintain by ourselves.

49 \global\advance \count1 by 1

\count2 to \count8 are set with the values of \part to \subparagraph, if these commands are defined.^{2}

50 \if@have@part              \count2\value{part}           \fi
51 \if@have@chapter           \count3\value{chapter}        \fi
52 \if@have@section           \count4\value{section}        \fi
53 \if@have@subsection        \count5\value{subsection}     \fi
54 \if@have@subsubsection     \count6\value{subsubsection}  \fi
55 \if@have@paragraph         \count7\value{paragraph}      \fi
56 \if@have@subparagraph      \count8\value{subparagraph}   \fi

\count9 is set to 1 on odd pages and to 0 on even pages.

57 \ifodd\count1\count9=1     \else\count9=0                \fi

58 }

59 \EveryShipout{\@countItoIX@shipout}

60 ⟨/package⟩

5 Acknowledgements

As usual Rebecca Stiels improved the quality of this documentation. If you need a translator from English or Français to German, send her an e-mail to

Rebecca@Andurg.HB.North.DE.

References

[1] Donald E. Knuth. The TEXBook, volume A of Computers and Typesetting. Addison-Wesley, 1986. Eleventh printing, revised, May 1991.

2We should probably also check the value of secnumdepth, but I don’t think this is necessary.

Index 5

Index

Numbers written in italic refer to the page where the corresponding entry is described, the ones \underline{underlined} to the definition, the rest to the places where the entry is used.

Symbols

\@addtoreset . . . . . . . . . . . . . . . . .

. . 22–26, 29–32, 35–37, 40, 41, 44

\@countItoIX@bugfix . . . . . . . . . . . \underline{20}
\@countItoIX@ifs . . . . . . . . . . . . . \underline{10}
\@countItoIX@shipout . . . . . . . . . . \underline{48}
\@have@chaptertrue . . . . . . . . . . . . 12
\@have@paragraphtrue . . . . . . . . . . 16

\@have@parttrue . . . . . . . . . . . . . . 11

\@have@sectiontrue . . . . . . . . . . . . 13
\@have@subparagraphtrue . . . . . . . 17
\@have@subsectiontrue . . . . . . . . . 14
\@have@subsubsectiontrue . . . . . . . 15

\@ifundefined . . . . . . . . . . . . . . 11–17

A

\advance . . . . . . . . . . . . . . . . . . . . 49

\AtBeginDocument . . . . . . . . . . . 19, 47

C

\count . . . . . . . . . . . . . . . . . . . . 49–57

E

\else . . . . . . . . . . . . . . . . . . . . . . . 57 \EveryShipout . . . . . . . . . . . . . . . . 59

F

\fi . . . . . . . . 27, 33, 38, 42, 45, 50–57

G \global . . . . . . . . . . . . . . . . . . . . . 49

I

                                       \if@have@chapter . . . . . . . . . 4, 28, 51
                                       \if@have@paragraph . . . . . . . . . . . 8, 55

\if@have@part . . . . . . . . . . . . 3, 21, 50

                                       \if@have@section . . . . . . . . . 5, 34, 52
                                       \if@have@subparagraph . . . . . . . . 9, 56
                                       \if@have@subsection . . . . . . . 6, 39, 53
                                       \if@have@subsubsection . . . . 7, 43, 54

\ifodd . . . . . . . . . . . . . . . . . . . . . . 57

L \let . . . . . . . . . . . . . . . . . . . . . . 19, 47

N \newcommand . . . . . . . . . . . . . 10, 20, 48 \newif . . . . . . . . . . . . . . . . . . . . . . 3–9

R \RequirePackage . . . . . . . . . . . . . . . 2

U \undefined . . . . . . . . . . . . . . . . 19, 47

V \value . . . . . . . . . . . . . . . . . . . . 50–56