blob: 1ecc31d8cd5084a375a388737152ff7e7bb8b1ac (
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
%D \module
%D [ file=spac-pag,
%D version=2009.10.16, % 1997.03.31, was core-spa.tex
%D title=\CONTEXT\ Spacing Macros,
%D subtitle=Pages,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
\writestatus{loading}{ConTeXt Spacing Macros / Pages}
\unprotect
%D The code here has evolved over time and might not be the best
%D around. Maybe much will be gone a some point.
\installcorenamespace {alignswitch}
\letvalue{\??alignswitch\v!left }\zerocount
\letvalue{\??alignswitch\v!middle}\plusone
\letvalue{\??alignswitch\v!right }\plustwo
\def\setalignmentswitch#1%
{\chardef\alignmentswitch\csname\??alignswitch\ifcsname\??alignswitch#1\endcsname#1\else\v!left\fi\endcsname}
\newif \ifpagestatemismatch
\newcount \realpagestateno
\newconstant\frozenpagestate
\def\dotrackpagestate#1#2%
{\ifdoublesided \ifinpagebody \else
\doforcedtrackpagestate{#1}{#2}%
\fi \fi}
\def\doforcedtrackpagestate#1#2%
{\ifcase\frozenpagestate
\global\advance#2\plusone
\setpagestate[#1][\number#2]%
\fi}
\let\m_spac_pagestates_realpage\empty
\newconditional\c_spac_pagestates_found
\unexpanded\def\docheckpagestate#1#2%
{\ifcase\frozenpagestate
\setpagestaterealpageno{#1}{\number#2}%
\fi}
\unexpanded\def\doifelserightpagestate#1#2% not expandable !
{\ifcase\frozenpagestate
\pagestatemismatchfalse
\realpagestateno\realfolio
\ifinpagebody
\ifdoublesided
\ifodd\realpageno\relax
\settrue\c_spac_pagestates_found
\else
\setfalse\c_spac_pagestates_found
\fi
\else
\settrue\c_spac_pagestates_found
\fi
\else\ifdoublesided
\edef\m_spac_pagestates_realpage{\pagestaterealpage{#1}{\number#2}}%
\ifx\m_spac_pagestates_realpage\empty
\ifodd\realpageno\relax
\settrue\c_spac_pagestates_found
\else
\setfalse\c_spac_pagestates_found
\fi
\else
\realpagestateno\m_spac_pagestates_realpage\relax
\ifnum\realpagestateno=\realpageno \else
\pagestatemismatchtrue
\fi
\ifodd\realpagestateno\relax
\settrue\c_spac_pagestates_found
\else
\setfalse\c_spac_pagestates_found
\fi
\fi
\else
\settrue\c_spac_pagestates_found
\fi\fi
\else
\ifodd\realpagestateno\relax
\settrue\c_spac_pagestates_found
\else
\setfalse\c_spac_pagestates_found
\fi
\fi
\ifconditional\c_spac_pagestates_found
\expandafter\firstoftwoarguments
\else
\expandafter\secondoftwoarguments
\fi}
\unexpanded\def\doifelseforcedrightpagestate#1#2%
{\ifcase\frozenpagestate
\pagestatemismatchfalse
\realpagestateno\realfolio
\edef\m_spac_pagestates_realpage{\pagestaterealpage{#1}{\number#2}}%
\ifx\m_spac_pagestates_realpage\empty
\ifodd\realpageno\relax
\settrue\c_spac_pagestates_found
\else
\setfalse\c_spac_pagestates_found
\fi
\else
\realpagestateno\m_spac_pagestates_realpage\relax
\ifnum\realpagestateno=\realpageno \else
\pagestatemismatchtrue
\fi
\ifodd\realpagestateno\relax
\settrue\c_spac_pagestates_found
\else
\setfalse\c_spac_pagestates_found
\fi
\fi
\else
\ifodd\realpagestateno\relax
\settrue\c_spac_pagestates_found
\else
\setfalse\c_spac_pagestates_found
\fi
\fi
\ifconditional\c_spac_pagestates_found
\expandafter\firstoftwoarguments
\else
\expandafter\secondoftwoarguments
\fi}
\let\doifrightpagestateelse \doifelserightpagestate
\let\doifforcedrightpagestateelse\doifelseforcedrightpagestate
\unexpanded\def\freezepagestate {\frozenpagestate\plusone }
\unexpanded\def\defrostpagestate{\frozenpagestate\zerocount}
% we can make more of these on top, but how to deal with mixed frozen states
% \dorecurse{500}{\dontleavehmode\signalrightpage\doifrightpageelse{right}{left}\par} % given doublesided
\newcount\nofraggedparagraphs
\definepagestate[\s!paragraph]
\unexpanded\def\signalrightpage {\dotrackpagestate \s!paragraph\nofraggedparagraphs} % use \dontleavehmode if needed
\unexpanded\def\doifelserightpage{\doifelserightpagestate\s!paragraph\nofraggedparagraphs}
\let\doifrightpageelse\doifelserightpage
\installcorenamespace{pagechanges}
\newif\ifpagechanged \let\lastchangedpage\empty
\def\spac_pagechanges_check#1#2#3%
{\pagechangedfalse
\doforcedtrackpagestate{#2}{#3}%
\edef\m_spac_pagestates_realpage{\pagestaterealpage{#2}{\number#3}}%
\ifx\m_spac_pagestates_realpage\empty \else
\ifnum\m_spac_pagestates_realpage>0\getvalue{\??pagechanges#2:#1}\relax
\pagechangedtrue
\fi
\fi
\ifpagechanged
\letgvalue{\??pagechanges#2:#1}\m_spac_pagestates_realpage
\globallet\lastchangedpage\m_spac_pagestates_realpage
\else
\globallet\lastchangedpage\realfolio
\fi}
\def\changedpagestate#1#2%
{\executeifdefined{\??pagechanges#2:#1}0}
\def\checkpagechange#1{\spac_pagechanges_check{#1}\s!paragraph\nofraggedparagraphs}
\def\changedpage #1{\changedpagestate{#1}\s!paragraph}
\protect \endinput
|