spac-pag.mkxl /size: 5405 b    last modification: 2023-12-21 09:44
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\newif      \ifpagestatemismatch
19\newconstant\frozenpagestate
20
21\permanent\protected\def\dotrackpagestate#1#2%
22  {\ifdoublesided \ifinpagebody \else
23     \doforcedtrackpagestate{#1}{#2}%
24   \fi \fi}
25
26\permanent\protected\def\doforcedtrackpagestate#1#2%
27  {\ifcase\frozenpagestate
28     \global\advanceby#2\plusone
29     \setpagestate[#1][\number#2]%
30   \fi}
31
32\lettonothing\m_spac_pagestates_realpage
33
34\newconditional\c_spac_pagestates_found
35
36\permanent\protected\def\docheckpagestate#1#2%
37  {\ifcase\frozenpagestate
38     \setpagestaterealpageno{#1}{\number#2}%
39   \fi}
40
41\permanent\protected\def\doifelserightpagestate#1#2% not expandable !
42  {\ifcase\frozenpagestate
43     \pagestatemismatchfalse
44     \realpagestateno\realfolio
45     \ifinpagebody
46       \ifdoublesided
47         \ifodd\realpageno\relax
48           \c_spac_pagestates_found\conditionaltrue
49         \else
50           \c_spac_pagestates_found\conditionalfalse
51         \fi
52       \else
53         \c_spac_pagestates_found\conditionaltrue
54       \fi
55     \orelse\ifdoublesided
56       \edef\m_spac_pagestates_realpage{\pagestaterealpage{#1}{\number#2}}%
57       \ifempty\m_spac_pagestates_realpage
58         \ifodd\realpageno\relax
59           \c_spac_pagestates_found\conditionaltrue
60         \else
61           \c_spac_pagestates_found\conditionalfalse
62         \fi
63       \else
64         \realpagestateno\m_spac_pagestates_realpage\relax
65         \ifnum\realpagestateno=\realpageno \else
66           \pagestatemismatchtrue
67         \fi
68         \ifodd\realpagestateno\relax
69           \c_spac_pagestates_found\conditionaltrue
70         \else
71           \c_spac_pagestates_found\conditionalfalse
72         \fi
73       \fi
74     \else
75       \c_spac_pagestates_found\conditionaltrue
76     \fi
77   \else
78     \ifodd\realpagestateno\relax
79       \c_spac_pagestates_found\conditionaltrue
80     \else
81       \c_spac_pagestates_found\conditionalfalse
82     \fi
83   \fi
84   \ifconditional\c_spac_pagestates_found
85     \expandafter\firstoftwoarguments
86   \else
87     \expandafter\secondoftwoarguments
88   \fi}
89
90\permanent\protected\def\doifelseforcedrightpagestate#1#2%
91  {\ifcase\frozenpagestate
92     \pagestatemismatchfalse
93     \realpagestateno\realfolio
94     \edef\m_spac_pagestates_realpage{\pagestaterealpage{#1}{\number#2}}%
95     \ifempty\m_spac_pagestates_realpage
96       \ifodd\realpageno\relax
97         \c_spac_pagestates_found\conditionaltrue
98       \else
99         \c_spac_pagestates_found\conditionalfalse
100       \fi
101     \else
102       \realpagestateno\m_spac_pagestates_realpage\relax
103       \ifnum\realpagestateno=\realpageno \else
104         \pagestatemismatchtrue
105       \fi
106       \ifodd\realpagestateno\relax
107         \c_spac_pagestates_found\conditionaltrue
108       \else
109         \c_spac_pagestates_found\conditionalfalse
110       \fi
111     \fi
112   \else
113     \ifodd\realpagestateno\relax
114       \c_spac_pagestates_found\conditionaltrue
115     \else
116       \c_spac_pagestates_found\conditionalfalse
117     \fi
118   \fi
119   \ifconditional\c_spac_pagestates_found
120     \expandafter\firstoftwoarguments
121   \else
122     \expandafter\secondoftwoarguments
123   \fi}
124
125\aliased\let\doifrightpagestateelse      \doifelserightpagestate
126\aliased\let\doifforcedrightpagestateelse\doifelseforcedrightpagestate
127
128\permanent\protected\def\freezepagestate {\frozenpagestate\plusone  }
129\permanent\protected\def\defrostpagestate{\frozenpagestate\zerocount}
130
131% we can make more of these on top, but how to deal with mixed frozen states
132
133% \dorecurse{500}{\dontleavehmode\signalrightpage\doifrightpageelse{right}{left}\par} % given doublesided
134
135\newinteger\nofraggedparagraphs
136
137\definepagestate[\s!paragraph]
138
139\permanent\protected\def\signalrightpage  {\dotrackpagestate      \s!paragraph\nofraggedparagraphs} % use \dontleavehmode if needed
140\permanent\protected\def\doifelserightpage{\doifelserightpagestate\s!paragraph\nofraggedparagraphs}
141\permanent\protected\def\rightpageorder   {\pagestaterealpageorder\s!paragraph\nofraggedparagraphs}
142
143\aliased\let\doifrightpageelse\doifelserightpage
144
145\installcorenamespace{pagechanges}
146
147\newif\ifpagechanged \mutable\lettonothing\lastchangedpage
148
149\def\spac_pagechanges_check#1#2#3%
150  {\pagechangedfalse
151   \doforcedtrackpagestate{#2}{#3}%
152   \edef\m_spac_pagestates_realpage{\pagestaterealpage{#2}{\number#3}}%
153   \ifempty\m_spac_pagestates_realpage \orelse\ifnum\m_spac_pagestates_realpage>0\csname\??pagechanges#2:#1\endcsname\relax
154     \pagechangedtrue
155   \fi
156   \ifpagechanged
157     \gletcsname\??pagechanges#2:#1\endcsname\m_spac_pagestates_realpage
158     \glet\lastchangedpage\m_spac_pagestates_realpage
159   \else
160     \glet\lastchangedpage\realfolio
161   \fi}
162
163\permanent\protected\def\changedpagestate#1#2%
164  {\executeifdefined{\??pagechanges#2:#1}0}
165
166\permanent\protected\def\checkpagechange#1{\spac_pagechanges_check{#1}\s!paragraph\nofraggedparagraphs}
167\permanent\protected\def\changedpage    #1{\changedpagestate{#1}\s!paragraph}
168
169\protect \endinput
170