summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/chappg/chappg.sty
blob: cd4526335d78a5bfff1696f2bce79a9e4160480a (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
%%
%% This is file `chappg.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% chappg.dtx  (with options: `package')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from chappg.sty.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file chappg.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%% This is chappg.dtx, and it's -*-LaTeX-*- text
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{chappg}%
        [2006/05/09 v2.1b page numbering by chapter
     number pages by chapter (or other unit)%
                   ]% $Id: chappg.dtx,v 1.4 2006/05/09 07:12:20 rf10 Exp rf10 $
\newif\if@chappg@auto      \@chappg@autofalse
\newif\if@chappg@resetting \@chappg@resettingfalse
\DeclareOption{auto}{\@chappg@autotrue}
\DeclareOption{noauto}{\@chappg@autofalse}
\ExecuteOptions{auto}
\ProcessOptions
\renewcommand\pagenumbering[2][\@chappg@thechapter]{%
  \global\c@page\@ne
  \protected@xdef\thepage{%
    \expandafter\noexpand\csname @#2\endcsname
      \noexpand\c@page
  }%
  \gdef\@chappg@prefix{#1}%
  \def\@tempa{#2}%
  \def\@tempb{bychapter}%
  \ifx\@tempa\@tempb
    \@chappg@checkloc
    \if@chappg@resetting
    \else
      \@addtoreset{page}{chapter}%
      \@chappg@resettingtrue
    \fi
  \else
    \if@chappg@resetting
      \@removefromreset{page}{chapter}%
      \@chappg@resettingfalse
    \fi
  \fi
}
\newcommand\@bychapter[1]{%
  \@chappg@prefix\chappgsep\@arabic#1%
  \ifx\@chappg@prefix\@chappg@surprise
    \if@chappg@surprised\else
      \xdef\@chappg@surprise@line{\the\inputlineno}%
      \global\@chappg@surprisedtrue
    \fi
  \fi
}
\def\@chappg@thechapter{%
  \ifnum\c@chapter=0
    \expandafter\@gobble
  \else
    \thechapter
  \fi
}
\providecommand\chappgsep{-}
\let\@@mainmatter\mainmatter
\def\mainmatter{\@@mainmatter
  \if@chappg@auto\pagenumbering{bychapter}\fi
}
\let\@@backmatter\backmatter
\def\backmatter{\@@backmatter
  \let\@chappg@prefix\@chappg@surprise
}
\def\@chappg@surprise{\textbf{??}}
\newif\if@chappg@surprised  \@chappg@surprisedfalse
\AtEndDocument{%
  \if@chappg@badloc
    \PackageWarningNoLine{chappg}{Bad location for
      \string\pagestyle{bychapter} command
      \MessageBreak
      \string\clearpage\space or \string\cleardoublepage\space
      \MessageBreak
      recommended before \string\pagestyle\space on line
      \@chappg@badloc@line
    }
  \fi
  \if@chappg@surprised
    \PackageWarningNoLine{chappg}{Possibly surprising page numbering in
      \string\backmatter
      \MessageBreak
      Use \string\pagenumbering[prefix]{bychapter}%
      \MessageBreak
      to select alternative before line \@chappg@surprise@line
    }
  \fi
}
\newif\if@chappg@badloc
\def\@chappg@checkloc{%
  \ifx\@onlypreamble\@notprerr
    \ifhmode
      \@chappg@badloctrue
      \xdef\@chappg@badloc@line{\the\inputlineno}%
    \else
      \ifdim\pagetotal>1sp
        \@chappg@badloctrue
        \xdef\@chappg@badloc@line{\the\inputlineno}%
      \fi
    \fi
  \fi % not in preamble
}
\renewcommand\@stpelt[1]{%
  \global\csname c@#1\endcsname
    \expandafter\ifx \csname c@#1\endcsname \c@page
      \@ne
    \else
      \z@
    \fi
}
\if@chappg@auto\pagenumbering{bychapter}\fi
%% fragment included from\\
%% CTAN macros/latex/contrib/fragments/removefr.tex
%%
\def\@removefromreset#1#2{\let\@tempb\@elt
   \expandafter\let\expandafter\@tempa\csname c@#1\endcsname
   \def\@elt##1{\expandafter\ifx\csname c@##1\endcsname\@tempa\else
         \noexpand\@elt{##1}\fi}%
   \expandafter\edef\csname cl@#2\endcsname{\csname cl@#2\endcsname}%
   \let\@elt\@tempb}
\endinput
%%
%% End of file `chappg.sty'.