spac-par.mkiv /size: 8408 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=spac-par,
3
%D version=2009.10.16, % 1997.03.31, was core-spa.tex
4
%D title=\CONTEXT\ Spacing Macros,
5
%D subtitle=Paragraphs,
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
/
Paragraphs
}
15 16
\unprotect
17 18
%D The dreadful sequence \type {\bgroup} \unknown\ \type {\carryoverpar} \unknown\
19
%D \type {\egroup} is needed when for instance sidefloats are used in combination
20
%D with something that starts with a group. This is because otherwise the
21
%D indentation as set (by the output routine) inside the group are forgotten
22
%D afterwards. (I must not forget its existence).
23 24
% Todo (maybe):
25
%
26
% \parshape \getparshape\relax
27
% \interlinepenalties \getinterlinepenalties\relax
28
% \clubpenalties \getclubpenalties\relax
29
% \widowpenalties \getwidowpenalties\relax
30
% \displaywidowpenalties\getdisplaywidowpenalties\relax
31 32
\def
\carryoverpar
#
1
% #1 can be \endgroup or \egroup or ... expandable !
33
{
\normalexpanded
34
{
\noexpand
#
1
%
35
\hangindent\the\hangindent
36
\hangafter
\the\hangafter
37
\parskip
\the\parskip
38
\leftskip
\the\leftskip
39
\rightskip
\the\rightskip
}}
40 41
\unexpanded
\def
\pushparagraphproperties
42
{
\edef
\currentparagraphproperties
{
\carryoverpar
\relax
}
%
43
\pushmacro
\currentparagraphproperties
}
44 45
\unexpanded
\def
\popparagraphproperties
46
{
\popmacro
\currentparagraphproperties
47
\currentparagraphproperties
}
48 49
\unexpanded
\def
\flushparagraphproperties
50
{
\popmacro
\currentparagraphproperties
}
51 52
%D Beware, changing this will break some code (like pos/backgrounds) but it has been
53
%D changed anyway so let's see where things go wrong.
54 55
\installcorenamespace
{
paragraphintro
}
56 57
\let
\insertparagraphintro
\relax
% hook into everypar
58 59
\newtoks
\t_spac_paragraphs_intro_first
60
\newtoks
\t_spac_paragraphs_intro_next
61
\newtoks
\t_spac_paragraphs_intro_each
62 63
\newconditional
\c_spac_paragraphs_intro_first
64
\newconditional
\c_spac_paragraphs_intro_next
65
\newconditional
\c_spac_paragraphs_intro_each
66 67
\unexpanded
\def
\setupparagraphintro
68
{
\dodoubleempty
\spac_paragraphs_intro
}
69 70
\unexpanded
\def
\spac_paragraphs_intro
[#
1
][#
2
]
%
71
{
\def
\spac_paragraphs_intro_step
##
1
%
72
{
\csname
\??paragraphintro
\ifcsname
\??paragraphintro
##
1
\endcsname
##
1
\fi\endcsname
{
#
2
}}
%
73
\processcommacommand
[#
1
]
\spac_paragraphs_intro_step
}
74 75
\letvalue
{
\??paragraphintro
\empty
}
\gobbleoneargument
76 77
\setvalue
{
\??paragraphintro\v!reset
}
#
1
%
78
{
\global
\setfalse
\c_spac_paragraphs_intro_first
79
\global
\setfalse
\c_spac_paragraphs_intro_next
80
\global
\setfalse
\c_spac_paragraphs_intro_each
81
\global
\t_spac_paragraphs_intro_first
\emptytoks
82
\global
\t_spac_paragraphs_intro_next
\emptytoks
83
\global
\t_spac_paragraphs_intro_each
\emptytoks
84
\glet
\insertparagraphintro
\relax
}
85 86
\setvalue
{
\??paragraphintro\v!first
}
#
1
%
87
{
\global
\settrue
\c_spac_paragraphs_intro_first
88
\gtoksapp
\t_spac_paragraphs_intro_first
{
#
1
}
%
89
\glet
\insertparagraphintro
\spac_paragraphs_flush_intro
}
90 91
\setvalue
{
\??paragraphintro\v!next
}
#
1
%
92
{
\global
\settrue
\c_spac_paragraphs_intro_next
93
\gtoksapp
\t_spac_paragraphs_intro_next
{
#
1
}
%
94
\glet
\insertparagraphintro
\spac_paragraphs_flush_intro
}
95 96
\setvalue
{
\??paragraphintro\v!each
}
#
1
%
97
{
\global
\settrue
\c_spac_paragraphs_intro_each
98
\gtoksapp
\t_spac_paragraphs_intro_each
{
#
1
}
%
99
\glet
\insertparagraphintro
\spac_paragraphs_flush_intro
}
100 101
%D We can say:
102
%D
103
%D \starttyping
104
%D \setupparagraphintro[first][\index{Knuth}]
105
%D \stoptyping
106
%D
107
%D Maybe more convenient is:
108
%D
109
%D \starttyping
110
%D \flushatparagraph{\index{Zapf}}
111
%D \stoptyping
112
%D
113
%D \starttyping
114
%D \setupparagraphintro[first][\hbox to 3.5em{\tt FIRST \hss}]
115
%D \setupparagraphintro[first][\hbox to 3.5em{\tt TSRIF \hss}]
116
%D \setupparagraphintro[next] [\hbox to 3.5em{\tt NEXT \hss}]
117
%D \setupparagraphintro[next] [\hbox to 3.5em{\tt TXEN \hss}]
118
%D \setupparagraphintro[each] [\hbox to 3.0em{\tt EACH \hss}]
119
%D \setupparagraphintro[each] [\hbox to 3.0em{\tt HCEA \hss}]
120
%D
121
%D some paragraph \par
122
%D some paragraph \par
123
%D some paragraph \par
124
%D some paragraph \par
125
%D
126
%D \setupparagraphintro[first][\hbox to 3.5em{\tt FIRST \hss}]
127
%D \setupparagraphintro[first][\hbox to 3.5em{\tt TSRIF \hss}]
128
%D
129
%D some paragraph \par
130
%D some paragraph \par
131
%D
132
%D \setupparagraphintro[reset]
133
%D
134
%D some paragraph \par
135
%D \stoptyping
136 137
\unexpanded
\def
\flushatparagraph
#
1
%
138
{
\global
\c_spac_paragraphs_intro_first
\plusone
139
\gtoksapp
\t_spac_paragraphs_intro_first
{
#
1
}
%
140
\glet
\insertparagraphintro
\spac_paragraphs_flush_intro
}
141 142
%D Here comes the flusher (we misuse the one level expansion of token registers to
143
%D feed a nice stream into the paragraph.)
144 145
\unexpanded
\def
\spac_paragraphs_flush_intro
% we make sure that the token lists expand directly
146
{
\normalexpanded
{
% % after another so the first code is there twice
147
\ifconditional
\c_spac_paragraphs_intro_each
148
\ifconditional
\c_spac_paragraphs_intro_next
149
\glet
\insertparagraphintro
\spac_paragraphs_flush_intro_next
150
\else
151
\glet
\insertparagraphintro
\spac_paragraphs_flush_intro_each
152
\fi
153
\ifconditional
\c_spac_paragraphs_intro_first
154
\global
\setfalse
\c_spac_paragraphs_intro_first
155
\global
\t_spac_paragraphs_intro_first
\emptytoks
156
\the
\t_spac_paragraphs_intro_first
157
\fi
158
\the
\t_spac_paragraphs_intro_each
159
\else
160
\ifconditional
\c_spac_paragraphs_intro_next
161
\glet
\insertparagraphintro
\spac_paragraphs_flush_intro_next
162
\fi
163
\ifconditional
\c_spac_paragraphs_intro_first
164
\global
\setfalse
\c_spac_paragraphs_intro_first
165
\global
\t_spac_paragraphs_intro_first
\emptytoks
166
\the
\t_spac_paragraphs_intro_first
167
\fi
168
\fi
}}
169 170
\unexpanded
\def
\spac_paragraphs_flush_intro_next
171
{
\normalexpanded
{
%
172
\global
\setfalse
\c_spac_paragraphs_intro_next
173
\global
\t_spac_paragraphs_intro_next
\emptytoks
174
\ifconditional
\c_spac_paragraphs_intro_each
175
\glet
\insertparagraphintro
\spac_paragraphs_flush_intro_each
176
\the
\t_spac_paragraphs_intro_next
177
\the
\t_spac_paragraphs_intro_each
178
\else
179
\glet
\insertparagraphintro
\relax
180
\the
\t_spac_paragraphs_intro_next
181
\fi
}}
182 183
\unexpanded
\def
\spac_paragraphs_flush_intro_each
184
{
\the
\t_spac_paragraphs_intro_each
}
185 186
%D \macros
187
%D {flushatnextpar}
188
%D
189
%D This macro collects data that will be flushed at the next paragraph. By using
190
%D this macro you can avoid interfering nodes (writes, etc).
191 192
\let
\flushpostponednodedata
\relax
% hook into everypar
193 194
\newbox
\b_spac_postponed_data
195
%newcount\c_spac_postponed_data
196 197
% \installcorenamespace {postponednodesstack}
198
%
199
% \initializeboxstack\??postponednodesstack
200
%
201
% \unexpanded\def\pushpostponednodedata
202
% {\global\advance\c_spac_postponed_data\plusone
203
% \savebox\??postponednodesstack{\the\c_spac_postponed_data}{\box\b_spac_postponed_data}}
204
%
205
% \unexpanded\def\poppostponednodedata
206
% {\global\setbox\b_spac_postponed_data\hbox{\foundbox\??postponednodesstack{\the\c_spac_postponed_data}}%
207
% \global\advance\c_spac_postponed_data\minusone
208
% \ifvoid\b_spac_postponed_data\else
209
% \glet\flushpostponednodedata\spac_postponed_data_flush
210
% \fi}
211 212
\newtoks
\everyflushatnextpar
213 214
\unexpanded
\def
\pushpostponednodedata
215
{
\globalpushbox
\b_spac_postponed_data
}
216 217
\unexpanded
\def
\poppostponednodedata
218
{
\globalpopbox
\b_spac_postponed_data
219
\ifvoid
\b_spac_postponed_data
\else
220
\glet
\flushpostponednodedata
\spac_postponed_data_flush
221
\fi
}
222 223
\unexpanded
\def
\flushatnextpar
224
{
\begingroup
225
\the
\everyflushatnextpar
226
\glet
\flushpostponednodedata
\spac_postponed_data_flush
227
\dowithnextboxcs
\spac_postponed_data_finish
\hpack
}
228 229
\def
\spac_postponed_data_finish
230
{
\global\setbox
\b_spac_postponed_data
\hpack
% to\zeropoint
231
{
\box
\b_spac_postponed_data
\box
\nextbox
}
%
232
\endgroup
}
233 234
\def
\spac_postponed_data_flush
235
{
%\iftrialtypesetting \else
236
\ifvoid
\b_spac_postponed_data
\else
237
\hpack
{
\smashedbox
\b_spac_postponed_data
}
% \box\b_spac_postponed_data
238
\fi
239
\glet
\flushpostponednodedata
\relax
240
}
%\fi}
241 242
\unexpanded
\def
\doflushatpar
% might be renamed
243
{
\ifvmode
244
\expandafter
\flushatnextpar
245
\else
246
\expandafter
\firstofoneargument
247
\fi
}
248 249
\protect
\endinput
250