-
Notifications
You must be signed in to change notification settings - Fork 0
/
changepage.sty
142 lines (122 loc) · 4.42 KB
/
changepage.sty
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
141
%% LaTeX2e file `changepage.sty'
%% generated by the `filecontents' environment
%% from source `changepage' on 2009/10/20.
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{changepage}[2009/10/20 v1.0c check page and change page layout]
% Don't use this with memoir
\newcommand*{\cp@whoopsusingmemoir}{}
\@ifclassloaded{memoir}{\def\cp@whoopsusingmemoir{\endinput}}
\cp@whoopsusingmemoir
% New \verb|\if| for the strict option
\newif\ifstrictpagecheck
\strictpagecheckfalse
% User commands for switching strict page checking on/off
\newcommand*{\strictpagecheck}{\strictpagechecktrue}
\newcommand*{\easypagecheck}{\strictpagecheckfalse}
% Declare and process options
\DeclareOption{strict}{\strictpagechecktrue}
\ProcessOptions\relax
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% New commands for strict checking of odd/even page.
%% Works by writing a label and then checking its pageref.
\newif\ifoddpage
\newcounter{cp@cntr}
\newcount\cp@tempcnt % instead of \verb|\@memcnta|
\newcommand{\cplabel}{^_}
\gdef\thepmemc@@page{\the\c@page}
\long\def\pmemprotected@write#1#2#3{% modified \verb|\protected@write|
\begingroup
\let\thepmemc@@page\relax
#2%
\let\protect\@unexpandable@protect
\edef\reserved@a{\write#1{#3}}%
\reserved@a
\endgroup
\if@nobreak\ifvmode\nobreak\fi\fi}
\newcommand*{\pmemlabel}[1]{\@bsphack
\pmemprotected@write\@auxout{}%
{\string\newpmemlabel{#1}{\thepmemc@@page}}%
\@esphack}
\newcommand*{\newpmemlabel}[2]{{\global\@namedef{m@#1}{#2}}}
\newcommand*{\pmemlabelref}[1]{%
\expandafter\ifx\csname m@#1\endcsname\relax
0% % 0 if there is no label yet in the aux file
\else
\csname m@#1\endcsname
\fi}
\DeclareRobustCommand{\checkoddpage}{%
\oddpagefalse%
\ifstrictpagecheck%
\stepcounter{cp@cntr}\pmemlabel{\cplabel\thecp@cntr}%
\cp@tempcnt=\pmemlabelref{\cplabel\thecp@cntr}\relax
\ifodd\cp@tempcnt\oddpagetrue\fi
\else
\ifodd\c@page\oddpagetrue\fi
\fi}
% End newcommands for strict checking of odd/even page.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copy of some of the code from the ifmtarg package to save requiring ifmtarg
\begingroup
\catcode`\Q=3
\long\gdef\@ifmtarg#1{\@xifmtarg#1QQ\@secondoftwo\@firstoftwo\@nil}
\long\gdef\@xifmtarg#1#2Q#3#4#5\@nil{#4}
\endgroup
% Set the page output parameters
\DeclareRobustCommand{\ch@ngetext}{%
\setlength{\@colht}{\textheight}\setlength{\@colroom}{\textheight}%
\setlength{\vsize}{\textheight}\setlength{\columnwidth}{\textwidth}%
\if@twocolumn%
\advance\columnwidth-\columnsep \divide\columnwidth\tw@%
\@firstcolumntrue%
\fi%
\setlength{\hsize}{\columnwidth}%
\setlength{\linewidth}{\hsize}}
\DeclareRobustCommand{\changetext}[5]{%
\@ifmtarg{#1}{}{\addtolength{\textheight}{#1}}%
\@ifmtarg{#2}{}{\addtolength{\textwidth}{#2}}%
\@ifmtarg{#3}{}{\addtolength{\evensidemargin}{#3}}%
\@ifmtarg{#4}{}{\addtolength{\oddsidemargin}{#4}}%
\@ifmtarg{#5}{}{\addtolength{\columnsep}{#5}}%
\ch@ngetext}
\DeclareRobustCommand{\changepage}[9]{%
\@ifmtarg{#1}{}{\addtolength{\textheight}{#1}}%
\@ifmtarg{#2}{}{\addtolength{\textwidth}{#2}}%
\@ifmtarg{#3}{}{\addtolength{\evensidemargin}{#3}}%
\@ifmtarg{#4}{}{\addtolength{\oddsidemargin}{#4}}%
\@ifmtarg{#5}{}{\addtolength{\columnsep}{#5}}%
\ch@ngetext%
\@ifmtarg{#6}{}{\addtolength{\topmargin}{#6}}%
\@ifmtarg{#7}{}{\addtolength{\headheight}{#7}}%
\@ifmtarg{#8}{}{\addtolength{\headsep}{#8}}%
\@ifmtarg{#9}{}{\addtolength{\footskip}{#9}}}
\newenvironment{adjustwidth}[2]{%
\begin{list}{}{%
\topsep\z@%
\listparindent\parindent%
\parsep\parskip%
\@ifmtarg{#1}{\setlength{\leftmargin}{\z@}}%
{\setlength{\leftmargin}{#1}}%
\@ifmtarg{#2}{\setlength{\rightmargin}{\z@}}%
{\setlength{\rightmargin}{#2}}%
}
\item[]}{\end{list}}
\newenvironment{adjustwidth*}[2]{%
\begin{list}{}{%
\topsep\z@%
\listparindent\parindent%
\parsep\parskip%
\checkoddpage
\ifoddpage% odd numbered page
\@ifmtarg{#1}{\setlength{\leftmargin}{\z@}}%
{\setlength{\leftmargin}{#1}}%
\@ifmtarg{#2}{\setlength{\rightmargin}{\z@}}%
{\setlength{\rightmargin}{#2}}%
\else% even numbered page
\@ifmtarg{#2}{\setlength{\leftmargin}{\z@}}%
{\setlength{\leftmargin}{#2}}%
\@ifmtarg{#1}{\setlength{\rightmargin}{\z@}}%
{\setlength{\rightmargin}{#1}}%
\fi}
\item[]}{\end{list}}
\endinput