| 1 |
% \iffalse |
| 2 |
% File: ordinalpt.dtx |
| 3 |
% Copyright (C) 2007 Miguel V. S. Frasson ([email protected]) |
| 4 |
% |
| 5 |
% This package may be distributed under the terms of the LaTeX |
| 6 |
% Project Public License, as described in lppl.txt in the base |
| 7 |
% LaTeX distribution, either version 1.2 or (at your option) |
| 8 |
% any later version. |
| 9 |
% |
| 10 |
%<*driver> |
| 11 |
\documentclass{ltxdoc} |
| 12 |
\usepackage{doc} |
| 13 |
\usepackage{ae} |
| 14 |
\usepackage{url} |
| 15 |
|
| 16 |
\begin{document} |
| 17 |
\DocInput{pagecont.dtx} |
| 18 |
\end{document} |
| 19 |
%</driver> |
| 20 |
% \fi |
| 21 |
% |
| 22 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 23 |
% |
| 24 |
% \StopEventually |
| 25 |
% |
| 26 |
% \changes{1.0}{2009/05/26}{initial version} |
| 27 |
% |
| 28 |
% \MakeShortVerb+ |
| 29 |
% |
| 30 |
% \title{\textsf{pagecont}: Page numbering continuation between documents} |
| 31 |
% \author{Miguel V.\ S.\ Frasson} |
| 32 |
% \date{2009--05--26 version 1.0} |
| 33 |
% |
| 34 |
% \maketitle |
| 35 |
% |
| 36 |
% \tableofcontents |
| 37 |
% |
| 38 |
% \section{Introduction} |
| 39 |
% |
| 40 |
% The package \textsf{pagecont} implements the functionality that |
| 41 |
% several documents can be typeset independently with page numbers in |
| 42 |
% sequence, like if they were a single document. |
| 43 |
% |
| 44 |
% \section{Usage} |
| 45 |
% |
| 46 |
% \begin{itemize} |
| 47 |
% |
| 48 |
% \item Ensure that all files run without errors. |
| 49 |
% |
| 50 |
% \item In the first document call the package with option `+first+'. |
| 51 |
% \begin{quote} |
| 52 |
% +\usepackage[first]{pagecont}+ |
| 53 |
% \end{quote} |
| 54 |
% \item In other documents, just call the package. |
| 55 |
% \begin{quote} |
| 56 |
% +\usepackage{pagecont}+ |
| 57 |
% \end{quote} |
| 58 |
% \item Run as many times as needed every document, but in the |
| 59 |
% sequence of documents; that is, run (as many times needed) the first |
| 60 |
% document, then run (as many times needed) the second, and so on. |
| 61 |
% |
| 62 |
% \end{itemize} |
| 63 |
% |
| 64 |
% At every run, the output files are produced normally, but the first |
| 65 |
% page of the second document is 1 plus the last page of the previous |
| 66 |
% one, and so on. |
| 67 |
% |
| 68 |
% \section{Idea of implementation} |
| 69 |
% |
| 70 |
% At the end of documents, a file (default is `+pagecont.pco+') is |
| 71 |
% saved with the current file information plus last file last page. |
| 72 |
% If the filename saved is the same, uses the last file last page. If |
| 73 |
% it is not the same, then you are compiling another file, so the last |
| 74 |
% page saved plus 1 is to be used as new first page. |
| 75 |
% |
| 76 |
% If the file saved does not exist, then no page is set, like if this |
| 77 |
% document is the first one. |
| 78 |
% |
| 79 |
% \section{User options} |
| 80 |
% |
| 81 |
% \DescribeEnv{first} |
| 82 |
% The document that uses the option +first+ does not set pages. It is |
| 83 |
% safer to use this option, because afterwards one starts again to |
| 84 |
% process the documents from the beginning, and if the file where the |
| 85 |
% info is saved exists, the page numbering will continue from the |
| 86 |
% number saved in the last run. |
| 87 |
% |
| 88 |
% \DescribeEnv{savefile=\textit{filename}} |
| 89 |
% With option `\texttt{savefile=\textit{filename}}' you can override |
| 90 |
% the default save file, which is +pagecont.pco+. |
| 91 |
% |
| 92 |
% \section{Code} |
| 93 |
% |
| 94 |
% Identidication of the package. |
| 95 |
% \begin{macrocode} |
| 96 |
\NeedsTeXFormat{LaTeX2e} |
| 97 |
\ProvidesPackage{pagecont}% |
| 98 |
[2009/05/26 v1 Page numbering continuation between documents] |
| 99 |
% \end{macrocode} |
| 100 |
% |
| 101 |
% Using package \textsf{keyval}. |
| 102 |
% \begin{macrocode} |
| 103 |
\RequirePackage{keyval} |
| 104 |
% \end{macrocode} |
| 105 |
% |
| 106 |
% \DescribeEnv{first} |
| 107 |
% Declaring option \texttt{first}, which sets a switch when executed. |
| 108 |
% \begin{macrocode} |
| 109 |
\newif\ifPGC@first |
| 110 |
\PGC@firstfalse |
| 111 |
\DeclareOption{first}{\PGC@firsttrue} |
| 112 |
% \end{macrocode} |
| 113 |
% |
| 114 |
% \DescribeEnv{savefile=\textit{filename}} |
| 115 |
% Declaring option \texttt{savefile=\textit{filename}}, using the |
| 116 |
% \textsf{keyval} package. |
| 117 |
% \begin{macrocode} |
| 118 |
\newcommand{\PGC@savefile}{pagecont.pco} |
| 119 |
\define@key{PGC@}{savefile}{\renewcommand{\PGC@savefile}{#1}} |
| 120 |
\newcommand{\PGC@kvsetkeys}[1]{\setkeys{PGC@}{#1}} |
| 121 |
\DeclareOption*{\expandafter\PGC@kvsetkeys\expandafter{\CurrentOption}} |
| 122 |
% \end{macrocode} |
| 123 |
% |
| 124 |
% Processing options. |
| 125 |
% \begin{macrocode} |
| 126 |
\ProcessOptions |
| 127 |
% \end{macrocode} |
| 128 |
% |
| 129 |
% \DescribeMacro{\PGC@info} |
| 130 |
% The macro +\PGC@info+, which is the content of the file |
| 131 |
% +\PGC@savefile+, has 3 args. The first is the jobname of the file |
| 132 |
% that saved the file. When called (at package call), it compares the |
| 133 |
% saved jobname and the actual +\jobname+. If they are the same, then |
| 134 |
% we should use the last page of last document (with different |
| 135 |
% jobname). This last page is the second arg of +\PGC@info+. If the |
| 136 |
% jobnames are different, the last page of last run, the third arg of |
| 137 |
% +\PGC@info+, is used as new start for counter \texttt{page}. |
| 138 |
% |
| 139 |
% \DescribeMacro{\PGC@lastfilelastpage} |
| 140 |
% The second argument of +\PGC@info+ is saved in the macro |
| 141 |
% +\PGC@lastfilelastpage+, which is originally set to be 0. This |
| 142 |
% macro will be used when saving the file, at +\end{document}+ time. |
| 143 |
% |
| 144 |
% \begin{macrocode} |
| 145 |
\newcommand{\PGC@lastfilelastpage}{0} |
| 146 |
\newcommand{\PGC@info}[3]{% |
| 147 |
% \end{macrocode} |
| 148 |
% The primitive +\jobname+ outputs chars with |
| 149 |
% catcode 12 (other), so it is needed a hack using +\meaning+ to |
| 150 |
% compare the two strings. See |
| 151 |
% \url{http://www.tex.ac.uk/cgi-bin/texfaq2html?label=compjobnam}. |
| 152 |
% \begin{macrocode} |
| 153 |
\edef\PGC@jobname{\jobname}% |
| 154 |
\def\PGC@jobnamesaved{#1}% |
| 155 |
\edef\PGC@jobnamesaved{\expandafter\strip@prefix\meaning\PGC@jobnamesaved}% |
| 156 |
\ifx\PGC@jobname\PGC@jobnamesaved |
| 157 |
\renewcommand{\PGC@lastfilelastpage}{#2}% |
| 158 |
\setcounter{page}{#2}% |
| 159 |
\else |
| 160 |
\renewcommand{\PGC@lastfilelastpage}{#3}% |
| 161 |
\setcounter{page}{#3}% |
| 162 |
\fi |
| 163 |
% \end{macrocode} |
| 164 |
% Increments counter page to be the number after the last page of last |
| 165 |
% document. |
| 166 |
% \begin{macrocode} |
| 167 |
\addtocounter{page}{1}} |
| 168 |
% \end{macrocode} |
| 169 |
% |
| 170 |
% \DescribeMacro{\PGC@savefile} |
| 171 |
% \DescribeMacro{\PGC@saveinfo} |
| 172 |
% Now the macro for saving information into file +\PGC@savefile+. |
| 173 |
% The macro +\PGC@saveinfo+ writes to file with filename |
| 174 |
% +\PGC@savefile+ the line |
| 175 |
% \begin{quote}\ttfamily |
| 176 |
% \string\PGC@info+{+\textit{jobname}+}{+\textit{lastfile-lastpage}+}{+\textit{lastpage}+}+ |
| 177 |
% \end{quote} |
| 178 |
% where \texttt{\textit{jobname}}, \texttt{\textit{lastfile-lastpage}} |
| 179 |
% and \texttt{\textit{lastpage}} are the full expansions of |
| 180 |
% +\jobname+, +\PGC@lastfilelastpage+ and +\arabic{page}+, |
| 181 |
% respectively. |
| 182 |
% \begin{macrocode} |
| 183 |
\newcommand{\PGC@saveinfo}{% |
| 184 |
\newwrite\PGC@file |
| 185 |
\expandafter\openout\expandafter\PGC@file\PGC@savefile\relax |
| 186 |
\write\PGC@file |
| 187 |
{\string\PGC@info{\jobname}{\PGC@lastfilelastpage}{\arabic{page}}}} |
| 188 |
% \end{macrocode} |
| 189 |
% |
| 190 |
% At +\end{document}+, save all to file, by the +\PGC@saveinfo+ macro. |
| 191 |
% \begin{macrocode} |
| 192 |
\AtEndDocument{\PGC@saveinfo} |
| 193 |
% \end{macrocode} |
| 194 |
% |
| 195 |
% Finally, starts action by including file `+\PGC@savefile+', when file |
| 196 |
% is not marked as first of the series. |
| 197 |
% \begin{macrocode} |
| 198 |
\ifPGC@first |
| 199 |
\else |
| 200 |
\IfFileExists{\PGC@savefile}{\input{\PGC@savefile}}{} |
| 201 |
\fi |
| 202 |
% \end{macrocode} |
| 203 |
% End of file. |
| 204 |
% \begin{macrocode} |
| 205 |
\endinput |
| 206 |
% \end{macrocode} |
| 207 |
|