spac-pag.mkiv /size: 5529 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=spac-pag,
3
%D version=2009.10.16, % 1997.03.31, was core-spa.tex
4
%D title=\CONTEXT\ Spacing Macros,
5
%D subtitle=Pages,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
\writestatus
{
loading
}{
ConTeXt
Spacing
Macros
/
Pages
}
15 16
\unprotect
17 18
%D The code here has evolved over time and might not be the best
19
%D around. Maybe much will be gone a some point.
20 21
\installcorenamespace
{
alignswitch
}
22 23
\letvalue
{
\??alignswitch\v!left
}
\zerocount
24
\letvalue
{
\??alignswitch\v!middle
}
\plusone
25
\letvalue
{
\??alignswitch\v!right
}
\plustwo
26 27
\def
\setalignmentswitch
#
1
%
28
{
\chardef
\alignmentswitch
\csname
\??alignswitch
\ifcsname
\??alignswitch
#
1
\endcsname
#
1
\else
\v!left
\fi\endcsname
}
29 30
\newif
\ifpagestatemismatch
31
\newcount
\realpagestateno
32
\newconstant
\frozenpagestate
33 34
\def
\dotrackpagestate
#
1
#
2
%
35
{
\ifdoublesided
\ifinpagebody
\else
36
\doforcedtrackpagestate
{
#
1
}{
#
2
}
%
37
\fi
\fi
}
38 39
\def
\doforcedtrackpagestate
#
1
#
2
%
40
{
\ifcase
\frozenpagestate
41
\global\advance
#
2
\plusone
42
\setpagestate
[#
1
][
\number
#
2
]
%
43
\fi
}
44 45
\let
\m_spac_pagestates_realpage
\empty
46 47
\newconditional
\c_spac_pagestates_found
48 49
\unexpanded
\def
\docheckpagestate
#
1
#
2
%
50
{
\ifcase
\frozenpagestate
51
\setpagestaterealpageno
{
#
1
}{
\number
#
2
}
%
52
\fi
}
53 54
\unexpanded
\def
\doifelserightpagestate
#
1
#
2
% not expandable !
55
{
\ifcase
\frozenpagestate
56
\pagestatemismatchfalse
57
\realpagestateno
\realfolio
58
\ifinpagebody
59
\ifdoublesided
60
\ifodd
\realpageno
\relax
61
\settrue
\c_spac_pagestates_found
62
\else
63
\setfalse
\c_spac_pagestates_found
64
\fi
65
\else
66
\settrue
\c_spac_pagestates_found
67
\fi
68
\else
\ifdoublesided
69
\edef
\m_spac_pagestates_realpage
{
\pagestaterealpage
{
#
1
}{
\number
#
2
}}
%
70
\ifx
\m_spac_pagestates_realpage
\empty
71
\ifodd
\realpageno
\relax
72
\settrue
\c_spac_pagestates_found
73
\else
74
\setfalse
\c_spac_pagestates_found
75
\fi
76
\else
77
\realpagestateno
\m_spac_pagestates_realpage
\relax
78
\ifnum
\realpagestateno
=
\realpageno
\else
79
\pagestatemismatchtrue
80
\fi
81
\ifodd
\realpagestateno
\relax
82
\settrue
\c_spac_pagestates_found
83
\else
84
\setfalse
\c_spac_pagestates_found
85
\fi
86
\fi
87
\else
88
\settrue
\c_spac_pagestates_found
89
\fi\fi
90
\else
91
\ifodd
\realpagestateno
\relax
92
\settrue
\c_spac_pagestates_found
93
\else
94
\setfalse
\c_spac_pagestates_found
95
\fi
96
\fi
97
\ifconditional
\c_spac_pagestates_found
98
\expandafter
\firstoftwoarguments
99
\else
100
\expandafter
\secondoftwoarguments
101
\fi
}
102 103
\unexpanded
\def
\doifelseforcedrightpagestate
#
1
#
2
%
104
{
\ifcase
\frozenpagestate
105
\pagestatemismatchfalse
106
\realpagestateno
\realfolio
107
\edef
\m_spac_pagestates_realpage
{
\pagestaterealpage
{
#
1
}{
\number
#
2
}}
%
108
\ifx
\m_spac_pagestates_realpage
\empty
109
\ifodd
\realpageno
\relax
110
\settrue
\c_spac_pagestates_found
111
\else
112
\setfalse
\c_spac_pagestates_found
113
\fi
114
\else
115
\realpagestateno
\m_spac_pagestates_realpage
\relax
116
\ifnum
\realpagestateno
=
\realpageno
\else
117
\pagestatemismatchtrue
118
\fi
119
\ifodd
\realpagestateno
\relax
120
\settrue
\c_spac_pagestates_found
121
\else
122
\setfalse
\c_spac_pagestates_found
123
\fi
124
\fi
125
\else
126
\ifodd
\realpagestateno
\relax
127
\settrue
\c_spac_pagestates_found
128
\else
129
\setfalse
\c_spac_pagestates_found
130
\fi
131
\fi
132
\ifconditional
\c_spac_pagestates_found
133
\expandafter
\firstoftwoarguments
134
\else
135
\expandafter
\secondoftwoarguments
136
\fi
}
137 138
\let
\doifrightpagestateelse
\doifelserightpagestate
139
\let
\doifforcedrightpagestateelse
\doifelseforcedrightpagestate
140 141
\unexpanded
\def
\freezepagestate
{
\frozenpagestate
\plusone
}
142
\unexpanded
\def
\defrostpagestate
{
\frozenpagestate
\zerocount
}
143 144
% we can make more of these on top, but how to deal with mixed frozen states
145 146
% \dorecurse{500}{\dontleavehmode\signalrightpage\doifrightpageelse{right}{left}\par} % given doublesided
147 148
\newcount
\nofraggedparagraphs
149 150
\definepagestate
[
\s!paragraph
]
151 152
\unexpanded
\def
\signalrightpage
{
\dotrackpagestate
\s!paragraph
\nofraggedparagraphs
}
% use \dontleavehmode if needed
153
\unexpanded
\def
\doifelserightpage
{
\doifelserightpagestate
\s!paragraph
\nofraggedparagraphs
}
154
\unexpanded
\def
\rightpageorder
{
\pagestaterealpageorder
\s!paragraph
\nofraggedparagraphs
}
155 156
\let
\doifrightpageelse\doifelserightpage
157 158
\installcorenamespace
{
pagechanges
}
159 160
\newif
\ifpagechanged
\let
\lastchangedpage
\empty
161 162
\def
\spac_pagechanges_check
#
1
#
2
#
3
%
163
{
\pagechangedfalse
164
\doforcedtrackpagestate
{
#
2
}{
#
3
}
%
165
\edef
\m_spac_pagestates_realpage
{
\pagestaterealpage
{
#
2
}{
\number
#
3
}}
%
166
\ifx
\m_spac_pagestates_realpage
\empty
\else
167
\ifnum
\m_spac_pagestates_realpage
>
0
\csname
\??pagechanges
#
2
:
#
1
\endcsname\relax
168
\pagechangedtrue
169
\fi
170
\fi
171
\ifpagechanged
172
\letgvalue
{
\??pagechanges
#
2
:
#
1
}
\m_spac_pagestates_realpage
173
\glet
\lastchangedpage
\m_spac_pagestates_realpage
174
\else
175
\glet
\lastchangedpage
\realfolio
176
\fi
}
177 178
\def
\changedpagestate
#
1
#
2
%
179
{
\executeifdefined
{
\??pagechanges
#
2
:
#
1
}
0
}
180 181
\def
\checkpagechange
#
1
{
\spac_pagechanges_check
{
#
1
}
\s!paragraph
\nofraggedparagraphs
}
182
\def
\changedpage
#
1
{
\changedpagestate
{
#
1
}
\s!paragraph
}
183 184
\protect
\endinput
185