spac-hor.mkiv /size: 41 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=spac-hor,
3
%D version=2009.10.16, % 1997.03.31, was core-spa.tex
4
%D title=\CONTEXT\ Spacing Macros,
5
%D subtitle=Horizontal,
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
/
Horizontal
}
15 16
\unprotect
17 18
\registerctxluafile
{
spac
-
hor
}{}
19 20
\let
\parfillrightskip
\parfillskip
21
\newskip
\parfillleftskip
22
\newconstant
\parfillleftmode
23 24
\let
\v_spac_indentation_current
\empty
% amount/keyword
25 26
\newdimen
\d_spac_indentation_par
27
\parindent
\d_spac_indentation_par
% for the show
28 29
\newconditional
\c_spac_indentation_indent_first
\settrue
\c_spac_indentation_indent_first
30
\newconstant
\c_spac_indentation_toggle_state
31 32
%D After a blank or comparable situation (left side floats) we
33
%D need to check if the next paragraph has to be indented.
34 35
\unexpanded
\def
\presetindentation
36
{
\doifoutervmode
{
\ifconditional
\c_spac_indentation_indent_first
\else
\spac_indentation_variant_no
\fi
}}
37 38
\unexpanded
\def
\setupindenting
39
{
\doifelsenextoptionalcs
\spac_indentation_setup_options
\spac_indentation_setup_size
}
40 41
% \unexpanded\def\spac_indentation_setup_size
42
% {\assigndimension\v_spac_indentation_current\d_spac_indentation_par{1\emwidth}{1.5\emwidth}{2\emwidth}}
43 44
\unexpanded
\def
\spac_indentation_setup_size
45
{
\assigndimension
\v_spac_indentation_current
\d_spac_indentation_par
{
1
\emwidth
}{
1
.
5
\emwidth
}{
2
\emwidth
}
%
46
\ifzeropt
\parindent\else
47
\parindent
\d_spac_indentation_par
\relax
% new per 2019-04-12 : just in case it has been set beforehand
48
\fi
}
49 50
\let
\synchronizeindenting
\spac_indentation_setup_size
51 52
\let
\m_spac_indentation_options
\empty
53 54
\def
\spac_indentation_setup_options
[#
1
]
%
55
{
\edef
\m_spac_indentation_options
{
#
1
}
% comma separated list
56
\ifx
\m_spac_indentation_options
\empty
\else
57
\spac_indentation_setup_indeed
58
\fi
}
59 60
\def
\spac_indentation_setup_indeed
61
{
% not here: \settrue\c_spac_indentation_indent_first
62
% not here: \parindent\d_spac_indentation_par
63
% not here: \c_spac_indentation_toggle_state\zerocount
64
\processcommacommand
[
\m_spac_indentation_options
]
\spac_indentation_apply_step_one
% catch small, medium, etc
65
\processcommacommand
[
\m_spac_indentation_options
]
\spac_indentation_apply_step_two
% catch rest
66
\ifzeropt
\parindent\else
67
\doifemptytoks
\everypar
\spac_indentation_set_everypar
68
\fi
69
\ifconditional
\c_spac_indentation_indent_first
70
\spac_indentation_variant_yes
% better than: \let\checkindentation\relax
71
\else
72
\spac_indentation_variant_no
73
\fi
74
\spac_indentation_check_toggle
}
75 76
\def
\spac_indentation_set_everypar
77
{
\everypar
{
\checkindentation
}}
78 79
\unexpanded
\def
\useindentingparameter
#
1
% faster local variant
80
{
\edef
\m_spac_indentation_options
{
#
1
\c!indenting
}
%
81
\ifx
\m_spac_indentation_options
\empty
\else
82
\spac_indentation_setup_indeed
83
\fi
}
84 85
% \def\spac_indentation_apply_step_one#1%
86
% {\ifcsname\??indentingmethod#1\endcsname
87
% % case two
88
% \else
89
% \edef\v_spac_indentation_current{#1}% single entry in list
90
% \let\normalindentation\v_spac_indentation_current
91
% \spac_indentation_setup_size
92
% \fi}
93
%
94
% \def\spac_indentation_apply_step_two#1%
95
% {\ifcsname\??indentingmethod#1\endcsname
96
% \csname\??indentingmethod#1\endcsname
97
% \else
98
% % case one
99
% \fi}
100 101
% \defineindenting[whatever][yes,2cm]
102
% %defineindenting[whatever][yes,-2cm]
103
%
104
% \setupindenting[yes,-2em] \input ward \par
105
% \setupindenting[yes,2em] \input ward \par
106
% \setupindenting[whatever] \input ward \par
107 108
\installcorenamespace
{
indentingpreset
}
109 110
\unexpanded
\def
\defineindenting
111
{
\dodoubleargument
\spac_indenting_define
}
112 113
\def
\spac_indenting_define
[#
1
][#
2
]
% todo: mixes
114
{
\setevalue
{
\??indentingpreset
#
1
}{
#
2
}}
115 116
% \def\spac_indentation_apply_step_one_nested#1%
117
% {\expandafter\processcommacommand\expandafter[\csname\??indentingpreset#1\endcsname]\spac_indentation_apply_step_one}
118
%
119
% \def\spac_indentation_apply_step_two_nested#1%
120
% {\expandafter\processcommacommand\expandafter[\csname\??indentingpreset#1\endcsname]\spac_indentation_apply_step_two}
121
%
122
% \def\spac_indentation_apply_step_one#1%
123
% {\ifcsname\??indentingpreset#1\endcsname
124
% \spac_indentation_apply_step_one_nested{#1}%
125
% \else\ifcsname\??indentingmethod#1\endcsname
126
% % case two
127
% \else
128
% \edef\v_spac_indentation_current{#1}% single entry in list
129
% \let\normalindentation\v_spac_indentation_current
130
% \spac_indentation_setup_size
131
% \fi\fi}
132
%
133
% \def\spac_indentation_apply_step_two#1%
134
% {\ifcsname\??indentingpreset#1\endcsname
135
% \spac_indentation_apply_step_two_nested{#1}%
136
% \else\ifcsname\??indentingmethod#1\endcsname
137
% \lastnamedcs
138
% \else
139
% % case one
140
% \fi\fi}
141 142
\def
\spac_indentation_apply_step_one_nested
143
{
\expandafter
\processcommacommand
\expandafter
[
\lastnamedcs
]
\spac_indentation_apply_step_one
}
144 145
\def
\spac_indentation_apply_step_two_nested
146
{
\expandafter
\processcommacommand
\expandafter
[
\lastnamedcs
]
\spac_indentation_apply_step_two
}
147 148
\def
\spac_indentation_apply_step_one
#
1
%
149
{
\ifcsname
\??indentingpreset
#
1
\endcsname
150
\spac_indentation_apply_step_one_nested
151
\else\ifcsname
\??indentingmethod
#
1
\endcsname
152
% case two
153
\else
154
\edef
\v_spac_indentation_current
{
#
1
}
% single entry in list
155
\let
\normalindentation
\v_spac_indentation_current
156
\spac_indentation_setup_size
157
\fi\fi
}
158 159
\def
\spac_indentation_apply_step_two
#
1
%
160
{
\ifcsname
\??indentingpreset
#
1
\endcsname
161
\spac_indentation_apply_step_two_nested
162
\else\ifcsname
\??indentingmethod
#
1
\endcsname
163
\lastnamedcs
164
\else
165
% case one
166
\fi\fi
}
167 168
\unexpanded
\def
\indenting
% kind of obsolete
169
{
\doifelsenextoptionalcs
\spac_indentation_setup_options
\relax
}
170 171
% use \noindentation to suppress next indentation
172 173
\installcorenamespace
{
indentingmethod
}
174 175
\unexpanded
\def
\installindentingmethod
#
1
#
2
%
176
{
\setvalue
{
\??indentingmethod
#
1
}{
#
2
}}
177 178
\installindentingmethod
\v!no
{
\parindent
\zeropoint
}
179
\installindentingmethod
\v!not
{
\parindent
\zeropoint
}
180 181
\installindentingmethod
\v!first
{
\settrue
\c_spac_indentation_indent_first
}
182
\installindentingmethod
\v!next
{
\setfalse
\c_spac_indentation_indent_first
}
183 184
\installindentingmethod
\v!yes
{
\parindent
\d_spac_indentation_par
\relax
}
% not \indent !
185
\installindentingmethod
\v!always
{
\parindent
\d_spac_indentation_par
\relax
}
% not \indent !
186 187
\installindentingmethod
\v!never
{
\parindent
\zeropoint
\relax
% no \indent !
188
\c_spac_indentation_toggle_state
\zerocount
}
189 190
\installindentingmethod
\v!odd
{
\c_spac_indentation_toggle_state
\plusone
}
191
\installindentingmethod
\v!even
{
\c_spac_indentation_toggle_state
\plustwo
}
192 193
\installindentingmethod
\v!normal
{
\ifx
\normalindentation
\empty
\else
194
\let
\v_spac_indentation_current
\normalindentation
195
\spac_indentation_setup_size
196
\fi
}
197 198
\installindentingmethod
\v!reset
{
\settrue
\c_spac_indentation_indent_first
199
\parindent
\zeropoint
200
\c_spac_indentation_toggle_state
\zerocount
}
201 202
\installindentingmethod
\v!toggle
{
\parindent
\ifzeropt
\parindent
203
\d_spac_indentation_par
204
\else
205
\zeropoint
206
\fi\relax
}
207 208
\unexpanded
\def
\noindenting
{
\indenting
[
\v!no
,
\v!next
]
}
209
\unexpanded
\def
\doindenting
{
\indenting
[
\v!yes
,
\v!first
]
}
210 211
%D Here come the handlers (still rather messy ... we need states).
212 213
%newif\ifindentation \indentationtrue % will become a mode
214 215
\let
\checkindentation
\relax
216 217
\installmacrostack
\checkindentation
218
%installmacrostack\ifindentation
219 220
\def
\spac_indentation_remove
221
{
\ifzeropt
\parindent
\else
222
\begingroup
223
\setbox
\scratchbox
\lastbox
224
\endgroup
225
\fi
}
226 227
\def
\spac_indentation_kill_indeed
228
{
%\global\indentationfalse
229
\spac_indentation_remove
}
230 231
\def
\spac_indentation_do_toggle_indeed
232
{
%\global\indentationfalse
233
\glet
\checkindentation
\spac_indentation_no_toggle_indeed
234
\spac_indentation_remove
}
235 236
\def
\spac_indentation_no_toggle_indeed
237
{
%\global\indentationtrue
238
\glet
\checkindentation
\spac_indentation_do_toggle_indeed
}
239 240
\def
\spac_indentation_do_indeed
241
{}
%\global\indentationtrue}
242 243
\def
\spac_indentation_do_toggle
244
{
\glet
\checkindentation
\spac_indentation_do_toggle_indeed
}
245 246
\def
\spac_indentation_no_toggle
247
{
\glet
\checkindentation
\spac_indentation_no_toggle_indeed
}
248 249
\def
\spac_indentation_check_toggle
250
{
\ifcase
\c_spac_indentation_toggle_state
251
% nothing
252
\or
253
\spac_indentation_no_toggle
254
\or
255
\spac_indentation_do_toggle
256
\fi
}
257 258
\def
\spac_indentation_variant_yes
259
{
\glet
\checkindentation
\spac_indentation_do_indeed
}
260 261
\def
\spac_indentation_no_next_check
262
{
\spac_indentation_remove
263
\glet
\checkindentation
\spac_indentation_do_indeed
}
264 265
\def
\spac_indentation_variant_no
% made global
266
{
\ifinpagebody
\else
267
%\global\indentationfalse
268
\glet
\checkindentation
\spac_indentation_no_next_check
269
\fi
}
270 271
\def
\nonoindentation
% bv bij floats
272
{
\ifinpagebody
\else
273
%\global\indentationtrue
274
\glet
\checkindentation
\spac_indentation_do_indeed
275
\fi
}
276 277
\def
\spac_indentation_variant_force
278
{
\ifvmode
\ifzeropt
\parindent
\else
279
% was : \hskip\parindent
280
% can be: \indent
281
% but we test:
282
\noindent\hskip\parindent
283
\fi
\fi
}
284 285
\appendtoks
286
\push_macro_checkindentation
287
\push_macro_ifindentation
288
\to
\everypushsomestate
289 290
\appendtoks
291
\pop_macro_ifindentation
292
\pop_macro_checkindentation
293
\to
\everypopsomestate
294 295
% public:
296 297
\let
\indentation
\spac_indentation_variant_force
298
\let
\noindentation
\spac_indentation_variant_no
% public
299
\let
\doindentation
\spac_indentation_variant_yes
% public
300 301
\def
\dontrechecknextindentation
% public (in macros)
302
{
\glet
\dorechecknextindentation
\relax
}
303 304
\let
\dorechecknextindentation
\relax
% public (in macros)
305 306
\unexpanded
\def
\spac_indentation_check_next_indentation
307
{
\glet
\dorechecknextindentation
\relax
308
\doifelsenextchar
\par
\donothing
\spac_indentation_variant_no
}
% messy check as next is seldom \par
309 310
\def
\spac_indentation_variant_auto
311
{
\glet
\dorechecknextindentation
\spac_indentation_check_next_indentation
}
312 313
%D This one sets up the local indentation behaviour (i.e. either or not
314
%D a next paragraph will be indented).
315 316
\installcorenamespace
{
indentnext
}
317 318
\unexpanded
\def
\checknextindentation
[#
1
]
%
319
{
\begincsname
\??indentnext
#
1
\endcsname
}
320 321
\unexpanded
\def
\useindentnextparameter
#
1
% new, the more efficient variant
322
{
\edef
\p_indentnext
{
#
1
\c!indentnext
}
%
323
\ifx
\p_indentnext
\empty
\else
324
\begincsname
\??indentnext
\p_indentnext
\endcsname
325
\fi
}
326 327
\letvalue
{
\??indentnext
}
\donothing
328
\letvalue
{
\??indentnext\v!yes
}
\spac_indentation_variant_yes
329
\letvalue
{
\??indentnext\v!no
}
\spac_indentation_variant_no
330
\letvalue
{
\??indentnext\v!auto
}
\spac_indentation_variant_auto
331 332
%D An example of usage:
333
%D
334
%D \starttyping
335
%D \setupindenting[small,yes]
336
%D
337
%D \setupitemize [indentnext=auto]
338
%D \setuptyping [indentnext=auto]
339
%D \setupformulas[indentnext=auto]
340
%D
341
%D \input tufte \startitemize \item itemize \stopitemize
342
%D \input tufte \startitemize \item itemize \stopitemize
343
%D \input tufte \startitemize \item itemize \stopitemize
344
%D
345
%D \page
346
%D
347
%D \input tufte
348
%D \starttyping
349
%D verbatim
350
%D \stoptyping
351
%D
352
%D \input tufte
353
%D \starttyping
354
%D verbatim
355
%D \stoptyping
356
%D
357
%D \input tufte
358
%D \starttyping
359
%D verbatim
360
%D \stoptyping
361
%D
362
%D \page
363
%D
364
%D \input tufte \startformula a = b \stopformula
365
%D \input tufte \startformula a = b \stopformula
366
%D \input tufte \startformula a = b \stopformula
367
%D \stoptyping
368 369
% maybe an everyforgetparindent
370 371
\unexpanded
\def
\forgetparindent
372
{
\settrue
\c_spac_indentation_indent_first
% recently added
373
\d_spac_indentation_par
\zeropoint
374
\parindent
\zeropoint
375
\let
\v_spac_indentation_current
\v!none
}
376 377
\appendtoks
378
\forgetparindent
379
\to
\everyforgetall
380 381
\unexpanded
\def
\forgethorizontalstretch
382
{
\emergencystretch
\zeropoint
}
383 384
\appendtoks
385
\forgethorizontalstretch
386
\to
\everyforgetall
% needed in pagebody
387 388
%D Helper:
389 390
\unexpanded
\def
\softbreak
391
{
\relax\ifhmode\hskip\parfillskip
\break
\fi
}
392 393
%D \macros
394
%D {frenchspacing,nonfrenchspacing}
395
%D
396
%D Somehow \type{\frenchspacing} can lead to hyphenation between dashes so we now
397
%D have \type {\newfrenchspacing} (moved from \type {syst-chr}). Maybe it's not
398
%D needed any more.
399 400
%D Hm ... todo:
401 402
\installcorenamespace
{
spacecodemethod
}
403 404
\sfcode
`
\)
=
\zerocount
405
\sfcode
`
\'
=
\zerocount
406
\sfcode
`
\]
=
\zerocount
407 408
\def
\spac_spacecodes_set_fixed
#
1
%
409
{
\sfcode
`
\.
#
1
\relax
\sfcode
`
\,
#
1
\relax
410
\sfcode
`
\?
#
1
\relax
\sfcode
`
\!
#
1
\relax
411
\sfcode
`
\:
#
1
\relax
\sfcode
`
\;
#
1
\relax
}
412 413
\def
\spac_spacecodes_set_stretch
414
{
\sfcode
`
\.
3
0
0
0
\sfcode
`
\,
1
2
5
0
415
\sfcode
`
\?
3
0
0
0
\sfcode
`
\!
3
0
0
0
416
\sfcode
`
\:
2
0
0
0
\sfcode
`
\;
1
5
0
0
}
417 418
\unexpanded
\def
\frenchspacing
{
\spac_spacecodes_set_fixed
\plusthousand
}
419
\unexpanded
\def
\newfrenchspacing
{
\spac_spacecodes_set_fixed
{
1
0
5
0
}}
420
\unexpanded
\def
\nonfrenchspacing
{
\spac_spacecodes_set_stretch
}
421 422
\unexpanded
\def
\installspacingmethod
#
1
#
2
{
\setvalue
{
\??spacecodemethod
#
1
}{
#
2
}}
423 424
\installspacingmethod
\empty
{}
% keep values
425
\installspacingmethod
\v!fixed
{
\frenchspacing
}
% equal spaces everywhere
426
\installspacingmethod
\v!packed
{
\newfrenchspacing
}
% slighly more after punctuation
427
\installspacingmethod
\v!broad
{
\nonfrenchspacing
}
% more depending on what punctuation
428 429
\unexpanded
\def
\setupspacing
430
{
\doifelsenextoptionalcs
\spac_spacecodes_setup_yes
\spac_spacecodes_setup_nop
}
431 432
\def
\spac_spacecodes_setup_yes
[#
1
]
%
433
{
\begincsname
\??spacecodemethod
#
1
\endcsname
434
\updateraggedskips
}
435 436
\def
\spac_spacecodes_setup_nop
437
{
\updateraggedskips
}
438 439
%D Here's a tweak .. if needed one can configure it in the configuration
440
%D so that initialization happens more efficient.
441
%D
442
%D \starttyping
443
%D \startoverlay
444
%D {
445
%D \green
446
%D \enabledirectives[characters.spaceafteruppercase=normal]%
447
%D \vbox{\hsize 5em x. X\par x.\ X\par X. X\par X.\ X\par}
448
%D } {
449
%D \blue
450
%D \enabledirectives[characters.spaceafteruppercase=traditional]%
451
%D \vbox{\hsize 5em x. X\par x.\ X\par X. X\par X.\ X\par}
452
%D }
453
%D \stopoverlay
454
%D \stoptyping
455 456
% This is not needed, as \updateraggedskips is taking care of it:
457 458
\let
\synchronizespacecodes
\spac_spacecodes_setup_nop
% \relax
459 460
% \dorecurse{100}{\recurselevel\spacefactor 800 \space} \par
461
% \dorecurse{100}{\recurselevel\spacefactor1200 \space} \par
462
% \dorecurse{100}{\recurselevel\spacefactor 800 \normalspaceprimitive} \par
463
% \dorecurse{100}{\recurselevel\spacefactor1200 \normalspaceprimitive} \par
464 465
% When we don't add the % here, we effectively get \<endlinechar> and
466
% since we have by default \def\^^M{\ } we get into a loop.
467 468
\let
\normalspaceprimitive
=
\
% space-comment is really needed
469 470
%D As the \type{\ } is convenient in:
471
%D
472
%D \starttyping
473
%D \TEX\space x\crlf
474
%D \TEX\ x\crlf
475
%D \TEX{} x\crlf
476
%D \stoptyping
477
%D
478
%D from now on we treat it as a normal space and not as a space with \type
479
%D {sfcode} 1000.
480 481
\unexpanded
\def
\specialspaceprimitive
482
{
\begingroup
483
% so, no fancy extra spacing after: foo i.e.\ bar
484
\nonfrenchspacing
\normalspaceprimitive
485
\endgroup
}
486 487
\unexpanded
\def
\normalnotobeyedspace
488
{
\mathortext
\normalspaceprimitive
\specialspaceprimitive
}
% no \dontleavehmode\space (else no frenchspacing)
489 490
\let\
=
\normalnotobeyedspace
491 492
% Because I strip spaces at the end of lines (in the editor) we need a bit of
493
% a trick to define slash+newline, so \space and \<newline> are the same
494 495
% We need to be careful with \ and \space and the definition of ~ which uses \ as
496
% we need to associate unicode spacing with it. There is some messy aspect that
497
% I forgot to note down so I will revision the \ once I ran into it again.
498 499
% \ruledhbox spread 10pt {\frenchspacing xx xx\ X}
500
% \ruledhbox spread 10pt {\nonfrenchspacing xx xx\ X}
501
% \ruledhbox spread 10pt {\frenchspacing xx xx X}
502
% \ruledhbox spread 10pt {\nonfrenchspacing xx xx X}
503
% \ruledhbox spread 10pt {\frenchspacing xx xx~X}
504
% \ruledhbox spread 10pt {\nonfrenchspacing xx xx~X}
505 506
% \ruledhbox spread 10pt {\frenchspacing xx dr.\ X}
507
% \ruledhbox spread 10pt {\nonfrenchspacing xx dr.\ X}
508
% \ruledhbox spread 10pt {\frenchspacing xx dr. X}
509
% \ruledhbox spread 10pt {\nonfrenchspacing xx dr. X}
510
% \ruledhbox spread 10pt {\frenchspacing xx dr.~X}
511
% \ruledhbox spread 10pt {\nonfrenchspacing xx dr.~X}
512 513
\unexpanded
\def
\nonbreakablespace
{
\penalty
\plustenthousand
\normalspaceprimitive
}
% no space in math
514 515
\letcatcodecommand
\ctxcatcodes
\tildeasciicode
\nonbreakablespace
% overloaded later
516 517
\def
\space
{
}
518
\unexpanded
\def
\removelastspace
{
\ifhmode
\unskip\fi
}
519
\unexpanded
\def
\nospace
{
\removelastspace
\ignorespaces
}
520 521
\ifdefined
\nospaces
522
\unexpanded
\def
\nospacing
{
\normalnospaces
\plusone
}
523
\unexpanded
\def
\dospacing
{
\normalnospaces
\zerocount
}
524
\else
525
\unexpanded
\def
\nospacing
{
\spaceskip
\scaledpoint
\xspaceskip
\zeropoint
}
526
\unexpanded
\def
\dospacing
{
\spaceskip
\currentspaceskip
\xspaceskip
\zeropoint
}
% what
527
\fi
528 529
\ifdefined
\softhyphen
\else
530
\let
\softhyphen
\explicitdiscretionary
531
\fi
532 533
\cldcontext{
"
\string\\unexpanded\string\\def\string\\\string\n{\string\\space}
"
}
534
%cldcontext{"\string\\let\string\\\string\n=\string\\space"}
535 536
% in tables we need:
537
%
538
% \def\fixedspace {\hskip.5em\relax}
539
%
540
% but, since not all fonts have .5em digits:
541 542
\unexpanded
\def
\fixedspace
543
{
\setbox
\scratchbox
\hpack
{
\mathortext
{
0
}{
0
}}
% was \hbox
544
\hskip\wd
\scratchbox
\relax
}
545 546
\unexpanded
\def
\fixedspaces
547
{
\letcatcodecommand
\ctxcatcodes
\tildeasciicode
\fixedspace
548
\let
~
\fixedspace
}
% we need to renew it
549 550
\appendtoks
551
\let
~
\space
552
\let\
\space
553
\to
\everysimplifycommands
554 555
\newsignal
\s_spac_keep_unwanted_space
556 557
\unexpanded
\def
\keepunwantedspaces
558
{
\ifhmode
559
\ifdim
\lastskip
=
\s_spac_keep_unwanted_space
\else
560
\hskip
\s_spac_keep_unwanted_space
\relax
561
\fi
562
\fi
}
563 564
\unexpanded
\def
\removeunwantedspaces
565
{
\ifhmode
566
\expandafter
\spac_helpers_remove_unwantedspace
567
\fi
}
568 569
\def
\spac_helpers_remove_unwantedspace
570
{
\ifnum
\lastnodetype
=
\gluenodecode
571
\ifdim
\lastskip
=
\s_spac_keep_unwanted_space
\relax
572
\unskip
573
\else
574
\unskip
575
\doubleexpandafter
\spac_helpers_remove_unwantedspace
576
\fi
577
\fi
}
578 579
\unexpanded
\def
\onlynonbreakablespace
580
{
\ifdim
\lastskip
=
\interwordspace
581
\unskip
582
\nonbreakablespace
583
\fi
584
\ignorespaces
}
585 586
% \startbuffer
587
% \startlines \tt \fixedspaces
588
% 0~1~~2~~~3~~~~4~~~~~5
589
% 0~~~~~~~~~~~~~~~~~~~5
590
% $0~1~~2~~~3~~~~4~~~~~5$
591
% $0~~~~~~~~~~~~~~~~~~~5$
592
% \stoplines
593
%
594
% \starttabulate[|~|]
595
% \NC 0~1~~2~~~3~~~~4~~~~~5 \NC \NR \NC 0~~~~~~~~~~~~~~~~~~~5 \NC \NR
596
% \NC $0~1~~2~~~3~~~~4~~~~~5$ \NC \NR \NC $0~~~~~~~~~~~~~~~~~~~5$ \NC \NR
597
% \stoptabulate
598
%
599
% \starttable[||]
600
% \NC 0~1~~2~~~3~~~~4~~~~~5 \NC \AR \NC 0~~~~~~~~~~~~~~~~~~~5 \NC \AR
601
% \NC $0~1~~2~~~3~~~~4~~~~~5$ \NC \AR \NC $0~~~~~~~~~~~~~~~~~~~5$ \NC \AR
602
% \stoptable
603
% \stopbuffer
604
%
605
% \setupbodyfont[cmr] \getbuffer
606
% \setupbodyfont[lbr] \getbuffer
607 608
%D A couple of plain macros:
609 610
\ifdefined
\thinspace
\else
611 612
\unexpanded
\def
\thinspace
{
\kern
.
1
6
6
6
7
\emwidth
}
613
\unexpanded
\def
\negthinspace
{
\kern
-
.
1
6
6
6
7
\emwidth
}
614
\unexpanded
\def
\enspace
{
\kern
.
5
\emwidth
}
615 616
\fi
617 618
\ifdefined
\quad
\else
619 620
\unexpanded
\def
\enskip
{
\hskip
.
5
\emwidth
\relax
}
621
\unexpanded
\def
\quad
{
\hskip
\emwidth
\relax
}
622
\unexpanded
\def
\qquad
{
\hskip
2
\emwidth
\relax
}
623 624
\fi
625 626
\unexpanded
\def
\negenspace
{
\kern
-
.
5
\emwidth
}
627
\unexpanded
\def
\negemspace
{
\kern
-
\emwidth
}
628 629
\let
\emspace\quad
630 631
\unexpanded
\def
\charspace
{
}
% the unexpandable \space (as space can also be delimiter for numbers)
632 633
\unexpanded
\def
\quads
634
{
\dosingleempty
\spac_quads
}
635 636
\def
\spac_quads
[#
1
]
%
637
{
\zwj
\dorecurse
{
\iffirstargument
#
1
\else
\plusthree
\fi
}{
\hskip
\emwidth\zwj
}}
638 639
% Suggested by GB (not the name -):
640 641
\def
\rapfillskip
{
.
5
\hsize
plus
.
0
9
2
\hsize
minus
.
5
\hsize
}
% D.A.'s value
642 643
% Bovendien definieren we enkele extra \fill's:
644 645
\unexpanded
\def
\hfilll
{
\hskip
\zeropoint
\s!plus
1
\s!filll
\relax
}
646
\unexpanded
\def
\vfilll
{
\vskip
\zeropoint
\s!plus
1
\s!filll
\relax
}
647 648
%unexpanded\def\hfilneg {\hskip\zeropoint\s!plus-1\s!fil\relax}
649
\unexpanded
\def
\hfillneg
{
\hskip
\zeropoint
\s!plus
-
1
\s!fill
\relax
}
650
\unexpanded
\def
\hfilllneg
{
\hskip
\zeropoint
\s!plus
-
1
\s!filll
\relax
}
651
%unexpanded\def\vfilneg {\vskip\zeropoint\s!plus-1\s!fil\relax}
652
\unexpanded
\def
\vfillneg
{
\vskip
\zeropoint
\s!plus
-
1
\s!fill
\relax
}
653
\unexpanded
\def
\vfilllneg
{
\vskip
\zeropoint
\s!plus
-
1
\s!filll
\relax
}
654 655
\unexpanded
\def
\tfskip
{
\begingroup
\tf
\hskip
\emwidth
\endgroup
}
656
\unexpanded
\def
\dotfskip
#
1
{
\begingroup
\tf
\hskip
#
1
\endgroup
}
% used elsewhere
657 658
% maybe we should hash the analysis
659 660
\installcorenamespace
{
narrower
}
661
\installcorenamespace
{
narrowermethod
}
662 663
\newskip
\s_spac_narrower_left
664
\newskip
\s_spac_narrower_right
665
\newskip
\s_spac_narrower_middle
666 667
\installcommandhandler
\??narrower
{
narrower
}
\??narrower
668 669
\setupnarrower
670
[
\c!before
=
\endgraf
,
671
\c!after
=
\endgraf
,
672
\c!left
=
1
.
5
\emwidth
,
673
\c!right
=
1
.
5
\emwidth
,
674
\c!middle
=
1
.
5
\emwidth
,
675
\c!default
=
\v!middle
]
676 677
\appendtoks
678
\setuevalue
{
\e!start
\currentnarrower
}{
\spac_narrower_start
{
\currentnarrower
}}
%
679
\setuevalue
{
\e!stop
\currentnarrower
}{
\spac_narrower_stop
}
%
680
\to
\everydefinenarrower
681 682
\unexpanded
\def
\installnarrowermethod
#
1
#
2
%
683
{
\setvalue
{
\??narrowermethod
#
1
}{
#
2
}}
684 685
\unexpanded
\def
\spac_narrower_method_analyze
#
1
%
686
{
\ifcsname
\??narrowermethod
#
1
\endcsname
687
\lastnamedcs
688
\else
689
\global\advance
\s_spac_narrower_middle
#
1
\relax
690
\fi
}
691 692
\def
\spac_narrower_initialize
[#
1
]
% hm, can be dorepeat directly
693
{
\dorepeatwithcommand
[#
1
]
\spac_narrower_method_analyze
}
694 695
\installnarrowermethod
\v!left
{
\global\advance
\s_spac_narrower_left
\narrowerparameter
\c!left
\relax
}
696
\installnarrowermethod
\v!middle
{
\global\advance
\s_spac_narrower_middle
\narrowerparameter
\c!middle
\relax
}
697
\installnarrowermethod
\v!right
{
\global\advance
\s_spac_narrower_right
\narrowerparameter
\c!right
\relax
}
698
\installnarrowermethod
{
-
\v!left
}{
\global\advance
\s_spac_narrower_left
-
\narrowerparameter
\c!left
\relax
}
699
\installnarrowermethod
{
-
\v!middle
}{
\global\advance
\s_spac_narrower_middle
-
\narrowerparameter
\c!middle
\relax
}
700
\installnarrowermethod
{
-
\v!right
}{
\global\advance
\s_spac_narrower_right
-
\narrowerparameter
\c!right
\relax
}
701
\installnarrowermethod
\v!reset
{
\global
\s_spac_narrower_left
\zeropoint
702
\global
\s_spac_narrower_middle
\zeropoint
703
\global
\s_spac_narrower_right
\zeropoint
\relax
}
704
\installnarrowermethod
\v!none
{}
705
\installnarrowermethod
\v!reverse
{}
% never seen
706 707
\unexpanded
\def
\spac_narrower_start
#
1
%
708
{
\begingroup
709
\edef
\currentnarrower
{
#
1
}
%
710
\dosingleempty
\spac_narrower_start_indeed
}
711 712
\unexpanded
\def
\spac_narrower_start_indeed
[#
1
]
%
713
{
\iffirstargument
714
\spac_narrower_start_apply
{
#
1
}
%
715
\else
716
\spac_narrower_start_apply
{
\narrowerparameter
\v!default
}
%
717
\fi
}
718 719
\newskip
\s_spac_narrower_left_last
720
\newskip
\s_spac_narrower_right_last
721
\newconditional
\s_spac_narrower_last_swap
722 723
\def
\spac_narrower_start_apply
#
1
%
724
{
\narrowerparameter
\c!before
725
\global
\s_spac_narrower_left
\zeropoint
726
\global
\s_spac_narrower_right
\zeropoint
727
\global
\s_spac_narrower_middle
\zeropoint
728
\edef
\askednarrower
{
#
1
}
%
729
\ifx
\askednarrower
\v!reverse
730
\ifconditional
\s_spac_narrower_last_swap
731
\leftskip
\s_spac_narrower_right_last
732
\rightskip
\s_spac_narrower_left_last
733
\setfalse
\s_spac_narrower_last_swap
734
\else
735
\leftskip
\s_spac_narrower_left_last
736
\rightskip
\s_spac_narrower_right_last
737
\settrue
\s_spac_narrower_last_swap
738
\fi
739
\else
740
\normalexpanded
{
\processcommalistwithparameters
[
\askednarrower
]
}
\spac_narrower_initialize
741
\advance\leftskip
\dimexpr
\s_spac_narrower_left
+
\s_spac_narrower_middle
\relax
742
\advance\rightskip\dimexpr
\s_spac_narrower_right
+
\s_spac_narrower_middle
\relax
743
\fi
744
\seteffectivehsize
}
745 746
\unexpanded
\def
\spac_narrower_stop
747
{
\narrowerparameter
\c!after
748
\normalexpanded
{
%
749
\endgroup
750
\s_spac_narrower_left_last
\the\leftskip
\relax
751
\s_spac_narrower_right_last
\the\rightskip\relax
752
\ifconditional
\s_spac_narrower_last_swap
753
\setfalse
\s_spac_narrower_last_swap
754
\else
755
\settrue
\s_spac_narrower_last_swap
756
\fi
757
}}
758 759
\unexpanded
\def
\startnarrower
760
{
\dosingleempty
\spac_narrower_start_basic
}
761 762
\unexpanded
\def
\spac_narrower_start_basic
[#
1
]
%
763
{
\begingroup
764
\let
\currentnarrower
\empty
765
\iffirstargument
766
\spac_narrower_start_apply
{
#
1
}
%
767
\else
768
\spac_narrower_start_apply
{
\narrowerparameter
\v!default
}
%
769
\fi
}
770 771
\let
\stopnarrower
\spac_narrower_stop
772 773
\unexpanded
\def
\startnarrow
% current how
774
{
\begingroup
775
\dodoubleempty
\spac_narrower_start_named
}
776 777
% \def\spac_narrower_start_named[#1][#2]%
778
% {\edef\currentnarrower{#1}%
779
% \ifsecondargument
780
% \spac_narrower_start_apply{#2}%
781
% \else
782
% \spac_narrower_start_apply{\narrowerparameter\v!default}%
783
% \fi}
784 785
\def
\spac_narrower_start_named
786
{
\ifsecondargument
787
\expandafter
\spac_narrower_start_named_two
788
\else
789
\expandafter
\spac_narrower_start_named_one
790
\fi
}
791 792
\def
\spac_narrower_start_named_one
[#
1
]
%
793
{
\doifelseassignment
{
#
1
}
\spac_narrower_start_named_one_yes
\spac_narrower_start_named_one_nop
[#
1
]
}
794 795
\def
\spac_narrower_start_named_one_yes
[#
1
][#
2
]
% [settings] []
796
{
\setupcurrentnarrower
[#
1
]
%
797
\spac_narrower_start_apply
{
\narrowerparameter
\v!default
}}
798 799
\def
\spac_narrower_start_named_one_nop
[#
1
][#
2
]
% [tag] []
800
{
\edef
\currentnarrower
{
#
1
}
%
801
\spac_narrower_start_apply
{
\narrowerparameter
\v!default
}}
802 803
\def
\spac_narrower_start_named_two
[#
1
]
%
804
{
\doifelseassignment
{
#
1
}
\spac_narrower_start_named_settings_how
\spac_narrower_start_named_tag_unknown
[#
1
]
}
805 806
\def
\spac_narrower_start_named_settings_how
[#
1
][#
2
]
% [settings] [how]
807
{
\setupcurrentnarrower
[#
1
]
%
808
\spac_narrower_start_apply
{
#
2
}}
809 810
\def
\spac_narrower_start_named_tag_unknown
[#
1
][#
2
]
% [tag] [...]
811
{
\doifelseassignment
{
#
2
}
\spac_narrower_start_named_tag_settings
\spac_narrower_start_named_tag_how
[#
1
][#
2
]
}
812 813
\def
\spac_narrower_start_named_tag_settings
[#
1
][#
2
]
% [tag] [settings]
814
{
\edef
\currentnarrower
{
#
1
}
%
815
\setupcurrentnarrower
[#
2
]
%
816
\spac_narrower_start_apply
{
\narrowerparameter
\v!default
}}
817 818
\def
\spac_narrower_start_named_tag_how
[#
1
][#
2
]
% [tag] [how]
819
{
\edef
\currentnarrower
{
#
1
}
%
820
\spac_narrower_start_apply
{
#
2
}}
821 822
\let
\stopnarrow
\spac_narrower_stop
823 824
\newdimen
\d_spac_effective_hsize
\def
\effectivehsize
{
\hsize
}
825
\newdimen
\d_spac_effective_leftskip
\def
\effectiveleftskip
{
\dimexpr\leftskip
\relax
}
826
\newdimen
\d_spac_effective_rightskip
\def
\effectiverightskip
{
\dimexpr\rightskip\relax
}
827 828
\unexpanded
\def
\seteffectivehsize
829
{
\setlocalhsize
830
\d_spac_effective_hsize
\localhsize
831
\d_spac_effective_leftskip
1
\leftskip
832
\d_spac_effective_rightskip
1
\rightskip
833
\let
\effectivehsize
\d_spac_effective_hsize
834
\let
\effectiveleftskip
\d_spac_effective_leftskip
835
\let
\effectiverightskip
\d_spac_effective_rightskip
}
836 837
\installcorenamespace
{
skipadaptionleft
}
838
\installcorenamespace
{
skipadaptionright
}
839 840
\newskip
\leftskipadaption
841
\newskip
\rightskipadaption
842 843
\setvalue
{
\??skipadaptionleft
\v!yes
}{
\ifzeropt
\d_spac_indentation_par
\narrowerparameter
\c!left
\else
\d_spac_indentation_par
\fi
}
844
\letvalue
{
\??skipadaptionleft
\v!no
}
\zeropoint
845
\letvalue
{
\??skipadaptionleft
\empty
}
\zeropoint
846
\setvalue
{
\??skipadaptionright\v!yes
}{
\narrowerparameter
\c!right
}
847
\letvalue
{
\??skipadaptionright\v!no
}
\zeropoint
848
\letvalue
{
\??skipadaptionright
\empty
}
\zeropoint
849 850
% \setvalue{\??skipadaptionleft \v!standard}{\ifzeropt\d_spac_indentation_par\narrowerparameter\c!left\else\d_spac_indentation_par\fi}
851
% \setvalue{\??skipadaptionright\v!standard}{\narrowerparameter\c!right}
852 853
\letcsnamecsname
\csname
\??skipadaptionleft
\v!standard
\endcsname\csname
\??skipadaptionleft
\v!yes
\endcsname
854
\letcsnamecsname
\csname
\??skipadaptionright\v!standard
\endcsname\csname
\??skipadaptionright\v!yes
\endcsname
855 856
% \unexpanded\def\dosetleftskipadaption #1{\leftskipadaption \ifcsname\??skipadaptionleft #1\endcsname\csname\??skipadaptionleft #1\endcsname\else#1\fi\relax}
857
% \unexpanded\def\dosetrightskipadaption#1{\rightskipadaption\ifcsname\??skipadaptionright#1\endcsname\csname\??skipadaptionright#1\endcsname\else#1\fi\relax}
858 859
\unexpanded
\def
\dosetleftskipadaption
#
1
{
\leftskipadaption
\ifcsname
\??skipadaptionleft
#
1
\endcsname\lastnamedcs\else
#
1
\fi\relax
}
860
\unexpanded
\def
\dosetrightskipadaption
#
1
{
\rightskipadaption
\ifcsname
\??skipadaptionright
#
1
\endcsname\lastnamedcs\else
#
1
\fi\relax
}
861 862
\unexpanded
\def
\doadaptleftskip
#
1
{
\normalexpanded
{
\dosetleftskipadaption
{
#
1
}}
\advance\leftskip
\leftskipadaption
}
863
\unexpanded
\def
\doadaptrightskip
#
1
{
\normalexpanded
{
\dosetrightskipadaption
{
#
1
}}
\advance\rightskip
\rightskipadaption
}
864 865
\unexpanded
\def
\forgetbothskips
866
{
\leftskip
\zeropoint
867
\rightskip
\zeropoint
868
\relax
}
869 870
\appendtoks
871
\forgetbothskips
872
\to
\everyforgetall
873 874
% in spac-ver.mkiv
875
%
876
% \unexpanded\def\forgetparskip
877
% {\s_spac_whitespace_parskip\zeropoint
878
% \parskip\zeropoint
879
% \let\v_spac_whitespace_current\v!none}
880
%
881
% \appendtoks
882
% \forgetparskip
883
% \to \everyforgetall
884 885
%D Tolerance (can also be set with align):
886 887
\installcorenamespace
{
tolerancemethods
}
888 889
\unexpanded
\def
\installtolerancemethod
#
1
#
2
#
3
%
890
{
\setvalue
{
\??tolerancemethods
#
1
:
#
2
}{
#
3
}}
891 892
\installtolerancemethod
\v!vertical
\v!verystrict
{
\let
\bottomtolerance
\empty
}
893
\installtolerancemethod
\v!vertical
\v!strict
{
\def
\bottomtolerance
{
.
0
5
0
}}
894
\installtolerancemethod
\v!vertical
\v!tolerant
{
\def
\bottomtolerance
{
.
0
7
5
}}
895
\installtolerancemethod
\v!vertical
\v!verytolerant
{
\def
\bottomtolerance
{
.
1
0
0
}}
896 897
\installtolerancemethod
\v!horizontal
\v!stretch
{
\emergencystretch
\bodyfontsize
}
898
\installtolerancemethod
\v!horizontal
\v!space
{
\spaceskip
.
5
em
\s!plus
.
2
5
em
\s!minus
.
2
5
em
\relax
}
899
\installtolerancemethod
\v!horizontal
\v!verystrict
{
\tolerance
\plustwohundred
}
900
\installtolerancemethod
\v!horizontal
\v!strict
{
\tolerance
1
5
0
0
}
901
\installtolerancemethod
\v!horizontal
\v!tolerant
{
\tolerance
3
0
0
0
}
902
\installtolerancemethod
\v!horizontal
\v!verytolerant
{
\tolerance
4
5
0
0
}
903 904
\appendetoks
905
\pretolerance
\plushundred
906
\tolerance
\plustwohundred
907
\to
\everyforgetall
908 909
\def
\spac_tolerances_step_vertical
#
1
{
\csname
\??tolerancemethods\v!vertical
:
#
1
\endcsname
}
910
\def
\spac_tolerances_step_horizontal
#
1
{
\csname
\??tolerancemethods\v!horizontal
:
#
1
\endcsname
}
911 912
\unexpanded
\def
\setuptolerance
913
{
\dosingleargument
\spac_tolerances_setup
}
914 915
\def
\spac_tolerances_setup
[#
1
]
%
916
{
\doifelseinset
\v!vertical
{
#
1
}
%
917
{
\processcommacommand
[#
1
]
\spac_tolerances_step_vertical
}
918
{
\processcommacommand
[#
1
]
\spac_tolerances_step_horizontal
}}
919 920
%D \macros
921
%D {pushindentation,popindentation}
922
%D
923
%D The pushing and popping is done by:
924 925
\newbox
\b_spac_indentations_a
926
\newbox
\b_spac_indentations_b
927 928
\unexpanded
\def
\pushindentation
929
{
\begingroup
930
\ifhmode
931
\unskip
932
\setbox
\b_spac_indentations_a
\lastbox
% get \strut if present
933
\unskip
934
\setbox
\b_spac_indentations_b
\lastbox
% get \indent generated box
935
\unskip
936
\else
937
\dontleavehmode
% was \hskip\zeropoint % switch to horizontal mode
938
\unskip
939
\setbox
\b_spac_indentations_a
\lastbox
% get \indent generated box
940
\setbox
\b_spac_indentations_b
\emptybox
941
\fi
}
942 943
\unexpanded
\def
\popindentation
944
{
\box
\b_spac_indentations_b
945
\box
\b_spac_indentations_a
946
\endgroup
}
947 948
%D The only complication lays in \type{\strut}. In \PLAIN\
949
%D \TEX\ a \type{\strut} is defined as:
950
%D
951
%D \starttyping
952
%D \def\strut%
953
%D {\relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi}
954
%D \stoptyping
955
%D
956
%D But what is a \type{\strut}? Normally it's a rule of width
957
%D zero, but when made visual, it's a rule and a negative skip.
958
%D The mechanism for putting things in the margins described
959
%D here cannot handle this situation very well. One
960
%D characteristic of \type{\strut} is that the \type{\unhcopy}
961
%D results in entering horizontal mode, which in return leads
962
%D to some indentation.
963
%D
964
%D To serve our purpose a bit better, the macro \type{\strut}
965
%D can be redefined as:
966
%D
967
%D \starttyping
968
%D \def\strut
969
%D {\relax\ifmmode\else\hskip0pt\fi\copy\strutbox}
970
%D \stoptyping
971
%D
972
%D Or more compatible:
973
%D
974
%D \starttyping
975
%D \def\strut
976
%D {\relax\ifmmode
977
%D \copy\strutbox
978
%D \else
979
%D \bgroup\setbox\strutbox=\hbox{\box\strutbox}\unhcopy\strutbox\egroup
980
%D \fi}
981
%D \stoptyping
982
%D
983
%D In \CONTEXT\ however we save some processing time by putting
984
%D an extra \type{\hbox} around the \type{\strutbox}.
985 986
%D \starttyping
987
%D % \setuplayout[gridgrid=yes] \showgrid
988
%D
989
%D \startbuffer
990
%D test 1\crlf
991
%D test 2\crlf
992
%D
993
%D \crlf test 3
994
%D
995
%D test 4\crlf
996
%D test 5
997
%D
998
%D \crlf
999
%D \crlf
1000
%D \crlf
1001
%D test 6
1002
%D \stopbuffer
1003
%D
1004
%D \hbox
1005
%D {\hsize5em
1006
%D \ruledvtop{\getbuffer}\enspace
1007
%D \ruledvtop{\showstruts\getbuffer}\enspace
1008
%D \hsize15em \setuptyping[before=,after=]%
1009
%D \ruledvtop{\typebuffer}}
1010
%D \stoptyping
1011 1012
\unexpanded
\def
\justonespace
{
\removeunwantedspaces\space
}
1013
%unexpanded\def\justaperiod {\removeunwantedspaces.}
1014
%unexpanded\def\justacomma {\removeunwantedspaces,}
1015 1016
\installcorenamespace
{
hspace
}
1017 1018
\unexpanded
\def
\ignorecrlf
1019
{
\let
\crlf
\justonespace
\let
\\
\crlf
}
1020 1021
\unexpanded
\def
\definehspace
1022
{
\dotripleempty
\spac_hspaces_define
}
1023 1024
\def
\spac_hspaces_define
[#
1
][#
2
][#
3
]
% #1 = optional namespace
1025
{
\ifthirdargument
1026
\setvalue
{
\??hspace
#
1
:
#
2
}{
#
3
}
%
1027
\else
1028
\setvalue
{
\??hspace
:
#
1
}{
#
2
}
%
1029
\fi
}
1030 1031
\unexpanded
\def
\hspace
1032
{
\dodoubleempty
\spac_hspaces_insert
}
1033 1034
\def
\spac_hspaces_insert
[#
1
][#
2
]
%
1035
{
\ifhmode
1036
\removeunwantedspaces
1037
\hskip
% always a skip even when 0pt
1038
\ifsecondargument
1039
\hspaceamount
{
#
1
}{
#
2
}
%
1040
\else
\iffirstargument
1041
\hspaceamount
\empty
{
#
1
}
%
1042
\else
1043
\hspaceamount
\empty
\s!default
1044
\fi\fi
1045
\expandafter\ignorespaces
1046
\fi
}
1047 1048
\def
\hspaceamount
#
1
#
2
%
1049
{
\dimexpr\ifcsname
\??hspace
#
1
:
#
2
\endcsname\lastnamedcs\else
\zeropoint
\fi\relax
}
1050 1051
\def
\directhspaceamount
#
1
%
1052
{
\dimexpr\ifcsname
\??hspace
:
#
1
\endcsname\lastnamedcs\else
\zeropoint
\fi\relax
}
1053 1054
% no installhspace here (this is already an old command)
1055 1056
\definehspace
[
\v!small
]
[
.
2
5
\emspaceamount
]
1057
\definehspace
[
\v!medium
]
[
.
5
\emspaceamount
]
1058
\definehspace
[
\v!big
]
[
1
\emspaceamount
]
1059
\definehspace
[
\v!normal
]
[
1
\spaceamount
]
1060
\definehspace
[
\v!default
]
[
\spaceamount
]
1061
\definehspace
[
\v!none
]
[
\zeropoint
]
1062 1063
%D Taken from Taco's math module (cq. \AMS\ macros), but
1064
%D adapted to \type {\hspace}:
1065 1066
\unexpanded
\def
\textormathspace
#
1
#
2
#
3
{
\ifmmode
\mskip
#
1
#
2
\else\kern
#
1
\hspaceamount
\empty
{
#
3
}
\fi\relax
}
1067
\unexpanded
\def
\textormathspacecommand
#
1
#
2
#
3
{
\ifmmode
\mskip
#
1
#
2
\else
#
3
\fi\relax
}
1068
\unexpanded
\def
\breakabletextormathspace
#
1
#
2
#
3
{
\ifmmode
\mskip
#
1
#
2
\else\hskip
#
1
\hspaceamount
\empty
{
#
3
}
\fi\relax
}
1069 1070
\newmuskip
\hairmuskip
\hairmuskip
=
.
1
5
mu
1071 1072
\unexpanded
\def
\hairspace
{
\textormathspace
+
\hairmuskip
{
.
5
}}
1073
\unexpanded
\def
\thinspace
{
\textormathspace
+
\thinmuskip
1
}
1074
%unexpanded\def\medspace {\textormathspace+\medmuskip 2} % 4/18 em
1075
\unexpanded
\def
\thickspace
{
\textormathspace
+
\thickmuskip
3
}
1076
\unexpanded
\def
\neghairspace
{
\textormathspace
-
\thinmuskip
{
.
5
}}
1077
\unexpanded
\def
\negthinspace
{
\textormathspace
-
\thinmuskip
1
}
1078
\unexpanded
\def
\negmedspace
{
\textormathspace
-
\medmuskip
2
}
1079
\unexpanded
\def
\negthickspace
{
\textormathspace
-
\thickmuskip
3
}
1080 1081
\unexpanded
\edef
\medspace
{
\textormathspacecommand
+
\medmuskip
{
\Uchar
"
2
0
5
F
}}
1082 1083
% needed for unicode:
1084 1085
%unexpanded\def\breakablethinspace {\breakabletextormathspace+\thinmuskip1}
1086
%unexpanded\def\twoperemspace {\hskip\dimexpr\emwidth/2\relax} % == \enspace
1087
%unexpanded\def\threeperemspace {\hskip\dimexpr\emwidth/3\relax}
1088
%unexpanded\def\fourperemspace {\hskip\dimexpr\emwidth/4\relax}
1089
%unexpanded\def\fiveperemspace {\hskip\dimexpr\emwidth/5\relax} % goodie
1090
%unexpanded\def\sixperemspace {\hskip\dimexpr\emwidth/6\relax}
1091
%unexpanded\def\figurespace {\begingroup\setbox\scratchbox\hbox{0}\hskip\wd\scratchbox\endgroup} % there is a command for this
1092
%unexpanded\def\punctuationspace {\begingroup\setbox\scratchbox\hbox{.}\hskip\wd\scratchbox\endgroup}
1093
%unexpanded\def\ideographicspace {\hskip\dimexpr\emwidth/1\relax}
1094
%unexpanded\def\ideographichalffillspace{\hskip\dimexpr\emwidth/2\relax}
1095
%unexpanded\def\nobreakspace {\penalty\plustenthousand\kern\interwordspace}
1096
%unexpanded\def\narrownobreakspace {\penalty\plustenthousand\thinspace}
1097
%unexpanded\def\zerowidthnobreakspace {\penalty\plustenthousand\kern\zeropoint}
1098
%unexpanded\def\zerowidthspace {\hskip\zeropoint}
1099 1100
\definehspace
[
.
5
][
.
1
2
5
0
\emwidth
]
% hair
1101
\definehspace
[
1
]
[
.
1
6
6
7
\emwidth
]
% thin
1102
\definehspace
[
2
]
[
.
2
2
2
2
\emwidth
]
% med
1103
\definehspace
[
3
]
[
.
2
7
7
7
\emwidth
]
% thick
1104 1105
\let
\,
\thinspace
1106
\let
\:
\medspace
1107
\let
\;
\thickspace
1108
\let
\!
\negthinspace
1109 1110
% plain ...
1111
%
1112
% \ifdefined\> \else \unexpanded\def\>{\mskip \medmuskip } \fi
1113
% \ifdefined\* \else \unexpanded\def\*{\discretionary{\thinspace\the\textfont2\char2}{}{}} \fi
1114 1115
\def
\flexiblespaceamount
#
1
#
2
#
3
%
1116
{
#
1
\interwordspace
1117
\s!plus
#
2
\interwordstretch
1118
\s!minus
#
3
\interwordshrink
}
1119 1120
\def
\fixedspaceamount
#
1
%
1121
{
#
1
\interwordspace
}
1122 1123
% moved from page-lin
1124
%
1125
% the following code is used in startlines\stoplines
1126
%
1127
% do we need \normalspaceprimitive here?
1128 1129
\installcorenamespace
{
spacemethods
}
1130 1131
\unexpanded
\def
\installspacemethod
#
1
#
2
% needs to set \obeyedspace
1132
{
\setvalue
{
\??spacemethods
#
1
}{
#
2
}}
1133 1134
\def
\activatespacehandler
#
1
%
1135
{
\csname
\??spacemethods
\ifcsname
\??spacemethods
#
1
\endcsname
#
1
\else
\v!off
\fi\endcsname
}
1136 1137
\unexpanded
\def
\spac_spaces_checked_control
{
\mathortext\normalspace
{
\dontleavehmode
{
\tt
\controlspace
}}}
%
1138
\unexpanded
\def
\spac_spaces_checked_normal
{
\mathortext\normalspace
{
\dontleavehmode\normalspace
}}
%
1139
\unexpanded
\def
\spac_spaces_checked_fixed
{
\mathortext\normalspace
{
\dontleavehmode
\fixedspace
}}
%
1140 1141
% hm, order matters when we \let in \obeyspaces
1142 1143
\installspacemethod
\v!on
1144
{
\obeyspaces
1145
\let
\obeyedspace
\spac_spaces_checked_control
1146
\let\
=
\obeyedspace
}
1147 1148
\installspacemethod
\v!yes
1149
{
\obeyspaces
1150
\let
\obeyedspace
\spac_spaces_checked_normal
1151
\let\
=
\obeyedspace
}
1152 1153
\installspacemethod
\v!off
% == default
1154
{
\normalspaces
1155
\let
\obeyedspace\normalspace
1156
\let\
=
\normalspaceprimitive
}
% was \normalspace
1157 1158
\installspacemethod
\v!fixed
1159
{
\obeyspaces
1160
\let
\obeyedspace
\spac_spaces_checked_fixed
1161
\let\
=
\obeyedspace
}
1162 1163
\appendtoks
1164
\normalspaces
% to be sure
1165
\to
\everybeforeoutput
1166 1167
%D A more robust variant of the \MKII\ one:
1168
%D
1169
%D \startbuffer
1170
%D bla \TEX\autoinsertnextspace bla
1171
%D bla \TEX\autoinsertnextspace (bla)
1172
%D bla (\TEX\autoinsertnextspace) bla
1173
%D bla \TEX\autoinsertnextspace\ bla
1174
%D \stopbuffer
1175
%D
1176
%D \typebuffer \getbuffer
1177 1178
\unexpanded
\def
\autoinsertnextspace
1179
{
\futurelet
\nexttoken
\spac_spaces_auto_insert_next
}
1180 1181
\def
\spac_spaces_auto_insert_next
1182
{
\clf_autonextspace
{
\normalmeaning
\nexttoken
}}
% todo, just consult nexttoken at the lua end
1183 1184
%D Moved from bib module:
1185 1186
\unexpanded
\def
\outdented
#
1
%
1187
{
\hskip
-
\hangindent
#
1
\relax
}
1188 1189
%D Beware: due to char-def this becomes an active character but that
1190
%D might change sometime when we will replace all these specials to
1191
%D node insertions. We might even expand it to utf then as it then
1192
%D can be used in string comparison (not that much needed anyway).
1193 1194
% \chardef\zwnj="200C
1195
% \chardef\zwj ="200D
1196 1197
% TODO (but used in languages):
1198 1199
\unexpanded
\def
\spac_glues_text_or_math
#
1
#
2
%
1200
{
\begingroup
1201
\ifmmode
1202
\mskip
#
1
%
1203
\else
1204
\scratchdimen
#
1
\hspaceamount
\empty
{
#
2
}
%
1205
\scratchskip\scratchdimen
\s!plus
.
5
\scratchdimen
\s!minus
.
3
\scratchdimen
1206
\hskip
\scratchskip
1207
\fi
1208
\endgroup
}
1209 1210
\unexpanded
\def
\thinglue
{
\spac_glues_text_or_math
\thinmuskip
\v!small
}
1211
\unexpanded
\def
\medglue
{
\spac_glues_text_or_math
\medmuskip
\v!medium
}
1212
\unexpanded
\def
\thickglue
{
\spac_glues_text_or_math
\thickmuskip
\v!big
}
1213 1214
%D A rather unknown one:
1215 1216
\unexpanded
\def
\widened
% moved from cont-new
1217
{
\doifelsenextoptionalcs
\spac_widened_yes
\spac_widened_nop
}
1218 1219
\def
\spac_widened_yes
[#
1
]#
2
{
\hbox
\s!spread
#
1
{
\hss
#
2
\hss
}}
1220
\def
\spac_widened_nop
#
1
{
\hbox
\s!spread
\emwidth
{
\hss
#
1
\hss
}}
1221 1222
\definecomplexorsimple
\widened
1223 1224
%D For the moment here (used in page-txt):
1225 1226
\unexpanded
\def
\ignoredlinebreak
{
\unskip
\space
\ignorespaces
}
1227 1228
%D \macros
1229
%D {startignorespaces}
1230
%D
1231
%D I'll probably forget that this one exists:
1232
%D
1233
%D \starttyping
1234
%D \ruledhbox
1235
%D {\startignorespaces
1236
%D \def\oeps{a}
1237
%D \startignorespaces
1238
%D \def\oeps{a}
1239
%D \stopignorespaces
1240
%D \def\oeps{a}
1241
%D \stopignorespaces
1242
%D \oeps}
1243
%D \stoptyping
1244 1245
\newsignal
\s_spac_ignore_spaces
1246
\newcount
\c_spac_ignore_spaces
1247 1248
\unexpanded
\def
\startignorespaces
1249
{
\advance
\c_spac_ignore_spaces
\plusone
1250
\ifcase
\c_spac_ignore_spaces
\or
\ifhmode
1251
\hskip
\s_spac_ignore_spaces
1252
\fi
\fi
1253
\ignorespaces
}
1254 1255
\unexpanded
\def
\stopignorespaces
1256
{
\ifcase
\c_spac_ignore_spaces
\or
1257
\ifhmode
1258
\doloop
\spac_ignore_spaces_body
1259
\fi
1260
\fi
1261
\advance
\c_spac_ignore_spaces
\minusone
}
1262 1263
\def
\spac_ignore_spaces_body
1264
{
\ifzeropt
\lastskip
1265
\exitloop
1266
\else\ifdim\lastskip
=
\s_spac_ignore_spaces
1267
\unskip
1268
\exitloop
1269
\else
1270
\unskip
1271
\fi\fi
}
1272 1273
%D \macros
1274
%D {obeyfollowingtoken}
1275 1276
\def
\obeyfollowingtoken
{{}}
% end \cs scanning
1277 1278
%D Something new:
1279 1280
\unexpanded
\def
\interwordspacebefore
{
\wordboundary
\zwnj
\hskip
\interwordspace
\relax
}
1281
\unexpanded
\def
\interwordspaceafter
{
\hskip
\interwordspace
\relax
\zwnj
\wordboundary
}
1282 1283
\unexpanded
\def
\interwordspacesbefore
#
1
{
\dofastloopcs
{
#
1
}
\interwordspacebefore
}
1284
\unexpanded
\def
\interwordspacesafter
#
1
{
\dofastloopcs
{
#
1
}
\interwordspaceafter
}
1285
\unexpanded
\def
\interwordspaces
#
1
{
\wordboundary
\zwnj
\dofastloopcs
{
\numexpr
#
1
+
\minusone
}
\interwordspaceafter
}
1286 1287
\protect
\endinput
1288