spac-hor.mkiv /size: 41 Kb    last modification: 2021-10-28 13:50
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`\.3000 \sfcode`\,1250
415   \sfcode`\?3000 \sfcode`\!3000
416   \sfcode`\:2000 \sfcode`\;1500 }
417
418\unexpanded\def\frenchspacing   {\spac_spacecodes_set_fixed\plusthousand}
419\unexpanded\def\newfrenchspacing{\spac_spacecodes_set_fixed{1050}}
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\specialspaceprimitive
488  {% is a current state, set explicitly or when a character is appended
489   \ifhmode
490     \spacefactor\plusthousand
491   \else
492     \dontleavehmode
493   \fi
494   \normalspaceprimitive}
495
496\unexpanded\def\normalnotobeyedspace
497  {\mathortext\normalspaceprimitive\specialspaceprimitive} % no \dontleavehmode\space (else no frenchspacing)
498
499\let\ =\normalnotobeyedspace
500
501% Because I strip spaces at the end of lines (in the editor) we need a bit of
502% a trick to define slash+newline, so \space and \<newline> are the same
503
504% We need to be careful with \ and \space and the definition of ~ which uses \ as
505% we need to associate unicode spacing with it. There is some messy aspect that
506% I forgot to note down so I will revision the \ once I ran into it again.
507
508% \ruledhbox spread 10pt {\frenchspacing    xx xx\ X}
509% \ruledhbox spread 10pt {\nonfrenchspacing xx xx\ X}
510% \ruledhbox spread 10pt {\frenchspacing    xx xx X}
511% \ruledhbox spread 10pt {\nonfrenchspacing xx xx X}
512% \ruledhbox spread 10pt {\frenchspacing    xx xx~X}
513% \ruledhbox spread 10pt {\nonfrenchspacing xx xx~X}
514
515% \ruledhbox spread 10pt {\frenchspacing    xx dr.\ X}
516% \ruledhbox spread 10pt {\nonfrenchspacing xx dr.\ X}
517% \ruledhbox spread 10pt {\frenchspacing    xx dr. X}
518% \ruledhbox spread 10pt {\nonfrenchspacing xx dr. X}
519% \ruledhbox spread 10pt {\frenchspacing    xx dr.~X}
520% \ruledhbox spread 10pt {\nonfrenchspacing xx dr.~X}
521
522\unexpanded\def\nonbreakablespace{\penalty\plustenthousand\normalspaceprimitive} % no space in math
523
524\letcatcodecommand \ctxcatcodes \tildeasciicode \nonbreakablespace % overloaded later
525
526           \def\space          { }
527\unexpanded\def\removelastspace{\ifhmode\unskip\fi}
528\unexpanded\def\nospace        {\removelastspace\ignorespaces}
529
530\ifdefined\nospaces
531    \unexpanded\def\nospacing{\normalnospaces\plusone}
532    \unexpanded\def\dospacing{\normalnospaces\zerocount}
533\else
534    \unexpanded\def\nospacing{\spaceskip\scaledpoint     \xspaceskip\zeropoint}
535    \unexpanded\def\dospacing{\spaceskip\currentspaceskip\xspaceskip\zeropoint} % what
536\fi
537
538\ifdefined\softhyphen \else
539    \let\softhyphen\explicitdiscretionary
540\fi
541
542\cldcontext{"\string\\unexpanded\string\\def\string\\\string\n{\string\\space}"}
543%cldcontext{"\string\\let\string\\\string\n=\string\\space"}
544
545% in tables we need:
546%
547% \def\fixedspace   {\hskip.5em\relax}
548%
549% but, since not all fonts have .5em digits:
550
551\unexpanded\def\fixedspace
552  {\setbox\scratchbox\hpack{\mathortext{0}{0}}% was \hbox
553   \hskip\wd\scratchbox\relax}
554
555\unexpanded\def\fixedspaces
556  {\letcatcodecommand \ctxcatcodes \tildeasciicode\fixedspace
557   \let~\fixedspace} % we need to renew it
558
559\appendtoks
560    \let~\space
561    \let\ \space
562\to \everysimplifycommands
563
564\newsignal\s_spac_keep_unwanted_space
565
566\unexpanded\def\keepunwantedspaces
567  {\ifhmode
568     \ifdim\lastskip=\s_spac_keep_unwanted_space\else
569        \hskip\s_spac_keep_unwanted_space\relax
570     \fi
571   \fi}
572
573\unexpanded\def\removeunwantedspaces
574  {\ifhmode
575     \expandafter \spac_helpers_remove_unwantedspace
576   \fi}
577
578\def\spac_helpers_remove_unwantedspace
579  {\ifnum\lastnodetype=\gluenodecode
580     \ifdim\lastskip=\s_spac_keep_unwanted_space\relax
581       \unskip
582     \else
583       \unskip
584       \doubleexpandafter\spac_helpers_remove_unwantedspace
585     \fi
586   \fi}
587
588\unexpanded\def\onlynonbreakablespace
589  {\ifdim\lastskip=\interwordspace
590     \unskip
591     \nonbreakablespace
592   \fi
593   \ignorespaces}
594
595% \startbuffer
596% \startlines \tt \fixedspaces
597%  0~1~~2~~~3~~~~4~~~~~5
598%  0~~~~~~~~~~~~~~~~~~~5
599% $0~1~~2~~~3~~~~4~~~~~5$
600% $0~~~~~~~~~~~~~~~~~~~5$
601% \stoplines
602%
603% \starttabulate[|~|]
604% \NC  0~1~~2~~~3~~~~4~~~~~5  \NC \NR \NC  0~~~~~~~~~~~~~~~~~~~5  \NC \NR
605% \NC $0~1~~2~~~3~~~~4~~~~~5$ \NC \NR \NC $0~~~~~~~~~~~~~~~~~~~5$ \NC \NR
606% \stoptabulate
607%
608% \starttable[||]
609% \NC  0~1~~2~~~3~~~~4~~~~~5  \NC \AR \NC  0~~~~~~~~~~~~~~~~~~~5  \NC \AR
610% \NC $0~1~~2~~~3~~~~4~~~~~5$ \NC \AR \NC $0~~~~~~~~~~~~~~~~~~~5$ \NC \AR
611% \stoptable
612% \stopbuffer
613%
614% \setupbodyfont[cmr] \getbuffer
615% \setupbodyfont[lbr] \getbuffer
616
617%D A couple of plain macros:
618
619\ifdefined\thinspace \else
620
621    \unexpanded\def\thinspace   {\kern .16667\emwidth}
622    \unexpanded\def\negthinspace{\kern-.16667\emwidth}
623    \unexpanded\def\enspace     {\kern     .5\emwidth}
624
625\fi
626
627\ifdefined\quad \else
628
629    \unexpanded\def\enskip{\hskip.5\emwidth\relax}
630    \unexpanded\def\quad  {\hskip  \emwidth\relax}
631    \unexpanded\def\qquad {\hskip 2\emwidth\relax}
632
633\fi
634
635\unexpanded\def\negenspace{\kern-.5\emwidth}
636\unexpanded\def\negemspace{\kern-  \emwidth}
637
638\let\emspace\quad
639
640\unexpanded\def\charspace{ } % the unexpandable \space (as space can also be delimiter for numbers)
641
642\unexpanded\def\quads
643  {\dosingleempty\spac_quads}
644
645\def\spac_quads[#1]%
646  {\zwj\dorecurse{\iffirstargument#1\else\plusthree\fi}{\hskip\emwidth\zwj}}
647
648% Suggested by GB (not the name -):
649
650\def\rapfillskip{.5\hsize plus .092\hsize minus .5\hsize} % D.A.'s value
651
652% Bovendien definieren we enkele extra \fill's:
653
654\unexpanded\def\hfilll   {\hskip\zeropoint\s!plus1\s!filll\relax}
655\unexpanded\def\vfilll   {\vskip\zeropoint\s!plus1\s!filll\relax}
656
657%unexpanded\def\hfilneg  {\hskip\zeropoint\s!plus-1\s!fil\relax}
658\unexpanded\def\hfillneg {\hskip\zeropoint\s!plus-1\s!fill\relax}
659\unexpanded\def\hfilllneg{\hskip\zeropoint\s!plus-1\s!filll\relax}
660%unexpanded\def\vfilneg  {\vskip\zeropoint\s!plus-1\s!fil\relax}
661\unexpanded\def\vfillneg {\vskip\zeropoint\s!plus-1\s!fill\relax}
662\unexpanded\def\vfilllneg{\vskip\zeropoint\s!plus-1\s!filll\relax}
663
664\unexpanded\def\tfskip    {\begingroup\tf\hskip\emwidth\endgroup}
665\unexpanded\def\dotfskip#1{\begingroup\tf\hskip      #1\endgroup} % used elsewhere
666
667% maybe we should hash the analysis
668
669\installcorenamespace{narrower}
670\installcorenamespace{narrowermethod}
671
672\newskip\s_spac_narrower_left
673\newskip\s_spac_narrower_right
674\newskip\s_spac_narrower_middle
675
676\installcommandhandler \??narrower {narrower} \??narrower
677
678\setupnarrower
679  [\c!before=\endgraf,
680   \c!after=\endgraf,
681   \c!left=1.5\emwidth,
682   \c!right=1.5\emwidth,
683   \c!middle=1.5\emwidth,
684   \c!default=\v!middle]
685
686\appendtoks
687   \setuevalue{\e!start\currentnarrower}{\spac_narrower_start{\currentnarrower}}%
688   \setuevalue{\e!stop \currentnarrower}{\spac_narrower_stop}%
689\to \everydefinenarrower
690
691\unexpanded\def\installnarrowermethod#1#2%
692  {\setvalue{\??narrowermethod#1}{#2}}
693
694\unexpanded\def\spac_narrower_method_analyze#1%
695  {\ifcsname\??narrowermethod#1\endcsname
696     \lastnamedcs
697   \else
698     \global\advance\s_spac_narrower_middle#1\relax
699   \fi}
700
701\def\spac_narrower_initialize[#1]% hm, can be dorepeat directly
702  {\dorepeatwithcommand[#1]\spac_narrower_method_analyze}
703
704\installnarrowermethod  \v!left   {\global\advance\s_spac_narrower_left   \narrowerparameter\c!left  \relax}
705\installnarrowermethod  \v!middle {\global\advance\s_spac_narrower_middle \narrowerparameter\c!middle\relax}
706\installnarrowermethod  \v!right  {\global\advance\s_spac_narrower_right  \narrowerparameter\c!right \relax}
707\installnarrowermethod{-\v!left  }{\global\advance\s_spac_narrower_left  -\narrowerparameter\c!left  \relax}
708\installnarrowermethod{-\v!middle}{\global\advance\s_spac_narrower_middle-\narrowerparameter\c!middle\relax}
709\installnarrowermethod{-\v!right }{\global\advance\s_spac_narrower_right -\narrowerparameter\c!right \relax}
710\installnarrowermethod  \v!reset  {\global        \s_spac_narrower_left   \zeropoint
711                                   \global        \s_spac_narrower_middle \zeropoint
712                                   \global        \s_spac_narrower_right  \zeropoint\relax}
713\installnarrowermethod \v!none    {}
714\installnarrowermethod \v!reverse {} % never seen
715
716\unexpanded\def\spac_narrower_start#1%
717  {\begingroup
718   \edef\currentnarrower{#1}%
719   \dosingleempty\spac_narrower_start_indeed}
720
721\unexpanded\def\spac_narrower_start_indeed[#1]%
722  {\iffirstargument
723     \spac_narrower_start_apply{#1}%
724   \else
725     \spac_narrower_start_apply{\narrowerparameter\v!default}%
726   \fi}
727
728\newskip\s_spac_narrower_left_last
729\newskip\s_spac_narrower_right_last
730\newconditional\s_spac_narrower_last_swap
731
732\def\spac_narrower_start_apply#1%
733  {\narrowerparameter\c!before
734   \global\s_spac_narrower_left  \zeropoint
735   \global\s_spac_narrower_right \zeropoint
736   \global\s_spac_narrower_middle\zeropoint
737   \edef\askednarrower{#1}%
738   \ifx\askednarrower\v!reverse
739     \ifconditional\s_spac_narrower_last_swap
740       \leftskip \s_spac_narrower_right_last
741       \rightskip\s_spac_narrower_left_last
742       \setfalse\s_spac_narrower_last_swap
743     \else
744       \leftskip \s_spac_narrower_left_last
745       \rightskip\s_spac_narrower_right_last
746       \settrue\s_spac_narrower_last_swap
747     \fi
748   \else
749     \normalexpanded{\processcommalistwithparameters[\askednarrower]}\spac_narrower_initialize
750     \advance\leftskip \dimexpr\s_spac_narrower_left +\s_spac_narrower_middle\relax
751     \advance\rightskip\dimexpr\s_spac_narrower_right+\s_spac_narrower_middle\relax
752   \fi
753   \seteffectivehsize}
754
755\unexpanded\def\spac_narrower_stop
756  {\narrowerparameter\c!after
757   \normalexpanded{%
758      \endgroup
759      \s_spac_narrower_left_last \the\leftskip \relax
760      \s_spac_narrower_right_last\the\rightskip\relax
761      \ifconditional\s_spac_narrower_last_swap
762        \setfalse\s_spac_narrower_last_swap
763      \else
764        \settrue\s_spac_narrower_last_swap
765      \fi
766   }}
767
768\unexpanded\def\startnarrower
769  {\dosingleempty\spac_narrower_start_basic}
770
771\unexpanded\def\spac_narrower_start_basic[#1]%
772  {\begingroup
773   \let\currentnarrower\empty
774   \iffirstargument
775     \spac_narrower_start_apply{#1}%
776   \else
777     \spac_narrower_start_apply{\narrowerparameter\v!default}%
778   \fi}
779
780\let\stopnarrower\spac_narrower_stop
781
782\unexpanded\def\startnarrow % current how
783  {\begingroup
784   \dodoubleempty\spac_narrower_start_named}
785
786% \def\spac_narrower_start_named[#1][#2]%
787%   {\edef\currentnarrower{#1}%
788%    \ifsecondargument
789%      \spac_narrower_start_apply{#2}%
790%    \else
791%      \spac_narrower_start_apply{\narrowerparameter\v!default}%
792%    \fi}
793
794\def\spac_narrower_start_named
795  {\ifsecondargument
796      \expandafter\spac_narrower_start_named_two
797   \else
798      \expandafter\spac_narrower_start_named_one
799   \fi}
800
801\def\spac_narrower_start_named_one[#1]%
802  {\doifelseassignment{#1}\spac_narrower_start_named_one_yes\spac_narrower_start_named_one_nop[#1]}
803
804\def\spac_narrower_start_named_one_yes[#1][#2]% [settings] []
805  {\setupcurrentnarrower[#1]%
806   \spac_narrower_start_apply{\narrowerparameter\v!default}}
807
808\def\spac_narrower_start_named_one_nop[#1][#2]% [tag] []
809  {\edef\currentnarrower{#1}%
810   \spac_narrower_start_apply{\narrowerparameter\v!default}}
811
812\def\spac_narrower_start_named_two[#1]%
813  {\doifelseassignment{#1}\spac_narrower_start_named_settings_how\spac_narrower_start_named_tag_unknown[#1]}
814
815\def\spac_narrower_start_named_settings_how[#1][#2]% [settings] [how]
816  {\setupcurrentnarrower[#1]%
817   \spac_narrower_start_apply{#2}}
818
819\def\spac_narrower_start_named_tag_unknown[#1][#2]% [tag] [...]
820  {\doifelseassignment{#2}\spac_narrower_start_named_tag_settings\spac_narrower_start_named_tag_how[#1][#2]}
821
822\def\spac_narrower_start_named_tag_settings[#1][#2]% [tag] [settings]
823  {\edef\currentnarrower{#1}%
824   \setupcurrentnarrower[#2]%
825   \spac_narrower_start_apply{\narrowerparameter\v!default}}
826
827\def\spac_narrower_start_named_tag_how[#1][#2]% [tag] [how]
828  {\edef\currentnarrower{#1}%
829   \spac_narrower_start_apply{#2}}
830
831\let\stopnarrow\spac_narrower_stop
832
833\newdimen\d_spac_effective_hsize     \def\effectivehsize    {\hsize}
834\newdimen\d_spac_effective_leftskip  \def\effectiveleftskip {\dimexpr\leftskip \relax}
835\newdimen\d_spac_effective_rightskip \def\effectiverightskip{\dimexpr\rightskip\relax}
836
837\unexpanded\def\seteffectivehsize
838  {\setlocalhsize
839   \d_spac_effective_hsize    \localhsize
840   \d_spac_effective_leftskip 1\leftskip
841   \d_spac_effective_rightskip1\rightskip
842   \let\effectivehsize    \d_spac_effective_hsize
843   \let\effectiveleftskip \d_spac_effective_leftskip
844   \let\effectiverightskip\d_spac_effective_rightskip}
845
846\installcorenamespace{skipadaptionleft}
847\installcorenamespace{skipadaptionright}
848
849\newskip\leftskipadaption
850\newskip\rightskipadaption
851
852\setvalue{\??skipadaptionleft \v!yes     }{\ifzeropt\d_spac_indentation_par\narrowerparameter\c!left\else\d_spac_indentation_par\fi}
853\letvalue{\??skipadaptionleft \v!no      }\zeropoint
854\letvalue{\??skipadaptionleft \empty     }\zeropoint
855\setvalue{\??skipadaptionright\v!yes     }{\narrowerparameter\c!right}
856\letvalue{\??skipadaptionright\v!no      }\zeropoint
857\letvalue{\??skipadaptionright\empty     }\zeropoint
858
859% \setvalue{\??skipadaptionleft \v!standard}{\ifzeropt\d_spac_indentation_par\narrowerparameter\c!left\else\d_spac_indentation_par\fi}
860% \setvalue{\??skipadaptionright\v!standard}{\narrowerparameter\c!right}
861
862\letcsnamecsname\csname\??skipadaptionleft \v!standard\endcsname\csname\??skipadaptionleft \v!yes\endcsname
863\letcsnamecsname\csname\??skipadaptionright\v!standard\endcsname\csname\??skipadaptionright\v!yes\endcsname
864
865% \unexpanded\def\dosetleftskipadaption #1{\leftskipadaption \ifcsname\??skipadaptionleft #1\endcsname\csname\??skipadaptionleft #1\endcsname\else#1\fi\relax}
866% \unexpanded\def\dosetrightskipadaption#1{\rightskipadaption\ifcsname\??skipadaptionright#1\endcsname\csname\??skipadaptionright#1\endcsname\else#1\fi\relax}
867
868\unexpanded\def\dosetleftskipadaption #1{\leftskipadaption \ifcsname\??skipadaptionleft #1\endcsname\lastnamedcs\else#1\fi\relax}
869\unexpanded\def\dosetrightskipadaption#1{\rightskipadaption\ifcsname\??skipadaptionright#1\endcsname\lastnamedcs\else#1\fi\relax}
870
871\unexpanded\def\doadaptleftskip #1{\normalexpanded{\dosetleftskipadaption {#1}}\advance\leftskip \leftskipadaption }
872\unexpanded\def\doadaptrightskip#1{\normalexpanded{\dosetrightskipadaption{#1}}\advance\rightskip\rightskipadaption}
873
874\unexpanded\def\forgetbothskips
875  {\leftskip\zeropoint
876   \rightskip\zeropoint
877   \relax}
878
879\appendtoks
880    \forgetbothskips
881\to \everyforgetall
882
883% in spac-ver.mkiv
884%
885% \unexpanded\def\forgetparskip
886%   {\s_spac_whitespace_parskip\zeropoint
887%    \parskip\zeropoint
888%    \let\v_spac_whitespace_current\v!none}
889%
890% \appendtoks
891%     \forgetparskip
892% \to \everyforgetall
893
894%D Tolerance (can also be set with align):
895
896\installcorenamespace{tolerancemethods}
897
898\unexpanded\def\installtolerancemethod#1#2#3%
899  {\setvalue{\??tolerancemethods#1:#2}{#3}}
900
901\installtolerancemethod \v!vertical   \v!verystrict   {\let\bottomtolerance\empty}
902\installtolerancemethod \v!vertical   \v!strict       {\def\bottomtolerance{.050}}
903\installtolerancemethod \v!vertical   \v!tolerant     {\def\bottomtolerance{.075}}
904\installtolerancemethod \v!vertical   \v!verytolerant {\def\bottomtolerance{.100}}
905
906\installtolerancemethod \v!horizontal \v!stretch      {\emergencystretch\bodyfontsize}
907\installtolerancemethod \v!horizontal \v!space        {\spaceskip.5em\s!plus.25em\s!minus.25em\relax}
908\installtolerancemethod \v!horizontal \v!verystrict   {\tolerance\plustwohundred}
909\installtolerancemethod \v!horizontal \v!strict       {\tolerance1500 }
910\installtolerancemethod \v!horizontal \v!tolerant     {\tolerance3000 }
911\installtolerancemethod \v!horizontal \v!verytolerant {\tolerance4500 }
912
913\appendetoks
914     \pretolerance\plushundred
915     \tolerance   \plustwohundred
916\to\everyforgetall
917
918\def\spac_tolerances_step_vertical  #1{\csname\??tolerancemethods\v!vertical  :#1\endcsname}
919\def\spac_tolerances_step_horizontal#1{\csname\??tolerancemethods\v!horizontal:#1\endcsname}
920
921\unexpanded\def\setuptolerance
922  {\dosingleargument\spac_tolerances_setup}
923
924\def\spac_tolerances_setup[#1]%
925  {\doifelseinset\v!vertical{#1}%
926     {\processcommacommand[#1]\spac_tolerances_step_vertical  }
927     {\processcommacommand[#1]\spac_tolerances_step_horizontal}}
928
929%D \macros
930%D   {pushindentation,popindentation}
931%D
932%D The pushing and popping is done by:
933
934\newbox\b_spac_indentations_a
935\newbox\b_spac_indentations_b
936
937\unexpanded\def\pushindentation
938  {\begingroup
939   \ifhmode
940     \unskip
941     \setbox\b_spac_indentations_a\lastbox       % get \strut if present
942     \unskip
943     \setbox\b_spac_indentations_b\lastbox       % get \indent generated box
944     \unskip
945   \else
946     \dontleavehmode % was \hskip\zeropoint      % switch to horizontal mode
947     \unskip
948     \setbox\b_spac_indentations_a\lastbox       % get \indent generated box
949     \setbox\b_spac_indentations_b\emptybox
950   \fi}
951
952\unexpanded\def\popindentation
953  {\box\b_spac_indentations_b
954   \box\b_spac_indentations_a
955   \endgroup}
956
957%D The only complication lays in \type{\strut}. In \PLAIN\
958%D \TEX\ a \type{\strut} is defined as:
959%D
960%D \starttyping
961%D \def\strut%
962%D   {\relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi}
963%D \stoptyping
964%D
965%D But what is a \type{\strut}? Normally it's a rule of width
966%D zero, but when made visual, it's a rule and a negative skip.
967%D The mechanism for putting things in the margins described
968%D here cannot handle this situation very well. One
969%D characteristic of \type{\strut} is that the \type{\unhcopy}
970%D results in entering horizontal mode, which in return leads
971%D to some indentation.
972%D
973%D To serve our purpose a bit better, the macro \type{\strut}
974%D can be redefined as:
975%D
976%D \starttyping
977%D \def\strut
978%D   {\relax\ifmmode\else\hskip0pt\fi\copy\strutbox}
979%D \stoptyping
980%D
981%D Or more compatible:
982%D
983%D \starttyping
984%D \def\strut
985%D   {\relax\ifmmode
986%D      \copy\strutbox
987%D    \else
988%D      \bgroup\setbox\strutbox=\hbox{\box\strutbox}\unhcopy\strutbox\egroup
989%D    \fi}
990%D \stoptyping
991%D
992%D In \CONTEXT\ however we save some processing time by putting
993%D an extra \type{\hbox} around the \type{\strutbox}.
994
995%D \starttyping
996%D % \setuplayout[gridgrid=yes] \showgrid
997%D
998%D \startbuffer
999%D test 1\crlf
1000%D test 2\crlf
1001%D
1002%D \crlf test 3
1003%D
1004%D test 4\crlf
1005%D test 5
1006%D
1007%D \crlf
1008%D \crlf
1009%D \crlf
1010%D test 6
1011%D \stopbuffer
1012%D
1013%D \hbox
1014%D   {\hsize5em
1015%D    \ruledvtop{\getbuffer}\enspace
1016%D    \ruledvtop{\showstruts\getbuffer}\enspace
1017%D    \hsize15em \setuptyping[before=,after=]%
1018%D    \ruledvtop{\typebuffer}}
1019%D \stoptyping
1020
1021\unexpanded\def\justonespace{\removeunwantedspaces\space}
1022%unexpanded\def\justaperiod {\removeunwantedspaces.}
1023%unexpanded\def\justacomma  {\removeunwantedspaces,}
1024
1025\installcorenamespace{hspace}
1026
1027\unexpanded\def\ignorecrlf
1028  {\let\crlf\justonespace\let\\\crlf}
1029
1030\unexpanded\def\definehspace
1031  {\dotripleempty\spac_hspaces_define}
1032
1033\def\spac_hspaces_define[#1][#2][#3]% #1 = optional namespace
1034  {\ifthirdargument
1035     \setvalue{\??hspace#1:#2}{#3}%
1036   \else
1037     \setvalue{\??hspace:#1}{#2}%
1038   \fi}
1039
1040\unexpanded\def\hspace
1041  {\dodoubleempty\spac_hspaces_insert}
1042
1043\def\spac_hspaces_insert[#1][#2]%
1044  {\ifhmode
1045     \removeunwantedspaces
1046     \hskip % always a skip even when 0pt
1047       \ifsecondargument
1048         \hspaceamount{#1}{#2}%
1049       \else\iffirstargument
1050         \hspaceamount\empty{#1}%
1051       \else
1052         \hspaceamount\empty\s!default
1053       \fi\fi
1054     \expandafter\ignorespaces
1055   \fi}
1056
1057\def\hspaceamount#1#2%
1058  {\dimexpr\ifcsname\??hspace#1:#2\endcsname\lastnamedcs\else\zeropoint\fi\relax}
1059
1060\def\directhspaceamount#1%
1061  {\dimexpr\ifcsname\??hspace  :#1\endcsname\lastnamedcs\else\zeropoint\fi\relax}
1062
1063% no installhspace here (this is already an old command)
1064
1065\definehspace [\v!small]   [.25\emspaceamount]
1066\definehspace [\v!medium]  [.5\emspaceamount]
1067\definehspace [\v!big]     [1\emspaceamount]
1068\definehspace [\v!normal]  [1\spaceamount]
1069\definehspace [\v!default] [\spaceamount]
1070\definehspace [\v!none]    [\zeropoint]
1071
1072%D Taken from Taco's math module (cq. \AMS\ macros), but
1073%D adapted to \type {\hspace}:
1074
1075\unexpanded\def\textormathspace         #1#2#3{\ifmmode\mskip#1#2\else\kern #1\hspaceamount\empty{#3}\fi\relax}
1076\unexpanded\def\textormathspacecommand  #1#2#3{\ifmmode\mskip#1#2\else#3\fi\relax}
1077\unexpanded\def\breakabletextormathspace#1#2#3{\ifmmode\mskip#1#2\else\hskip#1\hspaceamount\empty{#3}\fi\relax}
1078
1079\newmuskip\hairmuskip \hairmuskip=.15mu
1080
1081\unexpanded\def\hairspace    {\textormathspace+\hairmuskip{.5}}
1082\unexpanded\def\thinspace    {\textormathspace+\thinmuskip 1}
1083%unexpanded\def\medspace     {\textormathspace+\medmuskip  2}      % 4/18 em
1084\unexpanded\def\thickspace   {\textormathspace+\thickmuskip3}
1085\unexpanded\def\neghairspace {\textormathspace-\thinmuskip{.5}}
1086\unexpanded\def\negthinspace {\textormathspace-\thinmuskip 1}
1087\unexpanded\def\negmedspace  {\textormathspace-\medmuskip  2}
1088\unexpanded\def\negthickspace{\textormathspace-\thickmuskip3}
1089
1090\unexpanded\edef\medspace    {\textormathspacecommand+\medmuskip{\Uchar"205F}}
1091
1092% needed for unicode:
1093
1094%unexpanded\def\breakablethinspace      {\breakabletextormathspace+\thinmuskip1}
1095%unexpanded\def\twoperemspace           {\hskip\dimexpr\emwidth/2\relax} % == \enspace
1096%unexpanded\def\threeperemspace         {\hskip\dimexpr\emwidth/3\relax}
1097%unexpanded\def\fourperemspace          {\hskip\dimexpr\emwidth/4\relax}
1098%unexpanded\def\fiveperemspace          {\hskip\dimexpr\emwidth/5\relax} % goodie
1099%unexpanded\def\sixperemspace           {\hskip\dimexpr\emwidth/6\relax}
1100%unexpanded\def\figurespace             {\begingroup\setbox\scratchbox\hbox{0}\hskip\wd\scratchbox\endgroup} % there is a command for this
1101%unexpanded\def\punctuationspace        {\begingroup\setbox\scratchbox\hbox{.}\hskip\wd\scratchbox\endgroup}
1102%unexpanded\def\ideographicspace        {\hskip\dimexpr\emwidth/1\relax}
1103%unexpanded\def\ideographichalffillspace{\hskip\dimexpr\emwidth/2\relax}
1104%unexpanded\def\nobreakspace            {\penalty\plustenthousand\kern\interwordspace}
1105%unexpanded\def\narrownobreakspace      {\penalty\plustenthousand\thinspace}
1106%unexpanded\def\zerowidthnobreakspace   {\penalty\plustenthousand\kern\zeropoint}
1107%unexpanded\def\zerowidthspace          {\hskip\zeropoint}
1108
1109\definehspace[.5][.1250\emwidth] % hair
1110\definehspace[1] [.1667\emwidth] % thin
1111\definehspace[2] [.2222\emwidth] % med
1112\definehspace[3] [.2777\emwidth] % thick
1113
1114\let \, \thinspace
1115\let \: \medspace
1116\let \; \thickspace
1117\let \! \negthinspace
1118
1119% plain ...
1120%
1121% \ifdefined\> \else \unexpanded\def\>{\mskip \medmuskip  }                                \fi
1122% \ifdefined\* \else \unexpanded\def\*{\discretionary{\thinspace\the\textfont2\char2}{}{}} \fi
1123
1124\def\flexiblespaceamount#1#2#3%
1125         {#1\interwordspace
1126   \s!plus#2\interwordstretch
1127  \s!minus#3\interwordshrink}
1128
1129\def\fixedspaceamount#1%
1130  {#1\interwordspace}
1131
1132% moved from page-lin
1133%
1134% the following code is used in startlines\stoplines
1135%
1136% do we need \normalspaceprimitive here?
1137
1138\installcorenamespace{spacemethods}
1139
1140\unexpanded\def\installspacemethod#1#2% needs to set \obeyedspace
1141  {\setvalue{\??spacemethods#1}{#2}}
1142
1143\def\activatespacehandler#1%
1144  {\csname\??spacemethods\ifcsname\??spacemethods#1\endcsname#1\else\v!off\fi\endcsname}
1145
1146\unexpanded\def\spac_spaces_checked_control{\mathortext\normalspace{\dontleavehmode{\tt\controlspace}}}%
1147\unexpanded\def\spac_spaces_checked_normal {\mathortext\normalspace{\dontleavehmode\normalspace}}%
1148\unexpanded\def\spac_spaces_checked_fixed  {\mathortext\normalspace{\dontleavehmode\fixedspace}}%
1149
1150% hm, order matters when we \let in \obeyspaces
1151
1152\installspacemethod \v!on
1153  {\obeyspaces
1154   \let\obeyedspace\spac_spaces_checked_control
1155   \let\ =\obeyedspace}
1156
1157\installspacemethod \v!yes
1158  {\obeyspaces
1159   \let\obeyedspace\spac_spaces_checked_normal
1160   \let\ =\obeyedspace}
1161
1162\installspacemethod \v!off % == default
1163  {\normalspaces
1164   \let\obeyedspace\normalspace
1165   \let\ =\normalspaceprimitive} % was \normalspace
1166
1167\installspacemethod \v!fixed
1168  {\obeyspaces
1169   \let\obeyedspace\spac_spaces_checked_fixed
1170   \let\ =\obeyedspace}
1171
1172\appendtoks
1173   \normalspaces % to be sure
1174\to \everybeforeoutput
1175
1176%D A more robust variant of the \MKII\ one:
1177%D
1178%D \startbuffer
1179%D bla \TEX\autoinsertnextspace bla
1180%D bla \TEX\autoinsertnextspace (bla)
1181%D bla (\TEX\autoinsertnextspace) bla
1182%D bla \TEX\autoinsertnextspace\ bla
1183%D \stopbuffer
1184%D
1185%D \typebuffer \getbuffer
1186
1187\unexpanded\def\autoinsertnextspace
1188  {\futurelet\nexttoken\spac_spaces_auto_insert_next}
1189
1190\def\spac_spaces_auto_insert_next
1191  {\clf_autonextspace{\normalmeaning\nexttoken}} % todo, just consult nexttoken at the lua end
1192
1193%D Moved from bib module:
1194
1195\unexpanded\def\outdented#1%
1196  {\hskip-\hangindent#1\relax}
1197
1198%D Beware: due to char-def this becomes an active character but that
1199%D might change sometime when we will replace all these specials to
1200%D node insertions. We might even expand it to utf then as it then
1201%D can be used in string comparison (not that much needed anyway).
1202
1203% \chardef\zwnj="200C
1204% \chardef\zwj ="200D
1205
1206% TODO (but used in languages):
1207
1208\unexpanded\def\spac_glues_text_or_math#1#2%
1209  {\begingroup
1210   \ifmmode
1211     \mskip#1%
1212   \else
1213     \scratchdimen#1\hspaceamount\empty{#2}%
1214     \scratchskip\scratchdimen\s!plus.5\scratchdimen\s!minus.3\scratchdimen
1215     \hskip\scratchskip
1216   \fi
1217   \endgroup}
1218
1219\unexpanded\def\thinglue {\spac_glues_text_or_math\thinmuskip \v!small}
1220\unexpanded\def\medglue  {\spac_glues_text_or_math\medmuskip  \v!medium}
1221\unexpanded\def\thickglue{\spac_glues_text_or_math\thickmuskip\v!big}
1222
1223%D A rather unknown one:
1224
1225\unexpanded\def\widened % moved from cont-new
1226  {\doifelsenextoptionalcs\spac_widened_yes\spac_widened_nop}
1227
1228\def\spac_widened_yes[#1]#2{\hbox \s!spread       #1{\hss#2\hss}}
1229\def\spac_widened_nop    #1{\hbox \s!spread \emwidth{\hss#1\hss}}
1230
1231\definecomplexorsimple\widened
1232
1233%D For the moment here (used in page-txt):
1234
1235\unexpanded\def\ignoredlinebreak{\unskip\space\ignorespaces}
1236
1237%D \macros
1238%D   {startignorespaces}
1239%D
1240%D I'll probably forget that this one exists:
1241%D
1242%D \starttyping
1243%D \ruledhbox
1244%D   {\startignorespaces
1245%D      \def\oeps{a}
1246%D      \startignorespaces
1247%D        \def\oeps{a}
1248%D      \stopignorespaces
1249%D      \def\oeps{a}
1250%D    \stopignorespaces
1251%D    \oeps}
1252%D \stoptyping
1253
1254\newsignal\s_spac_ignore_spaces
1255\newcount \c_spac_ignore_spaces
1256
1257\unexpanded\def\startignorespaces
1258  {\advance\c_spac_ignore_spaces\plusone
1259   \ifcase\c_spac_ignore_spaces\or \ifhmode
1260     \hskip\s_spac_ignore_spaces
1261   \fi \fi
1262   \ignorespaces}
1263
1264\unexpanded\def\stopignorespaces
1265  {\ifcase\c_spac_ignore_spaces \or
1266     \ifhmode
1267       \doloop\spac_ignore_spaces_body
1268     \fi
1269   \fi
1270   \advance\c_spac_ignore_spaces\minusone}
1271
1272\def\spac_ignore_spaces_body
1273  {\ifzeropt\lastskip
1274     \exitloop
1275   \else\ifdim\lastskip=\s_spac_ignore_spaces
1276     \unskip
1277     \exitloop
1278   \else
1279     \unskip
1280   \fi\fi}
1281
1282%D \macros
1283%D   {obeyfollowingtoken}
1284
1285\def\obeyfollowingtoken{{}}  % end \cs scanning
1286
1287%D Something new:
1288
1289\unexpanded\def\interwordspacebefore{\wordboundary\zwnj\hskip\interwordspace\relax}
1290\unexpanded\def\interwordspaceafter {\hskip\interwordspace\relax\zwnj\wordboundary}
1291
1292\unexpanded\def\interwordspacesbefore#1{\dofastloopcs{#1}\interwordspacebefore}
1293\unexpanded\def\interwordspacesafter #1{\dofastloopcs{#1}\interwordspaceafter}
1294\unexpanded\def\interwordspaces      #1{\wordboundary\zwnj\dofastloopcs{\numexpr#1+\minusone}\interwordspaceafter}
1295
1296\protect \endinput
1297