summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/changepage/chngpage.sty
blob: 5f2542fcb1fd38cd4fede94b6a361d07f88f8448 (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
%% LaTeX2e file `chngpage.sty'
%% generated by the `filecontents' environment
%% from source `changepage' on 2009/10/20.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PLEASE NOTE:
% THIS PACKAGE IS DEPRECATED IN FAVOUR OF CHANGEPAGE.STY FOR REASONS
% OF COMPATIBILITY WITH THE MEMOIR CLASS. The two are equivalent;
% please do not use this one for new documents or packages.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{chngpage}[2009/10/20 v1.2b change page layout]

%% Note: internal package commands all include the string |cp@|.
%% New \cs{if} for the strict option.
\newif\ifcpstrict
  \cpstrictfalse

%% Declare and process options.
\DeclareOption{strict}{\cpstricttrue}
\ProcessOptions\relax

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% New commands for strict checking of odd/even page.
% Works by writing a label and then checking its pageref.
%
% Rewritten in v1.2 to handle roman, Roman, etc page numbers
% as well as arabic; also eliminates special code to handle
% hyperref. Based on the code in the memoir class.

\newif\ifcpoddpage
\newcounter{cp@cnt}
\newcounter{cp@tempcnt}
\newcommand{\cplabelprefix}{^_}

\gdef\thecp@page{\the\c@page}
\long\def\cp@protected@write#1#2#3{%  % modified \cs{protected@write}
  \begingroup
  \let\thecp@page\relax
  #2%
  \let\protect\@unexpandable@protect
  \edef\reserved@a{\write#1{#3}}%
  \reserved@a
  \endgroup
  \if@nobreak\ifvmode\nobreak\fi\fi}

\DeclareRobustCommand{\checkoddpage}{%
  \cpoddpagefalse
  \stepcounter{cp@cnt}\cplabel{\cplabelprefix\thecp@cnt}%
  \c@cp@tempcnt=\cp@labelref{\cplabelprefix\thecp@cnt}\relax
  \ifodd\c@cp@tempcnt\cpoddpagetrue\fi}

\newcommand{\cplabel}[1]{\@bsphack
  \cp@protected@write\@auxout{}%
    {\string\newcplabel{#1}{\thecp@page}}%
  \@esphack}

\newcommand{\newcplabel}[2]{{\global\@namedef{p@#1}{#2}}}

\newcommand{\cp@labelref}[1]{%
  \expandafter\ifx\csname p@#1\endcsname\relax
    0%  % 0 if there is no label yet in aux file
  \else
    \csname p@#1\endcsname
  \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}[3][\@empty]{%
  \begin{list}{}{%
    \topsep\z@%
    \listparindent\parindent%
    \parsep\parskip%
    \@ifmtarg{#2}{\setlength{\leftmargin}{\z@}}{\setlength{\leftmargin}{#2}}%
    \@ifmtarg{#3}{\setlength{\rightmargin}{\z@}}{\setlength{\rightmargin}{#3}}%
    \ifx\@empty #1\relax \else
      \cpoddpagefalse
      \ifcpstrict\checkoddpage\else
        \ifodd\c@page\cpoddpagetrue\fi
      \fi
      \ifcpoddpage\else  % even numbered page
        \@ifmtarg{#3}{\setlength{\leftmargin}{\z@}}{\setlength{\leftmargin}{#3}}%
        \@ifmtarg{#2}{\setlength{\rightmargin}{\z@}}{\setlength{\rightmargin}{#2}}%
      \fi
    \fi}
    \item[]}{\end{list}}

\endinput