Debian Codegraph @

texmf-dist/source/latex/count1to/count1to.dtx

raw
1 %% \iffalse meta-comment
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % Copyright (C) Martin Schröder, 1994–2009
5 % Marei Peischl (peiTeX) <[email protected]>, 2024
6 %
7 % This work may be distributed and/or modified under the
8 % conditions of the LaTeX Project Public License, either version 1.3c
9 % of this license or (at your option) any later version.
10 % The latest version of this license is in
11 % http://www.latex-project.org/lppl.txt
12 % and version 1.3c or later is part of all distributions of LaTeX
13 % version 2005/12/01 or later.
14 %
15 % This work has the LPPL maintenance status `maintained'.
16 % This package is maintained but will not receive any additional features.
17 %
18 % The Current Maintainer of this work is
19 % Marei Peischl <[email protected]>.
20 %
21 % This work consists of the files
22 % README.md
23 % count1to.dtx
24 % count1to.ins
25 % and the derived file
26 % count1to.sty.
27 %
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29 %
30 % \fi
31 % \iffalse
32 \NeedsTeXFormat{LaTeX2e}
33 %<package>\ProvidesPackage{count1to}
34 %<package> [2024-06-13 v2.11 Count1to9 Package (MS)]
35 %
36 %<*driver>
37 \ProvidesFile{count1to.drv}
38 [2024-06-13 v2.111 Driver for Count1to9 Package]
39 \documentclass[a4paper]{ltxdoc}
40 \usepackage[T1]{fontenc}
41 \usepackage{lmodern}
42 \usepackage{microtype}
43 \usepackage{booktabs}
44 \usepackage{url}
45 \usepackage{count1to}
46 \usepackage[toc]{multitoc}
47 \makeatletter
48 \IfFileExists{gitHeadInfo.gin}{
49 \newcommand*{\GI@githeadinfo@file}{gitHeadInfo.gin}
50 }{}
51 \makeatother
52 \usepackage{gitinfo2}
53 \usepackage{hypdoc}
54 \usepackage{geometry}
55 \GetFileInfo{count1to.sty}
56 \setcounter{IndexColumns}{2}
57 % onecolumn glossary
58 \makeatletter
59 \renewenvironment{theglossary}{%
60 \glossary@prologue
61 \setlength\emergencystretch{5em}
62 \GlossaryParms \let\item\@idxitem \ignorespaces}{}
63 \makeatother
64 \EnableCrossrefs
65 \RecordChanges
66 %%\DisableCrossrefs% Say \DisableCrossrefs if index is ready
67 \CodelineIndex % Index code by line number
68 %\OnlyDescription % comment out for implementation details
69 %%\OldMakeIndex % use if your MakeIndex is pre-v2.9
70 \setcounter{IndexColumns}{2}
71 \setlength{\IndexMin}{30ex}
72 \setlength{\premulticols}{\IndexMin}
73 \addtolength{\oddsidemargin}{1cm}
74 \addtolength{\textwidth}{-1cm}
75 \begin{document}
76 \DocInput{count1to.dtx}
77 \end{document}
78 %</driver>
79 % \fi
80 %
81 % \changes{v1.00}{1994/12/07}{New}
82 % \changes{v1.01}{1994/12/09}{Documentation improved}
83 % \changes{v1.02}{1996/12/29}{Documentation improved}
84 % \changes{v1.20}{1998/08/09}{Documentation improved}
85 % \changes{v1.22}{1999/06/08}{Moved to LPPL}
86 % \changes{v2.00}{2002/08/31}{Removed \texttt{TotalPages}}
87 % \changes{v2.1}{2009/05/24}{New address}
88 % \changes{v2.11}{2024-06-13}{Maintainer changed + removed from ms bundle + move to git}
89 %
90 % \newcommand*{\Count}[1]{\texttt{\symbol{92}count#1}}
91 % \newcommand*{\package}[1]{\textnormal{\sffamily#1}}
92 % \newcommand*{\NEWfeature}[1]{%
93 % \hskip 1sp \marginpar{\small\sffamily\raggedright
94 % New feature\\#1}}
95 %
96 % ^^A -----------------------------
97 %
98 % \changes{v1.03}{1997-03-09}{Fixed use of \cs{newline} in title.}
99 % \title{\unskip
100 % The \package{count1to} package^^A
101 % \thanks{^^A
102 % The version number of this file is \fileversion,
103 % revision~\#\gitAbbrevHash, last revised \protect\gitAuthorIsoDate.\protect\newline
104 % The name \textsf{count1to} is a tribute to the $8+3$ file-naming
105 % convention of certain ancient ``operating systems''; strictly
106 % speaking it should be \textsf{count1to9}.}
107 % }
108 % \changes{v2.00}{2002/08/31}{Changed e-mail}
109 % \author{Martin Schröder\\
110 % \url{https://gitlab.com/TeXhackse/count1to}\thanks{maintained by Marei Peischl}}
111 % \date{\filedate}
112 % \maketitle
113 %
114 % ^^A -----------------------------
115 %
116 %
117 % \begin{abstract}
118 % This package sets \Count{1} to \Count{8} with the values
119 % of \texttt{page} to \texttt{subparagraph}.
120 % \Count{9} is used to flag odd pages.
121 % The values of these counters are displayed and written in the
122 % \textsf{.dvi} file by \TeX{} and can later be used to select
123 % the pages of certain parts of the document for printing if the
124 % device driver supports this.
125 % \end{abstract}
126 %
127 % \pagestyle{headings}
128 %
129 % ^^A -----------------------------
130 %
131 % \tableofcontents
132 %
133 % ^^A -----------------------------
134 %
135 % \section{Introduction to version 2}
136 % ^^A
137 % The main change of this new version is the removal of the code for
138 % the \texttt{TotalPages} label.
139 % This code didn't work with the \package{hyperref}
140 % package\cite{package:hyperref} and better code to achieve the
141 % effect of it is contained in the \package{totpages}
142 % package\cite{package:totpages}.
143 % So old documents using this package will not work when they try to
144 % use the \texttt{TotalPages} label; these documents must be changed
145 % by inserting a \cs{usepackage\{totpages\}} in the preamble and
146 % replacing all occurences of \texttt{TotalPages} by
147 % \texttt{TotPages}.
148 %
149 % ^^A -----------------------------
150 %
151 % \section{Introduction}
152 % ^^A
153 % Most of the time users want to print only certain parts of a
154 % document; but these can only be selected by using the page numbers
155 % of these parts with most device drivers.
156 % This can be dif\/ficult or impossible if pages in dif\/ferent
157 % parts of the document have the same number---e.\,g. in the
158 % frontmatter and the first text pages (iii vs. 3).
159 %
160 % \TeX{} provides an easy solution to this problem: whenever a page
161 % is completed by the output routine and shipped out via
162 % \cs{shipout}, it displayes the values of \Count{0} to \Count{9}
163 % on the display (e.\,g. \texttt{[1]}) \emph{and writes them to the
164 % \textsf{.dvi} file}.
165 %
166 % \changes{v1.02}{1996/12/29}{fixed typos}
167 % \begin{quote}
168 % ``The first ten \Count{} registers, \Count{0} to \Count{9},
169 % are reserved for a special purpose: \TeX{} displays these ten
170 % counts on your terminal whenever ouputting a page, and it
171 % transmits them to the output file as an identification of that
172 % page.
173 % The counts are separated by decimal points on your terminal,
174 % with trailing `\texttt{.0}' patterns suppressed.
175 % Thus, for example, if \Count{0=5} and \Count{2=7} when a
176 % page is shipped out to the \texttt{dvi} file, and if the other
177 % counters are zero, \TeX{} will type `\texttt{[5.0.7]}'.
178 % Plain \TeX{} uses \Count{0} for the page number, and it keeps
179 % \Count{1} through~\Count{9} equal to zero; that is why you
180 % see `\texttt{[1]}' when page~1 is being output.
181 % In more complex applications the page numbers can have further
182 % structure; ten counts are shipped out so that there will be
183 % plenty of identification.''\cite[p\@. 119]{KnuthTeXa}
184 % \end{quote}
185 %
186 % \noindent
187 % Surprinsingly, until recently there existed no package for
188 % \LaTeX{} that used these \Count{}ers although some drivers allow
189 % the selection of pages based on other \Count{}s then \Count{0}
190 % (e.\,g. em\TeX).
191 %
192 % This package is the solution: It used the \package{everyshi}
193 % package\cite{package:everyshi} to set \Count{1} to \Count{9} before
194 % each \cs{shipout} with these values. Today it is using the kernel's shipout hooks \cite{texdoc:ltshipout}.
195 %
196 % \begin{center}
197 % \begin{tabular}{cl}\toprule
198 % \Count{} & value \\ \midrule
199 % 0 & relative page number (set by \LaTeX)\\
200 % 1 & absolute page number\\
201 % 2 & number of current \cs{part} \\
202 % 3 & number of current \cs{chapter} (0 with article class)\\
203 % 4 & number of current \cs{section} \\
204 % 5 & number of current \cs{subsection} \\
205 % 6 & number of current \cs{subsubsection} \\
206 % 7 & number of current \cs{paragraph} \\
207 % 8 & number of current \cs{subparagraph} \\
208 % 9 & 1 on odd pages, 0 on even pages\footnotemark\\
209 % \bottomrule
210 % \end{tabular}
211 % \end{center}
212 % \footnotetext{^^A
213 % If you have a better application for \Count{9}, let me know.}
214 %
215 % \noindent
216 % \textsf{count1to} also works with classes that do not define some
217 % or all of the sectioning commands and their counters, like
218 % \textsf{letter}.
219 % Although it is of somewhat little use then \texttt{:-)}.
220 %
221 % A note for users of this package: When you select the pages of
222 % some part of your document with a lower structure than
223 % \cs{chapter}, remember that only \cs{part}s and \cs{chapter}s
224 % start on a new page; if you want to print a complete
225 % \cs{section}, you should also select the first page of the next
226 % \cs{section}.
227 % Also note that \TeX{} ships out the values of the counters instead
228 % of their visual representation (produced with
229 % \cs{the}\emph{counter}), so appendix A sets \Count{4} to 1 in the
230 % article class.
231 %
232 % A note for developers of device drivers: Please add support for
233 % \Count{1} to~\texttt{9} to your programs.
234 % It would also be nice if users could easily select the next
235 % page(s) after a certain count (something like
236 % ``\texttt{*.*.*.*.2+1.*}'' should be possible for selecting all
237 % pages with $\Count{4}\mapsto\mathrm{section}=2$ plus the first
238 % page of section~3).
239 %
240 % ^^A -----------------------------
241 %
242 % \section{Options}
243 % ^^A
244 % The package has no options.
245 %
246 %
247 % ^^A -----------------------------
248 %
249 % \section{Required packages}
250 % ^^A
251 % With \LaTeX2e{} releases newer than 2020/10/01 this package does not require any other package.
252 %
253 %
254 % ^^A -----------------------------
255 %
256 % \StopEventually{^^A
257 %
258 % ^^A -----------------------------
259 %
260 % \section{Acknowledgements}
261 % ^^A
262 % As usual Rebecca Stiels improved the quality of this documentation.
263 %
264 %
265 % ^^A -----------------------------
266 %
267 % \begin{thebibliography}{1}
268 % \raggedright
269 % \bibitem{package:lastpage}
270 % Jeff Goldberg.
271 % \newblock The \package{lastpage}-package.
272 % \newblock \url{CTAN: tex-archive/macros/latex/contrib/other/lastpage}.
273 % \newblock \LaTeXe{} package.
274 % \bibitem{KnuthTeXa}
275 % Donald~E.\ Knuth.
276 % \newblock \emph{The {\TeX}Book}, volume~A of \emph{Computers
277 % and Typesetting}.
278 % \newblock Addison-Wes\-ley, 1986.
279 % \newblock Eleventh printing, revised, May 1991.
280 % \bibitem{package:totpages}
281 % Wilhelm M\"uller.
282 % \newblock The \package{totpages} package.
283 % \newblock \url{CTAN: tex-archive/macros/latex/contrib/supported/totpages/}.
284 % \newblock \LaTeXe{} package.
285 % \bibitem{package:hyperref}
286 % Sebastian Rahtz.
287 % \newblock Hypertext marks in \LaTeX.
288 % \newblock \url{CTAN: tex-archive/macros/latex/contrib/supported/hyperref/}.
289 % \bibitem{package:everyshi}
290 % Martin Schröder.
291 % \newblock The \package{everyshi} package.
292 % \newblock \url{CTAN: tex-archive/macros/latex/contrib/supported/ms/everyshi.dtx}.
293 % \newblock \LaTeXe{} package.
294 % \bibitem{texdoc:ltshipout}
295 % \newblock Frank Mittelbach, \LaTeX{} Project Team.
296 % \newblock The ltshipout documentation.
297 % \newblock \url{https://mirrors.ctan.org/macros/latex/base/ltshipout-doc.pdf}
298 % \end{thebibliography}
299 %
300 % }
301 %
302 %
303 % ^^A -----------------------------
304 %
305 % \section{The implementation}
306 % ^^A
307 % \setlength{\parindent}{0pt}
308 % \begin{macrocode}
309 %<*package>
310 % \end{macrocode}
311 %
312 % \changes{v1.20}{1998/04/10}{don't require \textsf{ifthen}}
313 % \changes{v1.10}{1997/11/01}{require \textsf{ifthen}}
314 % \changes{v2.11}{2024-06-13}{\package{everyshi} is obsolete}
315 %
316 % We need various \cs{if}s to check if the used counters
317 % are defined.
318 % \changes{v1.20}{1998/04/10}{\cs{newif} again}
319 % \changes{v1.10}{1997/11/01}{\cs{newboolean}}
320 % \begin{macrocode}
321 \newif\if@have@part
322 \newif\if@have@chapter
323 \newif\if@have@section
324 \newif\if@have@subsection
325 \newif\if@have@subsubsection
326 \newif\if@have@paragraph
327 \newif\if@have@subparagraph
328 % \end{macrocode}
329 %
330 % \begin{macro}{\@countItoIX@ifs}
331 % \cs{@countItoIX@ifs} is used to set all these \cs{if}s at
332 % |\begin{document}|.
333 % It is undefined after use to save some space.
334 % \changes{v2.00}{2002/08/31}{moved code for \cs{AtBeginDocument} to
335 % \cs{@countItoIX@init}}
336 % \changes{v1.20}{1998/04/10}{don't use \textsf{ifthen}}
337 % \changes{v1.10}{1997/11/01}{\cs{setboolean}}
338 % \changes{v1.02}{1996/12/29}{destruct after usage}
339 % \begin{macrocode}
340 \newcommand*{\@countItoIX@ifs}{
341 \@ifundefined{c@part} {}{\@have@parttrue}
342 \@ifundefined{c@chapter} {}{\@have@chaptertrue}
343 \@ifundefined{c@section} {}{\@have@sectiontrue}
344 \@ifundefined{c@subsection} {}{\@have@subsectiontrue}
345 \@ifundefined{c@subsubsection} {}{\@have@subsubsectiontrue}
346 \@ifundefined{c@paragraph} {}{\@have@paragraphtrue}
347 \@ifundefined{c@subparagraph} {}{\@have@subparagraphtrue}
348 }
349 % \end{macrocode}
350 % \end{macro}
351 %
352 % \begin{macro}{\@countItoIX@bugfix}
353 % The current version of \LaTeX{} has the ``feature'' that only the
354 % first level of counters associated with a counter via the optional
355 % argument of \cs{newcounter} is reset when the counter is stepped;
356 % so when you start a new chapter, the number for the subsection is
357 % not reset.
358 % This is normally no problem, but with this package, it is: If this
359 % bug is not fixed or worked-around, then whenever you use
360 % \cs{subparagraph} or some other lower sectioning command, and
361 % after that a sectioning command that is at least two levels higher
362 % (e.\,g. \cs{subsubsection}), the value of \texttt{subparagraph}
363 % would not be reset and would still be displayed and shipped out.
364 % So we have to associate \emph{all} lower-level sectioning commands
365 % with the higher levels.
366 % This is done via \cs{@addtoreset} at \cs{begin\{document\}}.
367 % \cs{@countItoIX@bugfix} is undefined after use to save some space.
368 % \changes{v2.00}{2002/08/31}{moved code for \cs{AtBeginDocument} to
369 % \cs{@countItoIX@init}}
370 % \changes{v1.20}{1998/04/10}{don't use \textsf{ifthen}}
371 % \changes{v1.10}{1997/11/01}{\cs{ifthenelse}}
372 % \changes{v1.02}{1996/12/29}{destruct after usage}
373 % \begin{macrocode}
374 \newcommand*{\@countItoIX@bugfix}{
375 \if@have@part
376 \@addtoreset{section} {part}
377 \@addtoreset{subsection} {part}
378 \@addtoreset{subsubsection}{part}
379 \@addtoreset{paragraph} {part}
380 \@addtoreset{subparagraph} {part}
381 \fi
382 \if@have@chapter
383 \@addtoreset{subsection} {chapter}
384 \@addtoreset{subsubsection}{chapter}
385 \@addtoreset{paragraph} {chapter}
386 \@addtoreset{subparagraph} {chapter}
387 \fi
388 \if@have@section
389 \@addtoreset{subsubsection}{section}
390 \@addtoreset{paragraph} {section}
391 \@addtoreset{subparagraph} {section}
392 \fi
393 \if@have@subsection
394 \@addtoreset{paragraph} {subsection}
395 \@addtoreset{subparagraph} {subsection}
396 \fi
397 \if@have@subsubsection
398 \@addtoreset{subparagraph} {subsubsection}
399 \fi
400 }
401 % \end{macrocode}
402 % \end{macro}
403 %
404 % \begin{macro}{\@countItoIX@init}
405 % \changes{v2.00}{2002/08/31}{new}
406 % \cs{@countItoIX@init} calls \cs{\@countItoIX@ifs} and
407 % \cs{@countItoIX@bugfix} and then frees their memory.
408 % This is done at \cs{begin\{document\}} via \cs{AtBeginDocument}.
409 % \begin{macrocode}
410 \newcommand*{\@countItoIX@init}{%
411 \message{ABD: Count1to9 initializing macros}%
412 \@countItoIX@ifs\let\@countItoIX@ifs\undefined
413 \@countItoIX@bugfix\let\@countItoIX@bugfix\undefined
414 }
415 \AddToHook{begindocument}[count1to-init]{\@countItoIX@init}
416 % \end{macrocode}
417 % \end{macro}
418 %
419 %
420 % \begin{macro}{\@countItoIX@shipout}
421 % \cs{@countItoIX@shipout} is used for setting \Count{1} to
422 % \Count{9} at each \cs{shipout}.
423 % \begin{macrocode}
424 \newcommand*{\@countItoIX@shipout}{
425 % \end{macrocode}
426 % \Count{1} is the absolute page number, which we have to maintain
427 % by ourselves.
428 % \begin{macrocode}
429 \global\advance \count1 by 1
430 % \end{macrocode}
431 % \Count{2} to \Count{8} are set with the values of
432 % \cs{part} to \cs{subparagraph}, if these commands are defined.^^A
433 % \footnote{We should probably also check the value of
434 % \texttt{secnumdepth}, but I don't think this is necessary.}
435 % \changes{v1.20}{1998/04/10}{don't use \textsf{ifthen}}
436 % \changes{v1.10}{1997/11/01}{\cs{ifthenelse}}
437 % \begin{macrocode}
438 \if@have@part \count2\value{part} \fi
439 \if@have@chapter \count3\value{chapter} \fi
440 \if@have@section \count4\value{section} \fi
441 \if@have@subsection \count5\value{subsection} \fi
442 \if@have@subsubsection \count6\value{subsubsection} \fi
443 \if@have@paragraph \count7\value{paragraph} \fi
444 \if@have@subparagraph \count8\value{subparagraph} \fi
445 % \end{macrocode}
446 % \Count{9} is set to~1 on odd pages and to~0 on even pages.
447 % \begin{macrocode}
448 \ifodd\count1\count9=1 \else\count9=0 \fi
449 }
450 % \end{macrocode}
451 % \changes{v2.11}{2024-06-13}{Remove everyshi but add compatibility mode}
452 % \begin{macrocode}
453 \providecommand\IfFormatAtLeastTF{\@ifl@t@r\fmtversion}
454 \IfFormatAtLeastTF{2020/10/01}{
455 \AddToHook{shipout/before}[count1to-shipout]{\@countItoIX@shipout}
456 }{
457 \RequirePackage{everyshi}
458 \EveryShipount{\@countItoIX@shipout}
459 }
460 % \end{macrocode}
461 % \end{macro}
462 %
463 % \begin{macrocode}
464 %</package>
465 % \end{macrocode}
466 %
467 % ^^A -----------------------------
468 %
469 % \Finale
470 %
471 % \PrintIndex\PrintChanges
472 % ^^A Make sure that the index is not printed twice
473 % ^^A (ltxdoc.cfg might have a second \PrintIndex command)
474 % \let\PrintChanges\relax
475 % \let\PrintIndex\relax