spac-ali.mkiv /size: 45 Kb    last modification: 2021-10-28 13:50
1
%D \module
2
%D [ file=spac-ali,
3
%D version=2009.10.16, % 1997.03.31, was core-spa.tex
4
%D title=\CONTEXT\ Spacing Macros,
5
%D subtitle=Alignments,
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
/
Alignments
}
15 16
\unprotect
17 18
%D The \type {new} and \type {old} methods are gone as we now have \type
19
%D {flush*} variants. Starting at the last day of 2011 both methods are
20
%D merged into one and caching has been added, which makes switching
21
%D twice as fast.
22 23
% Todo: find a way to force last lines to have some distance from the right
24
% edge (problem: keywords or presets), maybe a plugin
25
%
26
% \setupalign[...,myoption] % last
27
%
28
% but that also means myoption gets frozen due to caching.
29 30
\registerctxluafile
{
spac
-
ali
}
{
optimize
}
31 32
\definesystemattribute
[
realign
]
[
public
]
% might be combined with the next one
33
\definesystemattribute
[
alignstate
]
[
public
]
% will make a single attributes for several states
34 35
\appendtoks
36
\c_attr_realign
\attributeunsetvalue
37
\c_attr_alignstate
\attributeunsetvalue
38
\to
\everyforgetall
39 40
\unexpanded
\def
\resetrealignsignal
{
\c_attr_realign
\attributeunsetvalue
}
41
\unexpanded
\def
\signalinnerrealign
{
\clf_setrealign
\plustwo
}
42
\unexpanded
\def
\signalouterrealign
{
\clf_setrealign
\plusone
}
43 44
\installcorenamespace
{
aligncommand
}
45
\installcorenamespace
{
alignhorizontal
}
46
\installcorenamespace
{
alignvertical
}
47 48
\installcorenamespace
{
alignmentnormalcache
}
49
\installcorenamespace
{
alignmentraggedcache
}
50 51
% nasty hack:
52 53
\installcorenamespace
{
alignmentnormalcacheodd
}
54
\installcorenamespace
{
alignmentnormalcacheeven
}
55 56
\installcorenamespace
{
alignmentraggedcacheodd
}
57
\installcorenamespace
{
alignmentraggedcacheeven
}
58 59
\def
\??alignmentnormalcache
{
\ifodd
\realpageno
\??alignmentnormalcacheodd
\else
\??alignmentnormalcacheeven
\fi
}
60
\def
\??alignmentraggedcache
{
\ifodd
\realpageno
\??alignmentraggedcacheodd
\else
\??alignmentraggedcacheeven
\fi
}
61 62
\newtoks
\everyresetalign
% todo
63 64
% This will become a more advanced layout controller soon:
65 66
\newconditional
\layoutlefttoright
\settrue
\layoutlefttoright
67
\newconditional
\displaylefttoright
\settrue
\displaylefttoright
68
\newconditional
\inlinelefttoright
\settrue
\inlinelefttoright
69 70
\unexpanded
\def
\lefttoright
71
{
\ifvmode
72
\spac_directions_lefttoright_vmode
73
\else
74
\spac_directions_lefttoright_hmode
75
\fi
}
76 77
\unexpanded
\def
\righttoleft
78
{
\ifvmode
79
\spac_directions_righttoleft_vmode
80
\else
81
\spac_directions_righttoleft_hmode
82
\fi
}
83 84
\unexpanded
\def
\spac_directions_lefttoright_vmode
85
{
\settrue
\displaylefttoright
86
\settrue
\inlinelefttoright
87
\textdirection
\directionlefttoright
88
\pardirection
\directionlefttoright
}
89 90
\unexpanded
\def
\spac_directions_righttoleft_vmode
91
{
\setfalse
\displaylefttoright
92
\setfalse
\inlinelefttoright
93
\textdirection
\directionrighttoleft
94
\pardirection
\directionrighttoleft
}
95 96
\unexpanded
\def
\spac_directions_lefttoright_hmode
97
{
\linedirection
\directionlefttoright
% linedir keeps subtype of skip
98
\settrue
\inlinelefttoright
}
99 100
\unexpanded
\def
\spac_directions_righttoleft_hmode
101
{
\linedirection
\directionrighttoleft
% linedir keeps subtype of skip
102
\setfalse
\inlinelefttoright
}
103 104
\unexpanded
\def
\synchronizelayoutdirection
105
{
\ifconditional
\layoutlefttoright
106
\spac_directions_synchronize_lr
107
\else
108
\spac_directions_synchronize_rl
109
\fi
}
110 111
\unexpanded
\def
\synchronizedisplaydirection
112
{
\ifconditional
\displaylefttoright
113
\spac_directions_synchronize_lr
114
\else
115
\spac_directions_synchronize_rl
116
\fi
}
117 118
\def
\spac_directions_synchronize_lr
119
{
\settrue
\inlinelefttoright
120
\textdirection
\directionlefttoright
121
\pardirection
\directionlefttoright
}
122 123
\def
\spac_directions_synchronize_rl
124
{
\setfalse
\inlinelefttoright
125
\textdirection
\directionrighttoleft
126
\pardirection
\directionrighttoleft
}
127 128
\unexpanded
\def
\synchronizeinlinedirection
129
{
% why not \linedirection here
130
\textdirection
\ifconditional
\inlinelefttoright
\directionlefttoright
\else
\directionrighttoleft
\fi
}
131 132
\unexpanded
\def
\checkedlefttoright
133
{
\ifvmode
134
\spac_directions_lefttoright_vmode
135
\else
136
\spac_directions_lefttoright_hmode_checked
137
\fi
}
138 139
\unexpanded
\def
\checkedrighttoleft
140
{
\ifvmode
141
\spac_directions_righttoleft_vmode
142
\else
143
\spac_directions_righttoleft_hmode_checked
144
\fi
}
145 146
\unexpanded
\def
\spac_directions_lefttoright_hmode_checked
147
{
\ifconditional
\inlinelefttoright
\else
148
\lefttoright
149
\fi
}
150 151
\unexpanded
\def
\spac_directions_righttoleft_hmode_checked
152
{
\ifconditional
\inlinelefttoright
153
\righttoleft
154
\fi
}
155 156
\installcorenamespace
{
bidi
}
157 158
\letvalue
{
\??bidi
\v!left
}
\checkedlefttoright
\letvalue
{
\??bidi
l
2
r
}
\checkedlefttoright
159
\letvalue
{
\??bidi
\v!right
}
\checkedrighttoleft
\letvalue
{
\??bidi
r
2
l
}
\checkedrighttoleft
160 161
\unexpanded
\def
\usebidiparameter
#
1
%
162
{
\begincsname
\??bidi
#
1
\c!bidi
\endcsname
}
163 164
\unexpanded
\def
\showdirections
165
{
\dontleavehmode
166
\begingroup
\infofont
\textdirection
\directionlefttoright
[
\space
167
layout
:
\ifconditional
\layoutlefttoright
l
2
r
\else
r
2
l
\fi
\space
168
display
:
\ifconditional
\displaylefttoright
l
2
r
\else
r
2
l
\fi
\space
169
inline
:
\ifconditional
\inlinelefttoright
l
2
r
\else
r
2
l
\fi
\space
170
]
\endgroup
}
171 172
\unexpanded
\def
\righttolefthbox
#
1
#
{
\reversehbox
#
1
\bgroup
\righttoleft
\let
\next
}
\let
\rtlhbox
\righttolefthbox
173
\unexpanded
\def
\lefttorighthbox
#
1
#
{
\naturalhbox
#
1
\bgroup
\lefttoright
\let
\next
}
\let
\ltrhbox
\lefttorighthbox
174
\unexpanded
\def
\righttoleftvbox
#
1
#
{
\reversevbox
#
1
\bgroup
\righttoleft
\let
\next
}
\let
\rtlvbox
\righttoleftvbox
175
\unexpanded
\def
\lefttorightvbox
#
1
#
{
\naturalvbox
#
1
\bgroup
\lefttoright
\let
\next
}
\let
\ltrvbox
\lefttorightvbox
176
\unexpanded
\def
\righttoleftvtop
#
1
#
{
\reversevtop
#
1
\bgroup
\righttoleft
\let
\next
}
\let
\rtlvtop
\righttoleftvtop
177
\unexpanded
\def
\lefttorightvtop
#
1
#
{
\naturalvtop
#
1
\bgroup
\lefttoright
\let
\next
}
\let
\ltrvtop
\lefttorightvtop
178 179
\unexpanded
\def
\autodirhbox
#
1
#
{
\hbox
#
1
\bgroup
\synchronizeinlinedirection
\let
\next
}
180
\unexpanded
\def
\autodirvbox
#
1
#
{
\vbox
#
1
\bgroup
\synchronizeinlinedirection
\let
\next
}
% maybe also pardir or maybe just a \vbox
181
\unexpanded
\def
\autodirvtop
#
1
#
{
\vtop
#
1
\bgroup
\synchronizeinlinedirection
\let
\next
}
% maybe also pardir or maybe just a \vtop
182 183
\unexpanded
\def
\leftorrighthbox
{
\ifconditional
\displaylefttoright
\expandafter
\lefttorighthbox
\else
\expandafter
\righttolefthbox
\fi
}
184
\unexpanded
\def
\leftorrightvbox
{
\ifconditional
\displaylefttoright
\expandafter
\lefttorightvbox
\else
\expandafter
\righttoleftvbox
\fi
}
185
\unexpanded
\def
\leftorrightvtop
{
\ifconditional
\displaylefttoright
\expandafter
\lefttorightvtop
\else
\expandafter
\righttoleftvtop
\fi
}
186 187
% Tolerance and hyphenation
188 189
\ifdefined
\lesshyphens
\else
\let
\lesshyphens
\relax
\fi
190
\ifdefined
\morehyphens
\else
\let
\morehyphens
\relax
\fi
191
\ifdefined
\nohyphens
\else
\let
\nohyphens
\relax
\fi
192
\ifdefined
\dohyphens
\else
\let
\dohyphens
\relax
\fi
193 194
\newconstant
\c_spac_tolerance_default
\c_spac_tolerance_default
1
5
0
0
% shouldn't that be 200
195
\newconstant
\c_spac_tolerance_minimum
\c_spac_tolerance_minimum
1
5
0
0
196
\newconstant
\c_spac_tolerance_normal
\c_spac_tolerance_normal
3
0
0
0
197
\newconstant
\c_spac_tolerance_extreme
\c_spac_tolerance_extreme
4
5
0
0
198 199
\def
\spac_align_set_raggedness_left
{
\plustwo
\bodyfontsize
}
200
\def
\spac_align_set_raggedness_right
{
\plustwo
\bodyfontsize
}
201
\def
\spac_align_set_raggedness_middle
{
\plussix
\bodyfontsize
}
% overloaded below
202 203
% oeps, hsize can be 0pt in which case we get a strange division
204
% was: 6\bodyfontsize, fails on: \placefigure{x $x=x$ x}{}
205 206
\def
\spac_align_set_raggedness_middle
{
\ifzeropt
\hsize
\plussix
\bodyfontsize
\else
.
5
\hsize
\fi
}
207 208
\unexpanded
\def
\setraggedness
#
1
% tricky .. we keep the global tolerance otherwise ... to be reconsidered
209
{
\ifnum
\tolerance
<
\c_spac_tolerance_minimum
210
\tolerance
\c_spac_tolerance_minimum
% small values have unwanted side effects
211
\else
212
% todo: take set value or none .. better done elsewhere (200 is normal)
213
\fi
214
\ifx
\dohyphens
\relax
% was 2.5 in old implementation using scratch registers
215
\hyphenpenalty
\dimexpr
2
.
8
\hsize
/
\dimexpr
#
1
\relax
\relax
% 50 in raggedright/raggedleft
216
%\else
217
% no need to do something as we're in \nohyphens
218
\fi
}
219 220
\unexpanded
\def
\spac_align_set_tolerant
221
{
\tolerance
\c_spac_tolerance_normal
}
222 223
\unexpanded
\def
\spac_align_set_very_tolerant
224
{
\tolerance
\c_spac_tolerance_extreme
}
225 226
\unexpanded
\def
\spac_align_set_stretch
227
{
\emergencystretch
\bodyfontsize
}
228 229
\unexpanded
\def
\spac_align_set_extreme_stretch
230
{
\emergencystretch
1
0
\bodyfontsize
}
231 232
% Vertical
233 234
\newconstant
\c_spac_align_state_vertical
235 236
\unexpanded
\def
\spac_align_set_vertical_none
237
{
\let
\raggedtopcommand
\relax
238
\let
\raggedbottomcommand
\relax
}
239 240
\unexpanded
\def
\spac_align_set_vertical_lohi
241
{
\let
\raggedtopcommand
\vfilll
242
\let
\raggedbottomcommand
\vfilll
}
243 244
\unexpanded
\def
\spac_align_set_vertical_low
245
{
\let
\raggedtopcommand
\vfilll
246
\let
\raggedbottomcommand
\relax
}
247 248
\unexpanded
\def
\spac_align_set_vertical_high
249
{
\let
\raggedtopcommand
\relax
250
\let
\raggedbottomcommand
\vfilll
}
251 252
\def
\spac_align_flush_vertical
253
{
\ifcase
\c_spac_align_state_vertical
254
\spac_align_set_vertical_none
255
\or
256
\spac_align_set_vertical_lohi
257
\or
258
\spac_align_set_vertical_low
259
\or
260
\spac_align_set_vertical_high
261
\fi
}
262 263
% Horizontal
264 265
\ifdefined
\raggedonelinerstate
\else
266
\newconditional
\raggedonelinerstate
% public
267
\fi
268 269
% \appendtoks
270
% \setfalse\raggedonelinerstate
271
% \to \everyforgetall
272 273
\newconstant
\raggedstatus
% public
274 275
\newconstant
\c_spac_align_state_horizontal
276
\newconstant
\c_spac_align_state_broad
277
\newconstant
\c_spac_align_state_par_fill
278 279
\def
\v_spac_align_fill_amount
{
\plusone
fil
}
280
\def
\v_spac_align_fill_amount_hard
{
\plusone
fill
}
281
\def
\v_spac_align_fill_amount_extreme
{
\plustenthousand
filll
}
282
\def
\v_spac_align_fill_amount_negative
{
\minusone
fil
}
283
\def
\v_spac_align_fill_amount_double
{
\plustwo
fil
}
284
\def
\v_spac_align_fill_amount_space
{
\plustwo
fil
}
% can be added to xspace if we have a key
285
\def
\v_spac_align_fill_amount_half
{
.
5
fil
}
286
\let
\v_spac_align_space_amount
\interwordspace
287
\def
\v_spac_align_space_amount_x
{
.
5
\emwidth
}
288 289
\newskip
\s_zero_plus_one_fil
\s_zero_plus_one_fil
=
0
pt
plus
1
fil
290
\newskip
\s_zero_plus_zero
\s_zero_plus_zero
=
0
pt
plus
0
pt
291 292
% \s!plus ... slower than inline
293 294
\unexpanded
\def
\spac_align_set_horizontal_none
% should also relax \updateraggedskips
295
{
\raggedstatus
\zerocount
296
\c_attr_alignstate
\attributeunsetvalue
297
\leftskip
\plusone
\leftskip
298
\rightskip
\plusone
\rightskip
299
\spaceskip
\zeropoint
300
\xspaceskip
\zeropoint
301
\parfillskip
\s_zero_plus_one_fil
% new
302
\setfalse
\raggedonelinerstate
% now here
303
\let
\updateraggedskips
\relax
}
% no need for adaption
304 305
\unexpanded
\def
\spac_align_set_horizontal_left
306
{
\setraggedness
\spac_align_set_raggedness_left
307
\raggedstatus
\plusone
308
\c_attr_alignstate
\plusone
309
\leftskip
\plusone
\leftskip
\s!plus
\spac_align_set_raggedness_left
310
\rightskip
\plusone
\rightskip
\s!plus
\zeropoint
311
\spaceskip
\v_spac_align_space_amount
312
\xspaceskip
\v_spac_align_space_amount_x
313
\parfillskip
\s_zero_plus_zero
314
\parindent
\zeropoint
315
\relax
}
316 317
\unexpanded
\def
\spac_align_set_horizontal_center
318
{
\setraggedness
\spac_align_set_raggedness_middle
319
\raggedstatus
\plustwo
320
\c_attr_alignstate
\plustwo
321
\leftskip
\plusone
\leftskip
\s!plus
\spac_align_set_raggedness_middle
322
\rightskip
\plusone
\rightskip
\s!plus
\spac_align_set_raggedness_middle
323
\spaceskip
\v_spac_align_space_amount
324
\xspaceskip
\v_spac_align_space_amount_x
325
\parfillskip
\s_zero_plus_zero
326
\parindent
\zeropoint
327
\relax
}
328 329
\unexpanded
\def
\spac_align_set_horizontal_right
330
{
\setraggedness
\spac_align_set_raggedness_right
331
\raggedstatus
\plusthree
332
\c_attr_alignstate
\plusthree
333
\leftskip
\plusone
\leftskip
\s!plus
\zeropoint
334
\rightskip
\plusone
\rightskip
\s!plus
\spac_align_set_raggedness_right
335
\spaceskip
\v_spac_align_space_amount
336
\xspaceskip
\v_spac_align_space_amount_x
337
\parfillskip
\s_zero_plus_one_fil
338
%\parindent \parindent
339
\relax
}
340 341
\unexpanded
\def
\spac_align_set_horizontal_very_left
342
{
\raggedstatus
\plusone
343
\c_attr_alignstate
\plusone
344
\leftskip
\plusone
\leftskip
\s!plus
\v_spac_align_fill_amount
345
\rightskip
\plusone
\rightskip
\s!plus
\zeropoint
346
\spaceskip
\v_spac_align_space_amount
347
\xspaceskip
\v_spac_align_space_amount_x
348
\parfillskip
\s_zero_plus_zero
349
\parindent
\zeropoint
350
\relax
}
351 352
\unexpanded
\def
\spac_align_set_horizontal_very_center
353
{
\raggedstatus
\plustwo
354
\c_attr_alignstate
\plustwo
355
\leftskip
\plusone
\leftskip
\s!plus
\v_spac_align_fill_amount
356
\rightskip
\plusone
\rightskip
\s!plus
\v_spac_align_fill_amount
357
\spaceskip
\v_spac_align_space_amount
358
\xspaceskip
\v_spac_align_space_amount_x
359
\parfillskip
\s_zero_plus_zero
360
\parindent
\zeropoint
361
\relax
}
362 363
\unexpanded
\def
\spac_align_set_horizontal_very_right
364
{
\raggedstatus
\plusthree
365
\c_attr_alignstate
\plusthree
366
\leftskip
\plusone
\leftskip
\s!plus
\zeropoint
367
\rightskip
\plusone
\rightskip
\s!plus
\v_spac_align_fill_amount
368
\spaceskip
\v_spac_align_space_amount
369
\xspaceskip
\v_spac_align_space_amount_x
370
\parfillskip
\s_zero_plus_zero
371
%\parindent \parindent
372
\relax
}
373 374
\unexpanded
\def
\spac_align_set_horizontal_wide_center
375
{
\setraggedness
\spac_align_set_raggedness_middle
376
\raggedstatus
\plustwo
377
\c_attr_alignstate
\plustwo
378
\leftskip
\plusone
\leftskip
\s!plus
\v_spac_align_fill_amount_half
379
\rightskip
\plusone
\rightskip
\s!plus
\v_spac_align_fill_amount_half
380
\spaceskip
\v_spac_align_space_amount
381
\xspaceskip
\v_spac_align_space_amount_x
382
\parfillskip
\s_zero_plus_zero
383
\parindent
\zeropoint
384
\relax
}
385 386
\unexpanded
\def
\spac_align_set_horizontal_centered_last_line
387
{
\raggedstatus
\zerocount
388
\c_attr_alignstate
\attributeunsetvalue
389
\leftskip
\plusone
\leftskip
\s!plus
\v_spac_align_fill_amount
\relax
390
\rightskip
\plusone
\rightskip
\s!plus
\v_spac_align_fill_amount_negative
\relax
391
\spaceskip
\zeropoint
\relax
392
\xspaceskip
\zeropoint
\relax
393
\parfillskip
\zeropoint
\s!plus
\v_spac_align_fill_amount_double
\relax
394
\parindent
\zeropoint
395
\relax
}
396 397
\unexpanded
\def
\spac_align_set_horizontal_flushedright_last_line
398
{
\raggedstatus
\zerocount
399
\c_attr_alignstate
\attributeunsetvalue
400
\leftskip
\plusone
\leftskip
\s!plus
\v_spac_align_fill_amount
\relax
401
\rightskip
\plusone
\rightskip
\s!plus
\v_spac_align_fill_amount_negative
\relax
402
\spaceskip
\zeropoint
\relax
403
\xspaceskip
\zeropoint
\relax
404
\parfillskip
\zeropoint
405
\parfillleftskip
\zeropoint
\s!plus
\v_spac_align_fill_amount_extreme
\relax
406
\parfillleftmode
\plustwo
% \plusone checks for multiple lines
407
\parindent
\zeropoint
408
\relax
}
409 410
\unexpanded
\def
\spac_align_set_horizontal_right_tt
% a plain command
411
{
\tttf
% brrr
412
\raggedstatus
\plusthree
413
\c_attr_alignstate
\plusthree
414
\leftskip
\plusone
\leftskip
\s!plus
\zeropoint
\relax
415
\rightskip
\plusone
\rightskip
\s!plus
\spac_align_set_raggedness_right
\relax
416
\spaceskip
\zeropoint
\relax
417
\xspaceskip
\zeropoint
\relax
418
\parfillskip
\s_zero_plus_zero
419
%\parindent \parindent
420
\relax
}
421 422
\unexpanded
\def
\spac_align_set_horizontal_extra
423
{
\xspaceskip
\zeropoint
\s!plus
\v_spac_align_fill_amount_space
\relax
}
424 425
\def
\spac_align_flush_horizontal
426
{
\ifcase
\c_spac_align_state_horizontal
427
% 0
428
\spac_align_set_horizontal_none
429
\or
430
% 1 center
431
\ifcase
\c_spac_align_state_broad
432
\spac_align_set_horizontal_center
433
\or
434
\spac_align_set_horizontal_very_center
435
\or
436
\spac_align_set_horizontal_wide_center
437
\fi
438
\or
439
% 2 flush left
440
\ifcase
\c_spac_align_state_broad
441
\spac_align_set_horizontal_right
442
\else
443
\spac_align_set_horizontal_very_right
444
\fi
445
\or
446
% 3 flush right
447
\ifcase
\c_spac_align_state_broad
448
\spac_align_set_horizontal_left
449
\else
450
\spac_align_set_horizontal_very_left
451
\fi
452
\or
453
% 4 inner
454
\ifdoublesided
455
\signalinnerrealign
456
\fi
457
\rightorleftpageaction
\spac_align_set_horizontal_right
\spac_align_set_horizontal_left
458
\or
459
% 5 outer
460
\ifdoublesided
461
\signalouterrealign
462
\fi
463
\rightorleftpageaction
\spac_align_set_horizontal_left
\spac_align_set_horizontal_right
464
\or
465
% 6 oneliner
466
\ifcase
\c_spac_align_state_broad
467
\spac_align_set_horizontal_right
468
\else
469
\spac_align_set_horizontal_very_right
470
\fi
471
\parfillskip
\zeropoint
472
\or
473
% 7 centered last line
474
\spac_align_set_horizontal_centered_last_line
475
\or
476
% 8 right aligned last line
477
\spac_align_set_horizontal_flushedright_last_line
478
\or
479
% 9 paragraph
480
\parfillskip
\zeropoint
481
\fi
482
\relax
}
483 484
% Page spacing:
485 486
\newconstant
\c_spac_align_state_page
487 488
\def
\bottomalignlimit
{
\plusthree
\lineheight
}
489 490
\newconstant
\bottomraggednessmode
% 0=ragged 1=normal/align 2=baseline
491 492
\unexpanded
\def
\raggedbottom
493
{
\bottomraggednessmode
\zerocount
494
\settopskip
}
495 496
\unexpanded
\def
\alignbottom
497
{
\bottomraggednessmode
\plusone
498
\settopskip
}
499 500
\unexpanded
\def
\baselinebottom
501
{
\bottomraggednessmode
\plustwo
502
\settopskip
}
503 504
\let
\normalbottom
\alignbottom
% downward compatible
505 506
\unexpanded
\def
\setbottomalignmode
#
1
%
507
{
\bottomraggednessmode
#
1
%
508
\settopskip
}
509 510
\def
\spac_align_flush_page
511
{
\ifcase
\c_spac_align_state_page
512
% keep state
513
\or
514
\raggedbottom
515
\or
516
\alignbottom
517
\or
518
\baselinebottom
519
\fi
}
520 521
% Directions
522 523
\newconstant
\c_spac_align_state_direction
524 525
\def
\spac_align_flush_direction
526
{
\ifcase
\c_spac_align_state_direction
527
% keep state
528
\or
529
\lefttoright
530
\or
531
\righttoleft
532
\fi
}
533 534
% Interesting is that the non cached version is also pretty efficient
535
% and as we cache we seldom call that one now so one can debate the
536
% speedup.
537 538
\newtoks
\t_spac_align_collected
539 540
\let
\raggedcommand
\relax
541
\let
\updateraggedskips
\relax
542 543
\def
\spac_align_add_to_cache
544
{
\let
\raggedbox
\relax
% why
545
% we inherit hyphenation and tolerance
546
\t_spac_align_collected
\emptytoks
547
\c_spac_align_state_broad
\zerocount
548
\c_spac_align_state_horizontal
\zerocount
549
\c_spac_align_state_vertical
\zerocount
550
\c_spac_align_state_direction
\zerocount
% what is default ?
551
\c_spac_align_state_page
\zerocount
552
\c_spac_align_state_par_fill
\zerocount
553
\ifcsname
\??aligncommand
\m_spac_align_asked
\endcsname
554
\lastnamedcs
555
\else
556
\rawprocesscommacommand
[
\m_spac_align_asked
]
\spac_align_collect
557
\fi
558
\normalexpanded
{
\t_spac_align_collected
559
{
% \resetrealignsignal % can go as it is always set
560
\setfalse
\raggedonelinerstate
% bad
561
\the
\t_spac_align_collected
562
\spac_align_flush_horizontal
563
\spac_align_flush_vertical
564
\spac_align_flush_direction
565
\spac_align_flush_page
566
\spac_align_flush_parfill
567
}
}
% kept, nice for tracing
568
\edef
\raggedcommand
{
\the
\t_spac_align_collected
}
%
569
\edef
\updateraggedskips
{
\spac_align_flush_horizontal
}
%
570
\expandafter
\glet
\csname
\??alignmentnormalcache
\m_spac_align_asked
\endcsname
\raggedcommand
571
\expandafter
\glet
\csname
\??alignmentraggedcache
\m_spac_align_asked
\endcsname
\updateraggedskips
}
572 573
\def
\spac_align_collect
#
1
%
574
{
\csname
\??aligncommand
#
1
\endcsname
}
575 576
% The local (key driven) setter:
577 578
\unexpanded
\def
\spac_align_prepare
#
1
% deferred
579
{
\edef
\m_spac_align_asked
{
#
1
}
%
580
\expandafter
\let
\expandafter
\raggedcommand
\csname
\??alignmentnormalcache
\m_spac_align_asked
\endcsname
581
\ifx
\raggedcommand
\relax
582
\spac_align_add_to_cache
583
\else
584
\expandafter
\let
\expandafter
\updateraggedskips
\csname
\??alignmentraggedcache
\m_spac_align_asked
\endcsname
585
\fi
}
586 587
\let
\dosetraggedcommand
\spac_align_prepare
% sort of public
588 589
% The regular align setter:
590 591
\unexpanded
\def
\setupalign
592
{
\dosingleempty
\spac_align_setup
}
593 594
\def
\spac_align_setup
[
#
1
]
% immediate
595
{
\edef
\m_spac_align_asked
{
#
1
}
%
596
\expandafter
\let
\expandafter
\raggedcommand
\csname
\??alignmentnormalcache
\m_spac_align_asked
\endcsname
597
\ifx
\raggedcommand
\relax
598
\spac_align_add_to_cache
599
\else
600
\expandafter
\let
\expandafter
\updateraggedskips
\csname
\??alignmentraggedcache
\m_spac_align_asked
\endcsname
601
\fi
602
\raggedcommand
}
603 604
\unexpanded
\def
\usealignparameter
#
1
% faster local variant
605
{
\edef
\m_spac_align_asked
{
#
1
\c!align
}
%
606
\ifx
\m_spac_align_asked
\empty
\else
607
\spac_align_use_indeed
608
\fi
}
609 610
\unexpanded
\def
\dousealignparameter
#
1
% faster local variant
611
{
\edef
\m_spac_align_asked
{
#
1
}
%
612
\ifx
\m_spac_align_asked
\empty
\else
613
\spac_align_use_indeed
614
\fi
}
615 616
\def
\spac_align_use_indeed
617
{
\expandafter
\let
\expandafter
\raggedcommand
\csname
\??alignmentnormalcache
\m_spac_align_asked
\endcsname
618
\ifx
\raggedcommand
\relax
619
\spac_align_add_to_cache
620
\else
621
\expandafter
\let
\expandafter
\updateraggedskips
\csname
\??alignmentraggedcache
\m_spac_align_asked
\endcsname
622
\fi
623
\raggedcommand
}
624 625
% experiment
626 627
\unexpanded
\def
\spac_align_use_later
#
1
%
628
{
\begingroup
629
\edef
\m_spac_align_asked
{
#
1
}
%
630
\expandafter
\let
\expandafter
\raggedcommand
\csname
\??alignmentnormalcache
\m_spac_align_asked
\endcsname
631
\ifx
\raggedcommand
\relax
632
\spac_align_add_to_cache
633
\fi
634
\endgroup
}
635 636
\unexpanded
\def
\spac_align_use_now
#
1
%
637
{
\csname
\??alignmentnormalcache
#
1
\endcsname
}
638 639
% Maybe we need something different in columns.
640 641
\unexpanded
\def
\installalign
#
1
#
2
% beware: commands must be unexpandable!
642
{
\ifcsname
\??aligncommand
#
1
\endcsname
\else
643
\setvalue
{
\??aligncommand
#
1
}
{
\toksapp
\t_spac_align_collected
{
#
2
}
}
%
644
\fi
}
645 646
% beware, toks stuff and states are set at a differt time, so installalign is
647
% only for special options
648
%
649
% \setvalue{\??aligncommand whatever}%
650
% {\c_spac_align_state_horizontal\plushundred
651
% \toksapp\t_spac_align_collected{.....}}
652
%
653
% this one could deal with both
654
%
655
% \unexpanded\def\installalignoption#1#2%
656
% {\ifcsname\??aligncommand#1\endcsname \else
657
% \setvalue{\??aligncommand#1}%
658
% {\spac_align_set_horizontal_none
659
% \c_spac_align_state_horizontal\plushundred % don't set
660
% \toksapp\t_spac_align_collected{#2}}%
661
% \fi}
662
%
663
% \installalignoption
664
% {whatever}
665
% {}
666 667
% The keywords:
668 669
\letvalue
{
\??aligncommand
\empty
}
\empty
670
\setvalue
{
\??aligncommand
\v!broad
}
{
\c_spac_align_state_broad
\plusone
}
671
\setvalue
{
\??aligncommand
\v!wide
}
{
\c_spac_align_state_broad
\plustwo
}
672 673
\setvalue
{
\??aligncommand
\v!bottom
}
{
\c_spac_align_state_page
\plusone
}
674
\setvalue
{
\??aligncommand
\v!height
}
{
\c_spac_align_state_page
\plustwo
}
675
\setvalue
{
\??aligncommand
\v!line
}
{
\c_spac_align_state_page
\plusthree
676
% this will become another keyword (undocumented anyway)
677
\toksapp
\t_spac_align_collected
{
\settrue
\raggedonelinerstate
}
}
678 679
\setvalue
{
\??aligncommand
\v!high
}
{
\c_spac_align_state_vertical
\plusthree
}
680
\setvalue
{
\??aligncommand
\v!low
}
{
\c_spac_align_state_vertical
\plustwo
}
681
\setvalue
{
\??aligncommand
\v!lohi
}
{
\c_spac_align_state_vertical
\plusone
}
682 683
\setvalue
{
\??aligncommand
\v!flushright
}
{
\c_spac_align_state_horizontal
\plusthree
}
684
\setvalue
{
\??aligncommand
\v!flushleft
}
{
\c_spac_align_state_horizontal
\plustwo
}
685
\setvalue
{
\??aligncommand
\v!middle
}
{
\c_spac_align_state_horizontal
\plusone
}
686
\setvalue
{
\??aligncommand
\v!no
}
{
\c_spac_align_state_horizontal
\plustwo
}
687
\setvalue
{
\??aligncommand
\v!yes
}
{
\c_spac_align_state_horizontal
\zerocount
}
688
\setvalue
{
\??aligncommand
\v!width
}
{
\c_spac_align_state_horizontal
\zerocount
}
689
\setvalue
{
\??aligncommand
\v!normal
}
{
\c_spac_align_state_horizontal
\zerocount
}
690
\setvalue
{
\??aligncommand
\v!reset
}
{
\c_spac_align_state_page
\zerocount
691
\c_spac_align_state_horizontal
\zerocount
}
692
\setvalue
{
\??aligncommand
\v!inner
}
{
\c_spac_align_state_horizontal
\plusfour
}
693
\setvalue
{
\??aligncommand
\v!outer
}
{
\c_spac_align_state_horizontal
\plusfive
}
694
\setvalue
{
\??aligncommand
\v!flushinner
}
{
\c_spac_align_state_horizontal
\plusfour
}
695
\setvalue
{
\??aligncommand
\v!flushouter
}
{
\c_spac_align_state_horizontal
\plusfive
}
696
\setvalue
{
\??aligncommand
\v!right
}
{
\c_spac_align_state_horizontal
\plustwo
}
697
\setvalue
{
\??aligncommand
\v!left
}
{
\c_spac_align_state_horizontal
\plusthree
}
698
\setvalue
{
\??aligncommand
\v!center
}
{
\c_spac_align_state_horizontal
\plusone
699
\c_spac_align_state_broad
\plustwo
}
700
\setvalue
{
\??aligncommand
\v!disable
}
{
\c_spac_align_state_horizontal
\plussix
}
701
\setvalue
{
\??aligncommand
\v!last
}
{
\c_spac_align_state_horizontal
\plusseven
}
702
\setvalue
{
\??aligncommand
\v!end
}
{
\c_spac_align_state_horizontal
\pluseight
}
703
\setvalue
{
\??aligncommand
\v!paragraph
}
{
\c_spac_align_state_horizontal
\plusnine
}
704 705
\setvalue
{
\??aligncommand
\v!lefttoright
}
{
\c_spac_align_state_direction
\plusone
}
706
\setvalue
{
\??aligncommand
\v!righttoleft
}
{
\c_spac_align_state_direction
\plustwo
}
707
\setvalue
{
\??aligncommand
l
2
r
}
{
\c_spac_align_state_direction
\plusone
}
708
\setvalue
{
\??aligncommand
r
2
l
}
{
\c_spac_align_state_direction
\plustwo
}
709 710
\setvalue
{
\??aligncommand
\v!table
}
{
\c_spac_align_state_vertical
\plusthree
711
\c_spac_align_state_broad
\plusone
712
\c_spac_align_state_horizontal
\plustwo
}
713 714
\setvalue
{
\??aligncommand
\v!lesshyphenation
}
{
\toksapp
\t_spac_align_collected
{
\lesshyphens
}
}
715
\setvalue
{
\??aligncommand
\v!morehyphenation
}
{
\toksapp
\t_spac_align_collected
{
\morehyphens
}
}
716 717
\setvalue
{
\??aligncommand
\v!hanging
}
{
\toksapp
\t_spac_align_collected
{
\font_protruding_enable
}
}
718
\setvalue
{
\??aligncommand
\v!hangingboth
}
{
\toksapp
\t_spac_align_collected
{
\font_protruding_enable_b
}
}
719
\setvalue
{
\??aligncommand
\v!nothanging
}
{
\toksapp
\t_spac_align_collected
{
\font_protruding_disable
}
}
720
\setvalue
{
\??aligncommand
\v!hz
}
{
\toksapp
\t_spac_align_collected
{
\font_expansion_enable
}
}
721
\setvalue
{
\??aligncommand
\v!fullhz
}
{
\toksapp
\t_spac_align_collected
{
\font_expansion_enable_k
}
}
722
\setvalue
{
\??aligncommand
\v!nohz
}
{
\toksapp
\t_spac_align_collected
{
\font_expansion_disable
}
}
723
%setvalue{\??aligncommand\v!spacing }{\toksapp\t_spac_align_collected{\normalspacing\zerocount}} % not yet
724
%setvalue{\??aligncommand\v!nospacing }{\toksapp\t_spac_align_collected{\normalspacing\plusone}} % not yet
725
\setvalue
{
\??aligncommand
\v!hyphenated
}
{
\toksapp
\t_spac_align_collected
{
\dohyphens
}
}
726
\setvalue
{
\??aligncommand
\v!nothyphenated
}
{
\toksapp
\t_spac_align_collected
{
\nohyphens
}
}
727 728
\setvalue
{
\??aligncommand
\v!tolerant
}
{
\toksapp
\t_spac_align_collected
{
\spac_align_set_tolerant
}
}
729
\setvalue
{
\??aligncommand
\v!verytolerant
}
{
\toksapp
\t_spac_align_collected
{
\spac_align_set_very_tolerant
}
}
730
\setvalue
{
\??aligncommand
\v!stretch
}
{
\toksapp
\t_spac_align_collected
{
\spac_align_set_stretch
}
}
731
\setvalue
{
\??aligncommand
\v!extremestretch
}
{
\toksapp
\t_spac_align_collected
{
\spac_align_set_extreme_stretch
}
}
732 733
\setvalue
{
\??aligncommand
\v!final
}
{
\c_spac_align_state_par_fill
\plusone
}
734
\setvalue
{
\??aligncommand
1
*
\v!final
}
{
\c_spac_align_state_par_fill
\plusone
}
735
\setvalue
{
\??aligncommand
2
*
\v!final
}
{
\c_spac_align_state_par_fill
\plustwo
}
% hardcoded multiplier
736
\setvalue
{
\??aligncommand
3
*
\v!final
}
{
\c_spac_align_state_par_fill
\plusthree
}
737
\setvalue
{
\??aligncommand
4
*
\v!final
}
{
\c_spac_align_state_par_fill
\plusfour
}
738 739
% a one shot (only usefull in e.g. framed, also needs tolerance and stretch)
740 741
\setvalue
{
\??aligncommand
\v!more
}
{
\toksapp
\t_spac_align_collected
{
\looseness
\plusone
}
}
742
\setvalue
{
\??aligncommand
1
*
\v!more
}
{
\toksapp
\t_spac_align_collected
{
\looseness
\plusone
}
}
743
\setvalue
{
\??aligncommand
2
*
\v!more
}
{
\toksapp
\t_spac_align_collected
{
\looseness
\plustwo
}
}
744 745
% \setvalue{\??aligncommand ... }{\toksapp\t_spac_align_collected{\nopenalties}}
746
% \setvalue{\??aligncommand ... }{\toksapp\t_spac_align_collected{\setdefaultpenalties}}
747 748
\definehspace
[
\v!final
]
[
\emspaceamount
]
749 750
\def
\spac_align_flush_parfill
751
{
\ifcase
\c_spac_align_state_par_fill
\else
752
\spac_align_flush_parfill_indeed
{
\number
\c_spac_align_state_par_fill
}
%
753
\fi
}
754 755
\unexpanded
\def
\spac_align_flush_parfill_indeed
#
1
%
756
{
\parfillskip
757
#
1
\directhspaceamount
\v!final
758
% plus \dimexpr\availablehsize-#1\directhspaceamount\v!final\relax
759
plus
1
fill
760
\relax
}
761 762
%D For Wolfgang:
763 764
\newtoks
\t_spac_every_swap_align
765 766
\appendtoks
767
\setvalue
{
\??aligncommand
\v!right
}
{
\c_spac_align_state_horizontal
\plusthree
}
%
768
\setvalue
{
\??aligncommand
\v!left
}
{
\c_spac_align_state_horizontal
\plustwo
}
%
769
\to
\t_spac_every_swap_align
770 771
\unexpanded
\def
\enablereversealignment
772
{
\the
\t_spac_every_swap_align
773
\t_spac_every_swap_align
\emptytoks
}
774 775
% Visible commands:
776 777
\let
\notragged
\spac_align_set_horizontal_none
778
\let
\raggedleft
\spac_align_set_horizontal_left
779
\let
\raggedcenter
\spac_align_set_horizontal_center
780
\let
\raggedright
\spac_align_set_horizontal_right
781
\let
\veryraggedleft
\spac_align_set_horizontal_very_left
782
\let
\veryraggedcenter
\spac_align_set_horizontal_very_center
783
\let
\veryraggedright
\spac_align_set_horizontal_very_right
784
\let
\raggedwidecenter
\spac_align_set_horizontal_wide_center
785
\let
\centeredlastline
\spac_align_set_horizontal_centered_last_line
786
\let
\flushedrightlastline
\spac_align_set_horizontal_flushedright_last_line
787
\let
\ttraggedright
\spac_align_set_horizontal_right_tt
% a plain command
788 789
\let
\forgetragged
\spac_align_set_horizontal_none
790 791
\appendtoks
792
\spac_align_set_horizontal_none
793
\to
\everyforgetall
794 795
% Box commands.
796 797
\unexpanded
\def
\ibox
798
{
\vbox
\bgroup
799
\forgetall
800
\let
\\
\endgraf
801
\ifdoublesided
\signalinnerrealign
\fi
802
\doifelserightpage
\spac_align_set_horizontal_right
\spac_align_set_horizontal_left
803
\let
\next
}
804 805
\unexpanded
\def
\obox
806
{
\vbox
\bgroup
807
\forgetall
808
\let
\\
\endgraf
809
\ifdoublesided
\signalouterrealign
\fi
810
\doifelserightpage
\spac_align_set_horizontal_left
\spac_align_set_horizontal_right
811
\let
\next
}
812 813
\let
\raggedbox
\relax
814 815
\def
\dosetraggedvbox
#
1
% can be more keys .. how about caching here (but seldom used)
816
{
\let
\raggedbox
\vbox
817
\processcommacommand
[
#
1
]
\spac_align_set_ragged_vbox
}
818 819
\def
\dosetraggedhbox
#
1
% can be more keys .. how about caching here (but seldom used)
820
{
\let
\raggedbox
\hbox
821
\processcommacommand
[
#
1
]
\spac_align_set_ragged_hbox
}
822 823
\def
\spac_align_set_ragged_vbox
#
1
%
824
{
\ifcsname
\??alignvertical
#
1
\endcsname
825
\lastnamedcs
826
\quitcommalist
827
\fi
}
828 829
\def
\spac_align_set_ragged_hbox
#
1
%
830
{
\ifcsname
\??alignhorizontal
#
1
\endcsname
831
\lastnamedcs
832
\quitcommalist
833
\fi
}
834 835
% \def\usealignparametersethbox#1%
836
% {\edef\p_spac_align{#1\c!align}%
837
% \let\raggedbox\hbox
838
% \ifx\p_spac_align\empty \else
839
% \processcommacommand[\p_spac_align]\spac_align_set_ragged_hbox
840
% \fi}
841
%
842
% \def\usealignparametersetvbox#1%
843
% {\edef\p_spac_align{#1\c!align}%
844
% \let\raggedbox\vbox
845
% \ifx\p_spac_align\empty \else
846
% \processcommacommand[\p_spac_align]\spac_align_set_ragged_vbox
847
% \fi}
848 849
\setvalue
{
\??alignvertical
\v!left
}
{
\let
\raggedbox
\lbox
}
850
\setvalue
{
\??alignvertical
\v!right
}
{
\let
\raggedbox
\rbox
}
851
\setvalue
{
\??alignvertical
\v!middle
}
{
\let
\raggedbox
\cbox
}
852
\setvalue
{
\??alignvertical
\v!inner
}
{
\let
\raggedbox
\ibox
}
853
\setvalue
{
\??alignvertical
\v!outer
}
{
\let
\raggedbox
\obox
}
854
\setvalue
{
\??alignvertical
\v!flushleft
}
{
\let
\raggedbox
\rbox
}
855
\setvalue
{
\??alignvertical
\v!flushright
}
{
\let
\raggedbox
\lbox
}
856
\setvalue
{
\??alignvertical
\v!center
}
{
\let
\raggedbox
\cbox
}
857
\setvalue
{
\??alignvertical
\v!no
}
{
\def
\raggedbox
{
\vbox
\bgroup
\spac_align_set_horizontal_right
\let
\next
=
}
]
}
858 859
% maybe \let's
860 861
\setvalue
{
\??alignhorizontal
\v!left
}
{
\def
\raggedbox
{
\doalignedline
\v!left
}
}
862
\setvalue
{
\??alignhorizontal
\v!right
}
{
\def
\raggedbox
{
\doalignedline
\v!right
}
}
863
\setvalue
{
\??alignhorizontal
\v!middle
}
{
\def
\raggedbox
{
\doalignedline
\v!middle
}
}
864
\setvalue
{
\??alignhorizontal
\v!inner
}
{
\def
\raggedbox
{
\doalignedline
\v!inner
}
}
865
\setvalue
{
\??alignhorizontal
\v!outer
}
{
\def
\raggedbox
{
\doalignedline
\v!outer
}
}
866
\setvalue
{
\??alignhorizontal
\v!flushleft
}
{
\def
\raggedbox
{
\doalignedline
\v!right
}
}
867
\setvalue
{
\??alignhorizontal
\v!flushright
}
{
\def
\raggedbox
{
\doalignedline
\v!left
}
}
868
\setvalue
{
\??alignhorizontal
\v!center
}
{
\def
\raggedbox
{
\doalignedline
\v!middle
}
}
869 870
% The next one can be in use so we keep it around but oen should
871
% be aware of possible interference.
872 873
\unexpanded
\def
\setraggedskips
#
1
#
2
#
3
#
4
#
5
#
6
#
7
% never change this name (todo: inline this one .. less tracingall)
874
{
\unexpanded
\def
\updateraggedskips
{
\dosetraggedskips
{
#
1
}
{
#
2
}
{
#
3
}
{
#
4
}
{
#
5
}
{
#
6
}
{
#
7
}
}
%
875
\updateraggedskips
}
876 877
\def
\dosetraggedskips
#
1
#
2
#
3
#
4
#
5
#
6
#
7
%
878
{
\raggedstatus
#
1
\relax
879
\leftskip
1
\leftskip
\s!plus
#
2
\relax
880
\rightskip
1
\rightskip
\s!plus
#
3
\relax
881
\spaceskip
#
4
\relax
882
\xspaceskip
#
5
\relax
883
\parfillskip
\zeropoint
\s!plus
#
6
\relax
884
\parindent
#
7
\relax
885
\c_attr_alignstate
\ifcase
\raggedstatus
\attributeunsetvalue
\else
\raggedstatus
\fi
}
886 887
% older (context) names:
888 889
\let
\spaceamount
\interwordspace
890
\let
\emspaceamount
\emwidth
891 892
% tracing:
893 894
\def
\spac_show_par_data
#
1
%
895
{
\ifx
#
1
\relax
\else
896
\hbox
{
\string
#
1
:
\the
#
1
}
\endgraf
897
\expandafter
\spac_show_par_data
898
\fi
}
899 900
\unexpanded
\def
\showpardata
901
{
\edef
\thepardata
902
{
\hbox
{
font
:
\fontname
\font
}
\endgraf
903
\spac_show_par_data
904
\interwordspace
\interwordstretch
\interwordshrink
\emwidth
\exheight
\extraspace
905
\hsize
\vsize
906
\leftskip
\rightskip
907
\spaceskip
\xspaceskip
908
\parindent
\parfillskip
909
\hyphenpenalty
\exhyphenpenalty
\automatichyphenpenalty
\explicithyphenpenalty
910
\displaywidowpenalty
\widowpenalty
\clubpenalty
\brokenpenalty
911
\doublehyphendemerits
\finalhyphendemerits
\adjdemerits
912
\relax
}
%
913
\dontleavehmode
914
\begingroup
915
\inleftmargin
{
\vsmash
{
\infofont
\framed
[
\c!align
=
\v!right
]
{
\thepardata
}
}
}
%
916
\endgroup
917
\let
\showpardata
\relax
}
918 919
\unexpanded
\def
\startshowpardata
920
{
\begingroup
921
\showstruts
922
\tracingparagraphs
\maxdimen
923
\appendtoksonce
\showpardata
\to
\everypar
}
924 925
\unexpanded
\def
\stopshowpardata
926
{
\endgraf
927
\endgroup
}
928 929
% Structure:
930 931
\unexpanded
\def
\startalignment
932
{
\par
933
\begingroup
934
\setupalign
}
935 936
\unexpanded
\def
\stopalignment
937
{
\par
938
\endgroup
}
939 940
\setnewconstant
\alignstrutmode
\plusone
941 942
% see later for the real definition, which in the simple case is:
943 944
\newtoks
\everyleftofalignedline
945
\newtoks
\everyrightofalignedline
946 947
\unexpanded
\def
\shiftalignedline
#
1
#
2
#
3
#
4
% left, right, inner, outer
948
{
\rightorleftpageaction
949
{
\everyleftofalignedline
{
\hskip
\dimexpr
#
1
+
#
3
\relax
}
%
950
\everyrightofalignedline
{
\hskip
\dimexpr
#
2
+
#
4
\relax
}
}
951
{
\everyleftofalignedline
{
\hskip
\dimexpr
#
1
+
#
4
\relax
}
%
952
\everyrightofalignedline
{
\hskip
\dimexpr
#
2
+
#
3
\relax
}
}
}
953 954
\def
\doalignline
#
1
#
2
% \\ == newline
955
{
\noindentation
% was \noindent
956
\dontleavehmode
% added in marrakesch at TUG 2006\begingroup
957
\begingroup
958
\setlocalhsize
% new
959
\protected
\def
\\
{
\egroup
\par
\doalignline
{
#
1
}
{
#
2
}
\bgroup
}
%
960
\dowithnextbox
961
{
\hbox
to
\localhsize
962
{
\ifcase
\alignstrutmode
\or
\strut
\fi
963
\the
\everyleftofalignedline
964
#
1
\unhbox
\nextbox
#
2
\relax
965
\the
\everyrightofalignedline
}
%
966
\endgroup
}
967
\hbox
}
968 969
% plain commands
970 971
\ifdefined
\line
\else
\def
\line
{
\hbox
to
\hsize
}
\fi
972
\ifdefined
\leftline
\else
\def
\leftline
#
1
{
\line
{
#
1
\hss
}
}
\fi
973
\ifdefined
\rightline
\else
\def
\rightline
#
1
{
\line
{
\hss
#
1
}
}
\fi
974
\ifdefined
\centerline
\else
\def
\centerline
#
1
{
\line
{
\hss
#
1
\hss
}
}
\fi
975 976
% direct commands
977 978
\installcorenamespace
{
alignwrapper
}
979 980
\setuvalue
{
\??alignwrapper
\v!left
}
{
\doalignline
\relax
\hss
}
981
\setuvalue
{
\??alignwrapper
\v!middle
}
{
\doalignline
\hss
\hss
}
982
\setuvalue
{
\??alignwrapper
\v!right
}
{
\doalignline
\hss
\relax
}
983
\setuvalue
{
\??alignwrapper
\v!max
}
{
\doalignline
\relax
\relax
}
984 985
\def
\spac_align_wrapper_middle
{
\doalignline
\hss
\hss
}
986 987
\def
\spac_align_wrapper_handle
#
1
%
988
%{\csname\??alignwrapper\ifcsname\??alignwrapper#1\endcsname#1\else\v!middle\fi\endcsname}
989
{
\ifcsname
\??alignwrapper
#
1
\endcsname
\expandafter
\lastnamedcs
\else
\expandafter
\spac_align_wrapper_middle
\fi
}
990 991
\unexpanded
\def
\spac_align_wrapper_start
[
#
1
]
%
992
{
\spac_align_wrapper_handle
{
#
1
}
%
993
\bgroup
\ignorespaces
}
994 995
\unexpanded
\def
\spac_align_wrapper_stop
996
{
\removeunwantedspaces
\egroup
}
997 998
\unexpanded
\def
\startlinealignment
999
{
\dosingleempty
\spac_align_wrapper_start
}
1000 1001
\let
\stoplinealignment
\spac_align_wrapper_stop
1002 1003
\unexpanded
\def
\startleftaligned
{
\spac_align_wrapper_start
[
\v!left
]
}
\let
\stopleftaligned
\spac_align_wrapper_stop
1004
\unexpanded
\def
\startmiddlealigned
{
\spac_align_wrapper_start
[
\v!middle
]
}
\let
\stopmiddlealigned
\spac_align_wrapper_stop
1005
\unexpanded
\def
\startrightaligned
{
\spac_align_wrapper_start
[
\v!right
]
}
\let
\stoprightaligned
\spac_align_wrapper_stop
1006
\unexpanded
\def
\startmaxaligned
{
\spac_align_wrapper_start
[
\v!max
]
}
\let
\stopmaxaligned
\spac_align_wrapper_stop
1007 1008
\let
\startmidaligned
\startmiddlealigned
\let
\stopmidaligned
\stopmiddlealigned
1009
\let
\startcenteraligned
\startmiddlealigned
\let
\stopcenteraligned
\stopmiddlealigned
1010 1011
\unexpanded
\def
\leftaligned
{
\spac_align_wrapper_handle
\v!left
}
1012
\unexpanded
\def
\middlealigned
{
\spac_align_wrapper_handle
\v!middle
}
1013
\unexpanded
\def
\rightaligned
{
\spac_align_wrapper_handle
\v!right
}
1014
\unexpanded
\def
\maxaligned
{
\spac_align_wrapper_handle
\v!max
}
1015 1016
\let
\midaligned
\middlealigned
1017
\let
\centeraligned
\middlealigned
1018 1019
\installcorenamespace
{
alignline
}
1020 1021
\letvalue
{
\??alignline
\v!left
}
\leftaligned
1022
\letvalue
{
\??alignline
\v!right
}
\rightaligned
1023
\letvalue
{
\??alignline
\v!middle
}
\midaligned
1024
\letvalue
{
\??alignline
\v!flushleft
}
\rightaligned
% beware, makes no sense in locations / we will have a special locations handler
1025
\letvalue
{
\??alignline
\v!flushright
}
\leftaligned
% beware, makes no sense in locations / we will have a special locations handler
1026
\letvalue
{
\??alignline
\v!center
}
\midaligned
1027
\letvalue
{
\??alignline
\v!max
}
\maxaligned
1028 1029
\def
\doalignedline
#
1
{
\resetrealignsignal
\csname
\??alignline
#
1
\endcsname
}
1030 1031
%D Experimental (will be redone when floats are redone as it's real messy
1032
%D now). It can also be made faster (if needed).
1033 1034
\def
\doxalignline
#
1
#
2
#
3
#
4
#
5
#
6
%
1035
{
\noindentation
% was \noindent
1036
\dontleavehmode
% added in marrakesch at TUG 2006\begingroup
1037
\begingroup
1038
\setlocalhsize
1039
\protected
\def
\\
{
\egroup
\par
\doxalignline
#
1
#
2
#
3
#
4
#
5
#
6
\bgroup
}
% inefficient
1040
\dowithnextbox
1041
{
\hbox
to
\localhsize
1042
{
#
1
\hskip
\ifdone
#
2
\else
#
3
\fi
#
4
%
1043
\hbox
to
\localhsize
1044
{
\the
\everyleftofalignedline
1045
\ifcase
\alignstrutmode
\or
\strut
\fi
1046
\ifdone
#
5
\unhbox
\nextbox
#
6
\else
#
6
\unhbox
\nextbox
#
5
\fi
1047
\the
\everyrightofalignedline
}
%
1048
\hss
}
%
1049
\endgroup
}
1050
\hbox
}
1051 1052
\def
\doxcheckline
% used for floats so multipass anyway
1053
{
\signalrightpage
\doifelserightpage
\donetrue
\donefalse
}
1054 1055
\setvalue
{
\??alignline
\v!inner
}
{
\doxalignline
\doxcheckline
+
+
\zeropoint
\relax
\hss
}
1056
\setvalue
{
\??alignline
\v!outer
}
{
\doxalignline
\doxcheckline
+
+
\zeropoint
\hss
\relax
}
1057
\setvalue
{
\??alignline
\v!innermargin
}
{
\doxalignline
\doxcheckline
-
+
\innermargintotal
\relax
\hss
}
1058
\setvalue
{
\??alignline
\v!outermargin
}
{
\doxalignline
\doxcheckline
+
-
\outermargintotal
\hss
\relax
}
1059
\setvalue
{
\??alignline
\v!inneredge
}
{
\doxalignline
\doxcheckline
-
+
\inneredgetotal
\relax
\hss
}
1060
\setvalue
{
\??alignline
\v!outeredge
}
{
\doxalignline
\doxcheckline
+
-
\outeredgetotal
\hss
\relax
}
1061
\setvalue
{
\??alignline
\v!backspace
}
{
\doxalignline
\doxcheckline
-
+
\backspace
\relax
\hss
}
1062
\setvalue
{
\??alignline
\v!cutspace
}
{
\doxalignline
\doxcheckline
+
-
\cutspace
\hss
\relax
}
1063 1064
\setvalue
{
\??alignline
\v!leftmargin
}
{
\doxalignline
\donefalse
-
-
\leftmargintotal
\hss
\relax
}
1065
\setvalue
{
\??alignline
\v!rightmargin
}
{
\doxalignline
\donefalse
+
+
\rightmargintotal
\relax
\hss
}
1066
\setvalue
{
\??alignline
\v!leftedge
}
{
\doxalignline
\donefalse
-
-
\leftedgetotal
\hss
\relax
}
1067
\setvalue
{
\??alignline
\v!rightedge
}
{
\doxalignline
\donefalse
+
+
\rightedgetotal
\relax
\hss
}
1068 1069
\def
\doalignedline
#
1
% unchecked
1070
{
\csname
\??alignline
#
1
\endcsname
}
% no \resetrealignsignal here ?
1071 1072
\def
\alignedline
#
1
#
2
% setting default
1073
% {\csname\??alignline\ifcsname\??alignline#1\endcsname#1\else#2\fi\endcsname}
1074
{
\ifcsname
\??alignline
#
1
\endcsname
1075
\expandafter
\lastnamedcs
1076
\else
1077
\csname
\??alignline
#
2
\expandafter
\endcsname
1078
\fi
}
1079 1080
% beware: \wordright{whatever\kern-\rightskip} should work!
1081
% so, no funny boxing here
1082 1083
\unexpanded
\def
\wordright
1084
{
\dosingleempty
\spac_word_right
}
1085 1086
\def
\spac_word_right
[
#
1
]
%
1087
{
% don't change
1088
\groupedcommand
1089
{
\removeunwantedspaces
1090
\hfill
1091
\allowbreak
% changed back from \hskip\zeropoint
1092
\strut
1093
\hfill
1094
\quad
% decent spacing
1095
\hbox
}
1096
{
\doifelse
{
#
1
}
\v!right
{
\kern
-
\rightskip
}
{
\doifsomething
{
#
1
}
{
\kern
-
#
1
}
}
%
1097
\parfillskip
\zeropoint
1098
\finalhyphendemerits
\zerocount
% yes or no (see hyhenation/specialcases-001.tex)
1099
\par
}
}
1100 1101
% \dorecurse{5}{something} \wordright{--someone} \endgraf
1102
% \dorecurse{6}{something} \wordright{--someone} \endgraf
1103
% \dorecurse{7}{something} \wordright{--someone} \endgraf
1104
%
1105
% \dorecurse{5}{something} \wordright{--someone else entirely} \endgraf
1106
% \dorecurse{6}{something} \wordright{--someone else entirely} \endgraf
1107
% \dorecurse{7}{something} \wordright{--someone else entirely} \endgraf
1108
%
1109
% \wordright[\rightskip]{whatever}
1110 1111
% Trick posted by WS on mailing list, generalized a bit. The bottom text only shows
1112
% op when there is one line space available. We could add some extra space if needed.
1113 1114
% \unexpanded\def\bottomword
1115
% {\par
1116
% \dowithnextbox
1117
% {\leaders\box\nextbox\vfil\page}
1118
% \vbox to \lineheight}
1119
%
1120
% \unexpanded\def\bottomword
1121
% {\par
1122
% \groupedcommand
1123
% {\leaders
1124
% \vbox to \lineheight\bgroup}
1125
% {\egroup
1126
% \vfil
1127
% \page}}
1128 1129
% \simplealignedbox{2cm}{right}{x}
1130 1131
\installcorenamespace
{
alignsimple
}
1132
\installcorenamespace
{
alignsimplereverse
}
1133 1134
% todo: also handle \bgroup ... \egroup
1135 1136
\unexpanded
\def
\spac_align_simple_left
#
1
{
{
#
1
\hss
}
}
1137
\unexpanded
\def
\spac_align_simple_right
#
1
{
{
\hss
#
1
}
}
1138
\unexpanded
\def
\spac_align_simple_middle
#
1
{
{
\hss
#
1
\hss
}
}
1139 1140
\letvalue
{
\??alignsimple
\v!right
}
\spac_align_simple_left
1141
\letvalue
{
\??alignsimple
\v!outer
}
\spac_align_simple_left
% not managed! see linenumbers
1142
\letvalue
{
\??alignsimple
\v!flushleft
}
\spac_align_simple_left
1143
\letvalue
{
\??alignsimple
\v!left
}
\spac_align_simple_right
1144
\letvalue
{
\??alignsimple
\v!inner
}
\spac_align_simple_right
% not managed! see linenumbers
1145
\letvalue
{
\??alignsimple
\v!flushright
}
\spac_align_simple_right
1146
\letvalue
{
\??alignsimple
\v!middle
}
\spac_align_simple_middle
1147 1148
\letvalue
{
\??alignsimplereverse
\v!right
}
\spac_align_simple_right
1149
\letvalue
{
\??alignsimplereverse
\v!outer
}
\spac_align_simple_right
% not managed! see linenumbers
1150
\letvalue
{
\??alignsimplereverse
\v!flushleft
}
\spac_align_simple_right
1151
\letvalue
{
\??alignsimplereverse
\v!left
}
\spac_align_simple_left
1152
\letvalue
{
\??alignsimplereverse
\v!inner
}
\spac_align_simple_left
% not managed! see linenumbers
1153
\letvalue
{
\??alignsimplereverse
\v!flushright
}
\spac_align_simple_left
1154
\letvalue
{
\??alignsimplereverse
\v!middle
}
\spac_align_simple_middle
1155 1156
\unexpanded
\def
\simplealignedbox
#
1
#
2
%
1157
{
\hbox
\ifdim
#
1
>
\zeropoint
to
#
1
1158
\ifcsname
\??alignsimple
#
2
\endcsname
1159
\doubleexpandafter
\lastnamedcs
1160
\else
1161
\doubleexpandafter
\spac_align_simple_left
1162
\fi
1163
\fi
}
1164 1165
\unexpanded
\def
\simplealignedspreadbox
#
1
#
2
%
1166
{
\hbox
\ifdim
#
1
>
\zeropoint
spread
#
1
1167
\ifcsname
\??alignsimple
#
2
\endcsname
1168
\doubleexpandafter
\lastnamedcs
1169
\else
1170
\doubleexpandafter
\spac_align_simple_left
1171
\fi
1172
\fi
}
1173 1174
\unexpanded
\def
\simplealignedboxplus
#
1
#
2
#
3
%
1175
{
\hbox
#
3
\ifdim
#
1
>
\zeropoint
to
#
1
1176
\ifcsname
\??alignsimple
#
2
\endcsname
1177
\doubleexpandafter
\lastnamedcs
1178
\else
1179
\doubleexpandafter
\spac_align_simple_left
1180
\fi
1181
\fi
}
1182 1183
\newconditional
\alignsimplelefttoright
\settrue
\alignsimplelefttoright
1184 1185
\unexpanded
\def
\simplereversealignedbox
#
1
#
2
%
1186
{
\hbox
\ifdim
#
1
>
\zeropoint
to
#
1
1187
\ifcsname
\??alignsimplereverse
#
2
\endcsname
1188
\doubleexpandafter
\lastnamedcs
1189
\else
1190
\doubleexpandafter
\spac_align_simple_left
1191
\fi
1192
\fi
}
1193 1194
\unexpanded
\def
\simplereversealignedboxplus
#
1
#
2
#
3
%
1195
{
\hbox
#
3
\ifdim
#
1
>
\zeropoint
to
#
1
1196
\ifcsname
\??alignsimplereverse
#
2
\endcsname
1197
\doubleexpandafter
\lastnamedcs
1198
\else
1199
\doubleexpandafter
\spac_align_simple_left
1200
\fi
1201
\fi
}
1202 1203
% \installnamespace{alignsets}
1204
%
1205
% \setvalue{\??alignsets\v!right }#1#2{\let#1\relax\let#2\hss }
1206
% \setvalue{\??alignsets\v!left }#1#2{\let#1\hss \let#2\relax}
1207
% \setvalue{\??alignsets\v!flushright}#1#2{\let#1\hss \let#2\relax}
1208
% \setvalue{\??alignsets\v!flushleft }#1#2{\let#1\relax\let#2\hss }
1209
% \setvalue{\??alignsets\v!middle }#1#2{\let#1\hss \let#2\hss }
1210
% \setvalue{\??alignsets\v!low }#1#2{\let#1\vss \let#2\relax}
1211
% \setvalue{\??alignsets\v!high }#1#2{\let#1\relax\let#2\vss }
1212
% \setvalue{\??alignsets\v!lohi }#1#2{\let#1\vss \let#2\vss }
1213
% \setvalue{\??alignsets\s!unknown }#1#2{\let#1\relax\let#2\relax}
1214
%
1215
% \unexpanded\def\spac_align_set_ss#1%
1216
% {\csname\??alignsetss\ifcsname\??alignsetss#1\endcsname#1\else\s!unknown\fi\endcsname}
1217 1218
% Some obsolete (old) helpers:
1219 1220
\unexpanded
\def
\definehbox
1221
{
\dodoubleargument
\spac_align_definehbox
}
1222 1223
\def
\spac_align_definehbox
[
#
1
]
[
#
2
]
%
1224
{
\setvalue
{
hbox
#
1
}
#
#
1
{
\hbox
to
#
2
{
\begstrut
#
#
1
\endstrut
\hss
}
}
}
1225 1226
%D Some direction related helpers:
1227 1228
\installcorenamespace
{
reverse
}
1229 1230
\setvalue
{
\??reverse
\v!normal
}
{
\ifconditional
\inlinelefttoright
\else
\s!reverse
\fi
}
1231
\setvalue
{
\??reverse
\v!reverse
}
{
\ifconditional
\inlinelefttoright
\s!reverse
\fi
}
1232 1233
\let
\usedirectionparameterreverse
\gobbleoneargument
1234 1235
\protect
\endinput
1236