summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/supp-box.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/supp-box.mkiv')
-rw-r--r--Master/texmf-dist/tex/context/base/supp-box.mkiv1603
1 files changed, 888 insertions, 715 deletions
diff --git a/Master/texmf-dist/tex/context/base/supp-box.mkiv b/Master/texmf-dist/tex/context/base/supp-box.mkiv
index f449e1d76b4..de1da677a88 100644
--- a/Master/texmf-dist/tex/context/base/supp-box.mkiv
+++ b/Master/texmf-dist/tex/context/base/supp-box.mkiv
@@ -5,7 +5,7 @@
%D subtitle=Boxes,
%D author=Hans Hagen,
%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
@@ -17,6 +17,51 @@
\registerctxluafile{supp-box}{1.001}
+% This file is partially cleaned up.
+
+% handy to have
+%
+% \hbox to \hsize
+% {\en
+% \switchnaarkorps[5pt]%
+% \emergencystretch2em
+% \dimen0=\baselineskip
+% \baselineskip=\dimen0 plus 1pt
+% \hsize=.2\hsize
+% \vsize=2\hsize
+% \ruledvbox to \vsize{\input tufte \par}\hss
+% \ruledvbox to \vsize{\input tufte \par\kern-\prevdepth}\hss
+% \ruledvbox to \vsize{\input tufte \par\kern0pt}\hss
+% \ruledvbox to \vsize{\input tufte \par\vfill}\hss
+% \ruledvbox to \vsize{\input tufte \par\kern-\prevdepth\vfill}}
+%
+% \hbox to \hsize
+% {\en
+% \switchnaarkorps[5pt]%
+% \emergencystretch2em
+% \dimen0=\baselineskip
+% \baselineskip=\dimen0 plus 1pt
+% \hsize=.18\hsize
+% \vsize=2.5\hsize
+% \setbox0=\vbox{\input tufte\relax}%
+% \ruledvbox to \vsize{\unvcopy0}\hss
+% \ruledvbox to \vsize{\unvcopy0\kern-\dp0}\hss
+% \ruledvbox to \vsize{\unvcopy0\kern0pt}\hss
+% \ruledvbox to \vsize{\unvcopy0\vfill}\hss
+% \ruledvbox to \vsize{\unvcopy0\kern-\dp0\vfill}}
+
+%D \macros
+%D {dontcomplain}
+%D
+%D The next macro suppresses over- and underfull messages which
+%D often makes sense when we deal with boxes.
+
+\unexpanded\def\dontcomplain
+ {\hbadness\plustenthousand
+ \vbadness\plustenthousand
+ \hfuzz \maxdimen
+ \vfuzz \maxdimen}
+
%D This module implements some box manipulation macros. Some
%D are quite simple, some are more advanced and when understood
%D well, all can be of use.
@@ -35,12 +80,13 @@
\def\strutwd{\wd\strutbox}
%D \macros
-%D {resetbox, emptybox}
+%D {voidbox,nextbox}
%D
%D Let's start with an easy one. The next macro hides the
%D ugly \type {@} in \type {\voidb@x}.
-\ifx\voidbox\undefined \newbox\voidbox \fi
+\ifdefined\voidbox \else \newbox\voidbox \fi
+\ifdefined\nextbox \else \newbox\nextbox \fi
%D \macros
%D {nextdepth}
@@ -59,13 +105,15 @@
%D reducing the dimensions of a box to zero. The most resolute
%D one is presented first.
-\def\smashbox#1%
+\unexpanded\def\smashbox#1%
{\wd#1\zeropoint
\ht#1\zeropoint
\dp#1\zeropoint}
-\def\smashboxed#1%
- {\smashbox{#1}%
+\unexpanded\def\smashboxed#1%
+ {\wd#1\zeropoint
+ \ht#1\zeropoint
+ \dp#1\zeropoint
\box#1\relax}
%D \macros
@@ -74,45 +122,47 @@
%D Smashing can be used for overlaying boxes. Depending on
%D the mode, horizontal or vertical, one can use:
-\def\hsmashbox#1%
+\unexpanded\def\hsmashbox#1%
{\wd#1\zeropoint}
-\def\vsmashbox#1%
+\unexpanded\def\vsmashbox#1%
{\ht#1\zeropoint
\dp#1\zeropoint}
%D The next implementation is less sensitive for spurious
%D spaces.
-\newcount\registercount
+\newcount\c_boxes_register
-\def\smashbox
- {\afterassignment\dosmashbox\registercount}
+\unexpanded\def\smashbox
+ {\afterassignment\syst_boxes_smash_boxes_register\c_boxes_register}
-\def\dosmashbox
- {\wd\registercount\zeropoint
- \ht\registercount\zeropoint
- \dp\registercount\zeropoint}
+\def\syst_boxes_smash_boxes_register
+ {\wd\c_boxes_register\zeropoint
+ \ht\c_boxes_register\zeropoint
+ \dp\c_boxes_register\zeropoint}
-\def\smashedbox
- {\afterassignment\thesmashedbox\registercount}
+\unexpanded\def\hsmashbox
+ {\afterassignment\syst_boxes_hsmashed_boxes_register\c_boxes_register}
-\def\thesmashedbox
- {\dosmashbox
- \box\registercount}
+\def\syst_boxes_hsmashed_boxes_register
+ {\wd\c_boxes_register\zeropoint}
-\def\hsmashbox
- {\afterassignment\dohsmashbox\registercount}
+\unexpanded\def\vsmashbox
+ {\afterassignment\syst_boxes_vsmashed_boxes_register\c_boxes_register}
-\def\dohsmashbox
- {\wd\registercount\zeropoint}
+\def\syst_boxes_vsmashed_boxes_register
+ {\ht\c_boxes_register\zeropoint
+ \dp\c_boxes_register\zeropoint}
-\def\vsmashbox
- {\afterassignment\dovsmashbox\registercount}
+\unexpanded\def\smashedbox
+ {\afterassignment\syst_boxes_smashed_boxes_register\c_boxes_register}
-\def\dovsmashbox
- {\ht\registercount\zeropoint
- \dp\registercount\zeropoint}
+\unexpanded\def\syst_boxes_smashed_boxes_register
+ {\wd\c_boxes_register\zeropoint
+ \ht\c_boxes_register\zeropoint
+ \dp\c_boxes_register\zeropoint
+ \box\c_boxes_register}
%D \macros
%D {hsmash,vsmash,
@@ -123,29 +173,28 @@
%D and smashed alternatives. The later ones reduce all
%D dimensions to zero.
-% Ok, but inefficient and/or catcode unsafe:
-%
-% \def\hsmash #1{\bgroup\setbox0=\normalhbox{#1}\hsmashbox0\box0\egroup}
-% \def\vsmash #1{\bgroup\setbox0=\normalvbox{#1}\vsmashbox0\box0\egroup}
-% \def\hsmashed#1{\bgroup\setbox0=\normalhbox{#1}\smashbox 0\box0\egroup}
-% \def\vsmashed#1{\bgroup\setbox0=\normalvbox{#1}\smashbox 0\box0\egroup}
-%
-% Better, but a waste of tokens:
-%
-% \def\hsmash {\bgroup\dowithnextbox{\hsmashbox\nextbox\flushnextbox\egroup}\normalhbox}
-% \def\vsmash {\bgroup\dowithnextbox{\vsmashbox\nextbox\flushnextbox\nextbox\egroup}\normalvbox}
-% \def\hsmashed{\bgroup\dowithnextbox{\smashbox \nextbox\flushnextbox\nextbox\egroup}\normalhbox}
-% \def\vsmashed{\bgroup\dowithnextbox{\smashbox \nextbox\flushnextbox\nextbox\egroup}\normalvbox}
-%
-% The best:
+\unexpanded\def\hsmash {\bgroup\dowithnextboxcs\syst_boxes_hsmashed_nextbox\hbox}
+\unexpanded\def\vsmash {\bgroup\dowithnextboxcs\syst_boxes_vsmashed_nextbox\vbox}
+\unexpanded\def\hsmashed{\bgroup\dowithnextboxcs\syst_boxes_smashed_nextbox \hbox}
+\unexpanded\def\vsmashed{\bgroup\dowithnextboxcs\syst_boxes_smashed_nextbox \vbox}
+
+\unexpanded\def\syst_boxes_hsmashed_nextbox
+ {\wd\nextbox\zeropoint
+ \box\nextbox
+ \egroup}
-\def\dosomesmash#1% (begin|end)group ipv (b|e)group ?
- {\bgroup\dowithnextbox{#1\nextbox\flushnextbox\egroup}}
+\unexpanded\def\syst_boxes_vsmashed_nextbox
+ {\ht\nextbox\zeropoint
+ \dp\nextbox\zeropoint
+ \box\nextbox
+ \egroup}
-\def\hsmash {\dosomesmash\hsmashbox\normalhbox}
-\def\vsmash {\dosomesmash\vsmashbox\normalvbox}
-\def\hsmashed{\dosomesmash\smashbox \normalhbox}
-\def\vsmashed{\dosomesmash\smashbox \normalvbox}
+\unexpanded\def\syst_boxes_smashed_nextbox
+ {\ht\nextbox\zeropoint
+ \dp\nextbox\zeropoint
+ \wd\nextbox\zeropoint
+ \box\nextbox
+ \egroup}
%D \macros
%D {smashedhbox,smashedvbox}
@@ -157,12 +206,17 @@
%D \smashedvbox to ... {...}
%D \stoptyping
-\def\dosmashedbox#1%
- %{#1\bgroup\dowithnextbox{\smashbox\nextbox\flushnextbox\egroup}#1}
- {#1\bgroup\dowithnextbox{\smashedbox\nextbox\egroup}#1}
+\unexpanded\def\smashedhbox{\hbox\bgroup\dowithnextboxcs\syst_boxes_smashed_nextbox\hbox}
+\unexpanded\def\smashedvbox{\vbox\bgroup\dowithnextboxcs\syst_boxes_smashed_nextbox\vbox}
+
+%D First we define a helper. We use a \LUATEX\ feature in order to avoid
+%D mathpalettes.
-\def\smashedhbox{\dosmashedbox\hbox}
-\def\smashedvbox{\dosmashedbox\vbox}
+\newcount\c_boxes_math_style
+
+\unexpanded\def\syst_boxes_math_set_nextbox#1%
+ {\c_boxes_math_style\mathstyle
+ \setbox\nextbox\hbox{$\mathsurround\zeropoint\triggermathstyle\c_boxes_math_style{#1}$}}
%D \macros
%D {smash}
@@ -172,40 +226,61 @@
%D math module (although the \type {\leavevmode} is not added
%D here).
-\def\smash
- {\futurelet\nexttoken\dosmash}
+\unexpanded\def\smash
+ {\begingroup
+ \futurelet\nexttoken\syst_boxes_smash}
-\def\dosmash
- {\ifx\nexttoken[\@EA\dodosmash\else\@EA\donosmash\fi}
+\def\syst_boxes_smash
+ {\ifx\nexttoken[%
+ \expandafter\syst_boxes_smash_yes
+ \else
+ \expandafter\syst_boxes_smash_nop
+ \fi}
-\def\donosmash
- {\dodosmash[hd]}
+\def\syst_boxes_smash_nop
+ {\edef\m_boxes_smash_options{hd}%
+ \futurelet\nexttoken\syst_boxes_smash_indeed}
-\def\dodosmash[#1]%
- {\edef\@@smash{#1}\futurelet\nexttoken\dododosmash}
+\def\syst_boxes_smash_yes[#1]%
+ {\edef\m_boxes_smash_options{#1}%
+ \futurelet\nexttoken\syst_boxes_smash_indeed}
-\def\dododosmash % if needed we can avoid the \next
+\def\syst_boxes_smash_indeed
{\ifmmode
- \def\next##1{\mathpalette\mathsm@sh{##1}}%
+ \expandafter\syst_boxes_smash_math
\else\ifx\nexttoken\bgroup
- \let\next\finsm@sh
+ \doubleexpandafter\syst_boxes_smash_hbox
\else
- \def\next##1{\finsm@sh{##1}}%
- \fi\fi
- \next}
+ \doubleexpandafter\syst_boxes_smash_text
+ \fi\fi}
-\def\mathsm@sh#1#2% redefined plain macro
- {\finsm@sh{$\mathsurround\zeropoint#1{#2}$}}
+\def\syst_boxes_smash_math#1%
+ {\syst_boxes_math_set_nextbox{#1}%
+ \syst_boxes_smash_process}
-\def\makesm@sh#1% redefined plain macro (handles t b h d w)
- {\if#1w\nextboxwd\zeropoint\else
- \if#1h\nextboxht\zeropoint\else
- \if#1d\nextboxdp\zeropoint\else
- \if#1t\nextboxht\zeropoint\else
- \if#1b\nextboxdp\zeropoint\fi\fi\fi\fi\fi}
+\def\syst_boxes_smash_hbox
+ {\dowithnextboxcs\syst_boxes_smash_process\hbox}
-\def\finsm@sh % redefined plain macro
- {\dowithnextbox{\@EA\handletokens\@@smash\with\makesm@sh\flushnextbox}\normalhbox}
+\def\syst_boxes_smash_text#1%
+ {\setbox\nextbox\hbox{#1}%
+ \syst_boxes_smash_process}
+
+\def\syst_boxes_smash_process
+ {\expandafter\syst_boxes_smash_process_option\m_boxes_smash_options\relax
+ \box\nextbox
+ \endgroup}
+
+\def\syst_boxes_s_w{\wd\nextbox\zeropoint}
+\def\syst_boxes_s_h{\ht\nextbox\zeropoint}
+\def\syst_boxes_s_d{\dp\nextbox\zeropoint}
+\def\syst_boxes_s_t{\ht\nextbox\zeropoint}
+\def\syst_boxes_s_b{\dp\nextbox\zeropoint}
+
+\def\syst_boxes_smash_process_option#1%
+ {\ifx#1\relax\else
+ \csname boxes_s_#1\endcsname
+ \expandafter\syst_boxes_smash_process_option
+ \fi}
%D \starttabulate[|l|l|]
%D \NC w \NC \ruledhbox{\smash [w]{This is some great smashing, isn't it?}} \NC \NR
@@ -220,44 +295,78 @@
%D
%D The next implementation of \type {\phantom} cum suis does
%D not grab an argument in the non||math case, which is better.
-
-\unexpanded\def\phantom {\ph@nt\nextbox\nextbox\nextbox}
-\unexpanded\def\vphantom{\ph@nt\nextbox\nextbox\voidbox}
-\unexpanded\def\hphantom{\ph@nt\voidbox\voidbox\nextbox}
-
+%D
%D Due to a complicated call to \type {\mathpallete} and
%D thereby \type {\mathchoice}, the next macro looks ugly.
%D We also take care of non||braced arguments.
-\def\ph@nt#1#2#3%
- {\def\doph@nt
- {\ifmmode
- \def\mathph@nt####1####2{\makeph@nt#1#2#3{$\mathsurround\zeropoint####1{####2}$}}%
- \def\nextph@nt{\mathpalette\mathph@nt}%
- \else\ifx\nextph@nt\bgroup
- \def\nextph@nt{\makeph@nt#1#2#3}%
- \else
- \def\nextph@nt####1{\makeph@nt#1#2#3{####1}}%
- \fi\fi
- \nextph@nt}%
- \futurelet\nextph@nt\doph@nt}
+\unexpanded\def\phantom {\begingroup\futurelet\nexttoken\syst_boxes_phantom_indeed }
+\unexpanded\def\vphantom{\begingroup\futurelet\nexttoken\syst_boxes_phantom_indeed_v}
+\unexpanded\def\hphantom{\begingroup\futurelet\nexttoken\syst_boxes_phantom_indeed_h}
-\def\makeph@nt#1#2#3%
- {\begingroup
- \dowithnextbox
- {\setbox\scratchbox\emptyhbox
- \ht\scratchbox\ht#1%
- \dp\scratchbox\dp#2%
- \wd\scratchbox\wd#3%
- \box\scratchbox
- \endgroup}
- \normalhbox}
+\def\syst_boxes_phantom_math #1{\syst_boxes_math_set_nextbox{#1}\syst_boxes_phantom_make }
+\def\syst_boxes_phantom_math_v#1{\syst_boxes_math_set_nextbox{#1}\syst_boxes_phantom_make_v}
+\def\syst_boxes_phantom_math_h#1{\syst_boxes_math_set_nextbox{#1}\syst_boxes_phantom_make_h}
+
+\def\syst_boxes_phantom_hbox {\dowithnextboxcs\syst_boxes_phantom_make \hbox} % always hbox
+\def\syst_boxes_phantom_hbox_v{\dowithnextboxcs\syst_boxes_phantom_make_v\hbox} % always hbox
+\def\syst_boxes_phantom_hbox_h{\dowithnextboxcs\syst_boxes_phantom_make_h\hbox} % always hbox
+
+\def\syst_boxes_phantom_text #1{\setbox\nextbox\hbox{#1}\syst_boxes_phantom_make } % always hbox
+\def\syst_boxes_phantom_text_v#1{\setbox\nextbox\hbox{#1}\syst_boxes_phantom_make_v} % always hbox
+\def\syst_boxes_phantom_text_h#1{\setbox\nextbox\hbox{#1}\syst_boxes_phantom_make_h} % always hbox
+
+\def\syst_boxes_phantom_indeed
+ {\ifmmode
+ \expandafter\syst_boxes_phantom_math
+ \else\ifx\nexttoken\bgroup
+ \doubleexpandafter\syst_boxes_phantom_hbox
+ \else
+ \doubleexpandafter\syst_boxes_phantom_text
+ \fi\fi}
+
+\def\syst_boxes_phantom_indeed_v
+ {\ifmmode
+ \expandafter\syst_boxes_phantom_math_v
+ \else\ifx\nexttoken\bgroup
+ \doubleexpandafter\syst_boxes_phantom_hbox_v
+ \else
+ \doubleexpandafter\syst_boxes_phantom_text_v
+ \fi\fi}
+
+\def\syst_boxes_phantom_indeed_h
+ {\ifmmode
+ \expandafter\syst_boxes_phantom_math_h
+ \else\ifx\nexttoken\bgroup
+ \doubleexpandafter\syst_boxes_phantom_hbox_h
+ \else
+ \doubleexpandafter\syst_boxes_phantom_text_h
+ \fi\fi}
+
+\def\syst_boxes_phantom_make
+ {\setbox\scratchbox\emptyhbox
+ \ht\scratchbox\ht\nextbox
+ \dp\scratchbox\dp\nextbox
+ \wd\scratchbox\wd\nextbox
+ \box\scratchbox
+ \endgroup}
+
+\def\syst_boxes_phantom_make_v
+ {\setbox\scratchbox\emptyhbox
+ \ht\scratchbox\ht\nextbox
+ \dp\scratchbox\dp\nextbox
+ \box\scratchbox
+ \endgroup}
-\let\finph@nt\undefined
+\def\syst_boxes_phantom_make_h
+ {\setbox\scratchbox\emptyhbox
+ \wd\scratchbox\wd\nextbox
+ \box\scratchbox
+ \endgroup}
%D We also define plain's \type {\mathstrut}.
-\unexpanded\def\mathstrut{\vphantom{(}}
+\unexpanded\def\mathstrut{\vphantom(} % can be made faster by inlining
%D \macros
%D {getboxheight}
@@ -293,9 +402,9 @@
%D it accepts \type {{12}} as well as \type {12} as box
%D number.
-\def\getboxheight#1\of#2\box#3%
- {\def\next{#1\dimexpr\ht\registercount+\dp\registercount\relax}%
- \afterassignment\next\registercount=#3}
+\unexpanded\def\getboxheight#1\of#2\box#3%
+ {\def\next{#1\dimexpr\ht\c_boxes_register+\dp\c_boxes_register\relax}%
+ \afterassignment\next\c_boxes_register=#3}
%D For a long time the following three macros were part of
%D the grid snapping core module, but it makes more sense to
@@ -345,7 +454,7 @@
\newcount\noflines
\newdimen\noflinesheight
-\def\getnoflines#1%
+\unexpanded\def\getnoflines#1%
{\noflinesheight#1\relax
\ifzeropt\noflinesheight
\noflines\zerocount
@@ -361,7 +470,7 @@
\advance\noflines\minusone
\fi\fi}
-\def\getroundednoflines#1%
+\unexpanded\def\getroundednoflines#1%
{\noflinesheight#1\relax
\ifzeropt\noflinesheight
\noflines\zerocount
@@ -375,7 +484,7 @@
\noflines\noflinesheight
\fi\fi}
-\def\getrawnoflines#1%
+\unexpanded\def\getrawnoflines#1%
{\noflinesheight#1\relax
\ifzeropt\noflinesheight
\noflines\zerocount
@@ -439,12 +548,12 @@
\reshapebox{\global\advance\scratchcounter\plusone}%
\expandafter\egroup\expandafter\noflines\the\scratchcounter\relax}
-\def\determinenoflines
+\unexpanded\def\determinenoflines
{\bgroup
\forgetall
\let\crlf\endgraf
\let\\\endgraf
- \dowithnextbox{\dodeterminenoflines}\vbox}
+ \dowithnextboxcs\dodeterminenoflines\vbox}
%D \macros
%D {doiftextelse, doiftext}
@@ -458,19 +567,27 @@
%D \doiftext {data} {then branch}
%D \stoptyping
-\def\doiftextelse#1%
- {\bgroup
- \setbox\scratchbox\normalhbox
+\unexpanded\def\doiftextelse#1%
+ {\begingroup
+ \setbox\scratchbox\hbox
{\settrialtypesetting
\ignorespaces#1\removeunwantedspaces}%
\ifzeropt\wd\scratchbox
- \egroup\@EA\secondoftwoarguments
+ \endgroup\expandafter\secondoftwoarguments
\else
- \egroup\@EA\firstoftwoarguments
+ \endgroup\expandafter\firstoftwoarguments
\fi}
-\def\doiftext#1#2%
- {\doiftextelse{#1}{#2}\donothing}
+\unexpanded\def\doiftext#1%
+ {\begingroup
+ \setbox\scratchbox\hbox
+ {\settrialtypesetting
+ \ignorespaces#1\removeunwantedspaces}%
+ \ifzeropt\wd\scratchbox
+ \endgroup\expandafter\gobbleoneargument
+ \else
+ \endgroup\expandafter\firstofoneargument
+ \fi}
%D \macros
%D {dowithnextbox,nextbox}
@@ -495,8 +612,8 @@
%D
%D \starttyping
%D \def\getfloat%
-%D {\def\handlefloat{...\flushnextbox...}
-%D \dowithnextbox\handlefloat\normalvbox}
+%D {\def\handlefloat{...\box\nextbox...}
+%D \dowithnextboxcs\handlefloat\vbox}
%D \stoptyping
%D
%D instead of:
@@ -510,51 +627,46 @@
%D is needed because \type{\afterassignment} is executed inside
%D the box.
-\ifx\nextbox\undefined \newbox\nextbox \fi
-
-\long\def\dowithnextbox#1%
- {\long\def\dodowithnextbox{#1}%
- \afterassignment\dododowithnextbox
+\unexpanded\def\dowithnextbox#1%
+ {\def\syst_boxes_with_next_box{#1}%
+ \afterassignment\syst_boxes_with_next_box_indeed
\setbox\nextbox}
-\def\dododowithnextbox
- {\aftergroup\dodowithnextbox}
+\def\syst_boxes_with_next_box_indeed
+ {\aftergroup\syst_boxes_with_next_box}
-\long\def\dowithnextboxcs#1%
- {\let\dodowithnextbox#1%
- \afterassignment\dododowithnextbox
+\unexpanded\def\dowithnextboxcs#1%
+ {\let\syst_boxes_with_next_box#1%
+ \afterassignment\syst_boxes_with_next_box_indeed
\setbox\nextbox}
-\def\dododowithnextbox
- {\aftergroup\dodowithnextbox}
-
%D So in fact we get:
%D
%D \starttyping
-%D \setbox\nextbox { \aftergroup\dodowithnextbox ... }
+%D \setbox\nextbox { \aftergroup\syst_boxes_with_next_box ... }
%D \stoptyping
%D
%D or
%D
%D \starttyping
-%D \setbox\nextbox { ... } \dodowithnextbox
+%D \setbox\nextbox { ... } \syst_boxes_with_next_box
%D \stoptyping
%D
%D A slower but more versatile implementation is:
%D
%D \starttyping
%D \long\def\dowithnextbox#1#2%
-%D {\long\def\dodowithnextbox{#1}%
-%D \ifx#2\normalhbox
-%D \afterassignment\dododowithnextbox
-%D \else\ifx#2\normalvbox
-%D \afterassignment\dododowithnextbox
+%D {\long\def\syst_boxes_with_next_box{#1}%
+%D \ifx#2\hbox
+%D \afterassignment\syst_boxes_with_next_box_indeed
+%D \else\ifx#2\vbox
+%D \afterassignment\syst_boxes_with_next_box_indeed
%D \else\ifx#2\normalvtop
-%D \afterassignment\dododowithnextbox
+%D \afterassignment\syst_boxes_with_next_box_indeed
%D \else\ifx#2\normalvcenter
-%D \afterassignment\dododowithnextbox
+%D \afterassignment\syst_boxes_with_next_box_indeed
%D \else
-%D \afterassignment\dodowithnextbox
+%D \afterassignment\syst_boxes_with_next_box
%D \fi\fi\fi\fi
%D \setbox\nextbox#2}
%D \stoptyping
@@ -573,7 +685,7 @@
\def\nextboxdp {\dp\nextbox}
\def\nextboxhtdp {\dimexpr\ht\nextbox+\dp\nextbox\relax}
-\def\flushnextbox{\box\nextbox}
+\unexpanded\def\flushnextbox{\box\nextbox}
%D \macros
%D {dowithnextboxcontent}
@@ -588,38 +700,20 @@
%D
%D {\em todo: Search source for potential usage!}
-\long\def\dowithnextboxcontent#1#2% inside, after
- {\long\def\dodowithnextbox{#2}%
- \def\dododowithnextbox{#1\aftergroup\dodowithnextbox}%
- \afterassignment\dododowithnextbox
+\unexpanded\def\dowithnextboxcontent#1#2% inside, after
+ {\def\syst_boxes_with_next_box_one{#2}%
+ \def\syst_boxes_with_next_box_two{#1}%
+ \afterassignment\syst_boxes_with_next_box_content_indeed
\setbox\nextbox}
-%D Now we can redefine \type {\dowithnextbox} as follows:
-%D
-%D \starttyping
-%D \def\dowithnextbox{\dowithnextboxcontent\empty}
-%D \stoptyping
-%D
-%D But since this macro is used often and since this implementation
-%D is slower, we will not use that definition.
+\unexpanded\def\dowithnextboxcontentcs#1#2% inside, after
+ {\let\syst_boxes_with_next_box_one#2%
+ \let\syst_boxes_with_next_box_two#1%
+ \afterassignment\syst_boxes_with_next_box_content_indeed
+ \setbox\nextbox}
-% maybe:
-%
-% depending on the size of the action, about 10% faster
-%
-% \newtoks\nextboxtoks
-%
-% \def\dowithnextbox {\afterassignment\redowithnextbox\nextboxtoks}
-% \def\redowithnextbox {\afterassignment\dododowithnextbox\setbox\nextbox}
-% \def\dododowithnextbox{\aftergroup\dodowithnextbox}
-% \def\dodowithnextbox {\the\nextboxtoks}
-%
-% \long\def\dowithnextboxcontent#1% #2% inside, after
-% {\def\dododowithnextbox{#1\aftergroup\dodowithnextbox}%
-% \afterassignment\redowithnextboxcontent\nextboxtoks}
-%
-% \def\redowithnextboxcontent
-% {\afterassignment\dododowithnextbox\setbox\nextbox}
+\def\syst_boxes_with_next_box_content_indeed
+ {\syst_boxes_with_next_box_two\aftergroup\syst_boxes_with_next_box_one}
%D \macros
%D {llap, rlap, tlap, blap, clap}
@@ -627,13 +721,13 @@
%D Some well known friends, but we implement them our own
%D way. We want the macros to work in both math and text mode.
-\def\dodorlap{\normalhbox to \zeropoint{\flushnextbox\normalhss}\endgroup}
-\def\dodollap{\normalhbox to \zeropoint{\normalhss\flushnextbox}\endgroup}
-\def\dodoclap{\normalhbox to \zeropoint{\normalhss\flushnextbox\normalhss}\endgroup}
+\def\dodorlap{\hbox to \zeropoint{\box\nextbox\normalhss}\endgroup}
+\def\dodollap{\hbox to \zeropoint{\normalhss\box\nextbox}\endgroup}
+\def\dodoclap{\hbox to \zeropoint{\normalhss\box\nextbox\normalhss}\endgroup}
-\def\dorlap{\begingroup\dowithnextboxcs\dodorlap\normalhbox}
-\def\dollap{\begingroup\dowithnextboxcs\dodollap\normalhbox}
-\def\doclap{\begingroup\dowithnextboxcs\dodoclap\normalhbox}
+\def\dorlap{\begingroup\dowithnextboxcs\dodorlap\hbox}
+\def\dollap{\begingroup\dowithnextboxcs\dodollap\hbox}
+\def\doclap{\begingroup\dowithnextboxcs\dodoclap\hbox}
\def\domathclap{\mathpalette\dodomathclap} \def\dodomathclap#1#2{\doclap{$\mathsurround\zeropoint#1#2$}}
\def\domathllap{\mathpalette\dodomathllap} \def\dodomathllap#1#2{\dollap{$\mathsurround\zeropoint#1#2$}}
@@ -643,11 +737,11 @@
\unexpanded\def\llap{\mathortext\domathllap\dollap}
\unexpanded\def\clap{\mathortext\domathclap\doclap}
-\def\dodotlap{\normalvbox to \zeropoint{\normalvss\flushnextbox}\endgroup}
-\def\dodoblap{\normalvbox to \zeropoint{\flushnextbox\normalvss}\endgroup}
+\def\dodotlap{\vbox to \zeropoint{\normalvss\box\nextbox}\endgroup}
+\def\dodoblap{\vbox to \zeropoint{\box\nextbox\normalvss}\endgroup}
-\def\tlap{\begingroup\dowithnextboxcs\dodotlap\normalvbox}
-\def\blap{\begingroup\dowithnextboxcs\dodoblap\normalvbox}
+\unexpanded\def\tlap{\begingroup\dowithnextboxcs\dodotlap\vbox}
+\unexpanded\def\blap{\begingroup\dowithnextboxcs\dodoblap\vbox}
%D \macros
%D {beginofshapebox,
@@ -694,7 +788,7 @@
%D
%D \reshapebox
%D {\doglobal\increment\LineNumber
-%D \normalhbox{\llap{\LineNumber\hskip2em}\box\shapebox}}
+%D \hbox{\llap{\LineNumber\hskip2em}\box\shapebox}}
%D
%D \flushshapebox
%D \stopbuffer
@@ -716,7 +810,7 @@
%D
%D \reshapebox
%D {\doglobal\increment\LineNumber
-%D \normalhbox
+%D \hbox
%D {\llap{\LineNumber\ (\NumberOfLines)\hskip2em}%
%D \box\shapebox}%
%D \doglobal\decrement\NumberOfLines}
@@ -739,7 +833,7 @@
%D
%D \reshapebox
%D {\doglobal\increment\LineNumber
-%D \normalhbox{\llap{$\star$\hskip1em}\box\shapebox}%
+%D \hbox{\llap{$\star$\hskip1em}\box\shapebox}%
%D \doglobal\decrement\NumberOfLines}
%D
%D \flushshapebox
@@ -787,7 +881,7 @@
\def\shapesignal{.12345678pt} % or 12345sp
-\def\reshapebox#1%
+\unexpanded\def\reshapebox#1%
{\doreshapebox
{#1}%
{\penalty\shapepenalty}%
@@ -803,7 +897,7 @@
\ifzeropt\ht\oldshapebox % \ifdim\ht\oldshapebox=\zeropoint
\setbox\newshapebox\emptyvbox
\else
- \setbox\newshapebox\normalvbox
+ \setbox\newshapebox\vbox
{\unvcopy\oldshapebox
\setbox\newshapebox\emptybox
\shapecounter\zerocount
@@ -815,25 +909,25 @@
% We will turn this into a \MKIV\ variant.
-\def\insertshapesignal
- {\normalhbox to \shapesignal{\strut\hss}% plus \strut
+\unexpanded\def\insertshapesignal
+ {\hbox to \shapesignal{\strut\hss}% plus \strut
\prevdepth\strutdp} % never \nointerlineskip
-\def\restoreshapebox % compensates for the signal
+\unexpanded\def\restoreshapebox % compensates for the signal
{\global\setbox\tmpshapebox\vbox{\vskip-\lineheight\unvcopy\oldshapebox}}
\def\dodoreshapebox#1#2#3#4% \shapebox, \shapepenalty, \shapekern, \shapeskip
- {\ifnum\lastnodetype=\@@gluenode
+ {\ifnum\lastnodetype=\gluenodecode
\shapeskip\lastskip
- \global\setbox\tmpshapebox\normalvbox{#4\unvbox\tmpshapebox}%
+ \global\setbox\tmpshapebox\vbox{#4\unvbox\tmpshapebox}%
\unskip
- \else\ifnum\lastnodetype=\@@kernnode
+ \else\ifnum\lastnodetype=\kernnodecode
\shapekern\lastkern
- \global\setbox\tmpshapebox\normalvbox{#3\unvbox\tmpshapebox}%
+ \global\setbox\tmpshapebox\vbox{#3\unvbox\tmpshapebox}%
\unkern
- \else\ifnum\lastnodetype=\@@penaltynode
+ \else\ifnum\lastnodetype=\penaltynodecode
\shapepenalty\lastpenalty
- \global\setbox\tmpshapebox\normalvbox{#2\unvbox\tmpshapebox}%
+ \global\setbox\tmpshapebox\vbox{#2\unvbox\tmpshapebox}%
\unpenalty
\else\ifnum\lastnodetype<\zeropoint
\exitloop
@@ -844,7 +938,7 @@
\exitloop
\else
\shapecounter\zerocount
- \global\setbox\tmpshapebox\normalvbox{#1\unvbox\tmpshapebox}%
+ \global\setbox\tmpshapebox\vbox{#1\unvbox\tmpshapebox}%
\fi\fi
\fi\fi\fi\fi
\ifnum\shapecounter>100 % can be less
@@ -856,21 +950,21 @@
\advance\shapecounter \plusone
\fi}
-\def\beginofshapebox
- {\setbox\oldshapebox\normalvbox
+\unexpanded\def\beginofshapebox
+ {\setbox\oldshapebox\vbox
\bgroup
\reshapingboxtrue
\the\everyshapebox
\insertshapesignal}
-\def\endofshapebox
+\unexpanded\def\endofshapebox
{\endgraf
\egroup}
\let\beginshapebox\beginofshapebox
\let\endshapebox \endofshapebox
-\def\flushshapebox
+\unexpanded\def\flushshapebox
{\bgroup
\ifzeropt\ht\newshapebox % \ifdim\ht\newshapebox=\zeropoint
\else
@@ -921,7 +1015,7 @@
%
% \omlijnd[offset=0pt,hoogte=8mm,uitlijnen={rechts,laho}]{\bfa test}
-\def\innerflushshapebox
+\unexpanded\def\innerflushshapebox
{\ifzeropt\ht\newshapebox \else
\unvcopy\newshapebox\relax % unvcopy ! else spacing problem
% \kern-\dp\newshapebox\relax
@@ -943,15 +1037,15 @@
%D
%D When constructing a new box, using the content of \type
%D {\shapebox}, one can best use \type {\shapedhbox} instead
-%D of \type {\normalhbox}, since it manages the height and depth of
+%D of \type {\hbox}, since it manages the height and depth of
%D the line.
-\def\shapedhbox % lines with non strutted dimensions have
- {\expanded{\dowithnextbox % interlineskip so if we want the original
- {\nextboxht\the\ht\shapebox % spacing, we need to preserve the original
- \nextboxdp\the\dp\shapebox % height and depth which is definitely
- \noexpand\flushnextbox}} % needed if we apply struts to the 'new'
- \normalhbox} % box or do something that changed ist size
+\unexpanded\def\shapedhbox % lines with non strutted dimensions have
+ {\expanded{\dowithnextbox % interlineskip so if we want the original
+ {\dp\nextbox\the\ht\shapebox % spacing, we need to preserve the original
+ \dp\nextbox\the\dp\shapebox % height and depth which is definitely
+ \box\nextbox}} % needed if we apply struts to the 'new'
+ \hbox} % box or do something that changed ist size
%D \macros
%D {hyphenatedword,
@@ -969,7 +1063,7 @@
\def\doshowhyphenatednextbox
{\ctxcommand{showhyphenatedinlist(tex.box[\number\nextbox].list)}}
-\def\showhyphens{\dowithnextbox\doshowhyphenatednextbox\hbox}
+\unexpanded\def\showhyphens{\dowithnextboxcs\doshowhyphenatednextbox\hbox}
%D The following macros are seldom used but handy for tracing.
%D
@@ -983,9 +1077,9 @@
{\ctxcommand{hyphenatedlist(tex.box[\number\nextbox])}%
\unhbox\nextbox}
-\def\hyphenatedword {\dowithnextbox\dohyphenatednextbox \hbox}
-\def\hyphenatedpar {\dowithnextbox\dohyphenatednextbox \hbox}
-\def\hyphenatedfile#1{\dowithnextbox\dohyphenatednextbox \hbox{\readfile{#1}\donothing\donothing}}
+\unexpanded\def\hyphenatedword {\dowithnextboxcs\dohyphenatednextbox \hbox}
+\unexpanded\def\hyphenatedpar {\dowithnextboxcs\dohyphenatednextbox \hbox}
+\unexpanded\def\hyphenatedfile#1{\dowithnextboxcs\dohyphenatednextbox \hbox{\readfile{#1}\donothing\donothing}}
%D \macros
%D {processtokens}
@@ -1015,6 +1109,22 @@
%D The list of tokens may contain spaces, while \type{\\},
%D \type{{}} and \type{\ } are handled as space too.
+\unexpanded\def\processtokens#1#2#3#4#5%
+ {\begingroup
+ \def\lastcharacter{\lastcharacter}%
+ \def\space{ }%
+ \let\\=\space
+ \def\before {#1}%
+ \def\between{#2}%
+ \def\after {#3}%
+ \def\white {#4}%
+ \let\savedbefore\before
+ \doprocesstokens#5\lastcharacter
+ \endgroup}
+
+\def\doprocesstokens% the space after = is essential
+ {\afterassignment\dodoprocesstokens\let\nextprocessedtoken= }
+
\def\dodoprocesstokens
{\ifx\nextprocessedtoken\lastcharacter
\after
@@ -1038,22 +1148,6 @@
\fi\fi
\nextprocessedtoken}
-\def\doprocesstokens% the space after = is essential
- {\afterassignment\dodoprocesstokens\let\nextprocessedtoken= }
-
-\def\processtokens#1#2#3#4#5%
- {\begingroup
- \def\lastcharacter{\lastcharacter}%
- \def\space{ }%
- \let\\=\space
- \def\before {#1}%
- \def\between{#2}%
- \def\after {#3}%
- \def\white {#4}%
- \let\savedbefore\before
- \doprocesstokens#5\lastcharacter
- \endgroup}
-
%D \macros
%D {doboundtext}
%D
@@ -1073,16 +1167,16 @@
%D complex macro than needed at first sight.
\def\dodoboundtext#1%
- {\setbox0\normalhbox{#1}%
+ {\setbox0\hbox{#1}%
\advance\scratchdimen -\wd0
\ifdim\scratchdimen>\zeropoint\relax#1\fi}%
\def\doboundtext#1#2#3% still used?
- {\normalhbox
- {\setbox\scratchbox\normalhbox{#1}%
+ {\hbox
+ {\setbox\scratchbox\hbox{#1}%
\scratchdimen#2\relax
\ifdim\wd\scratchbox>\scratchdimen
- \setbox\scratchbox\normalhbox{#3}%
+ \setbox\scratchbox\hbox{#3}%
\advance\scratchdimen -\wd\scratchbox
\handletokens#1\with\dodoboundtext
\fi
@@ -1104,113 +1198,73 @@
%D When no width is given, the whole text comes available. The
%D sentinel is optional. This is about the third version.
-\ifx\fakecompoundhyphen\undefined \let\fakecompoundhyphen\relax \fi
-\ifx\veryraggedright \undefined \def\veryraggedright{\raggedright} \fi
-
-%D The simple alternative is as follows:
-%D
-%D \starttyping
-%D \unexpanded\def\limitatetext%
-%D {\bgroup % evt \setstrut
-%D \forgetall
-%D \fakecompoundhyphen % dangerous ! ! ! ! ! ! ! ! !
-%D \dowithnextbox\dolimitatetext\normalhbox}
-%D
-%D \def\dolimitatetext#1#2%
-%D {\doifelsenothing{#1}
-%D {\unhbox\nextbox}
-%D {\widowpenalty=0
-%D \clubpenalty=0
-%D \scratchdimen=#1\relax
-%D \ifdim\nextboxwd>\scratchdimen
-%D \setbox\scratchbox=\normalhbox{ #2}%
-%D \advance\scratchdimen by -\wd\scratchbox
-%D \setbox\nextbox=\normalvbox
-%D {\hsize=\scratchdimen
-%D \hfuzz\maxdimen
-%D \veryraggedright
-%D \strut\unhcopy\nextbox}%
-%D \ifdim\nextboxht>\strutht \else
-%D \setbox\scratchbox\emptyhbox % overfull and not split
-%D \fi
-%D \setbox\nextbox=\normalvbox % if omitted: missing brace reported
-%D {\splittopskip=\openstrutheight
-%D \setbox\nextbox=\vsplit\nextbox to \strutht
-%D \unvbox\nextbox
-%D \setbox\nextbox=\lastbox
-%D \global\setbox1=\normalhbox
-%D {\unhbox\nextbox\unskip\kern\zeropoint\box\scratchbox\unskip}}%
-%D \unhbox1
-%D \else
-%D \unhbox\nextbox
-%D \fi}%
-%D \egroup}
-%D \stoptyping
-%D
-%D The next alternative accepts a negative width. A negative
-%D value crops the beginning. The macro thereby becomes less
-%D readable, which is why we kept the original here too.
+\ifdefined\fakecompoundhyphen\else \let\fakecompoundhyphen\relax \fi
+\ifdefined\veryraggedright \else \def\veryraggedright{\raggedright} \fi
\unexpanded\def\limitatetext
{\bgroup % evt \setstrut
\forgetall % otherwise indentation and so
- %\def\limitatetext##1##2##3{##1}% \def !
\let\limitatetext\firstofthreearguments
\fakecompoundhyphen % dangerous ! ! ! ! ! ! ! ! !
- \dowithnextboxcs\dolimitatetext\normalhbox}
-
-\def\dolimitatetext#1#2%
- {\doifelsenothing{#1}
- {\unhbox\nextbox}
- {\nopenalties
- \scratchdimen#1\relax
- \ifdim\scratchdimen<\zeropoint\relax % we'll take the last line
- \donefalse
- \scratchdimen-\scratchdimen
- \else
- \donetrue
- \fi
- \ifdim\nextboxwd>\scratchdimen
- \setbox\scratchbox\normalhbox{\ifdone\space#2\else#2\space\fi}%
- \advance\scratchdimen -\wd\scratchbox
- \setbox0\flushnextbox
- \setbox\nextbox\normalvbox
- {\hsize\scratchdimen
- \hfuzz\maxdimen
- \veryraggedright
- \strut
- \ifdone \else
- \parfillskip\zeropoint
- \rightskip\zeropoint
- \hskip\zeropoint \!!plus 1\!!fill % \hsize
- \fi
- \unhcopy0}%
- \ifdim\nextboxht>\strutht
- \setbox\nextbox\normalvbox % if omitted: missing brace reported
- {\splittopskip\openstrutheight
- \ifdone
- \setbox\nextbox\vsplit\nextbox to \strutht
+ \dowithnextboxcs\syst_boxes_limitate_text\hbox}
+
+\def\syst_boxes_limitate_text#1% #2
+ {\doifelsenothing{#1}\syst_boxes_limitate_text_nop\syst_boxes_limitate_text_yes{#1}} % {#2}
+
+\def\syst_boxes_limitate_text_nop#1#2%
+ {\unhbox\nextbox
+ \egroup}
+
+\def\syst_boxes_limitate_text_yes#1#2%
+ {\nopenalties
+ \scratchdimen#1\relax
+ \ifdim\scratchdimen<\zeropoint\relax % we'll take the last line
+ \donefalse
+ \scratchdimen-\scratchdimen
+ \else
+ \donetrue
+ \fi
+ \ifdim\wd\nextbox>\scratchdimen
+ \setbox\scratchbox\hbox{\ifdone\space#2\else#2\space\fi}%
+ \advance\scratchdimen -\wd\scratchbox
+ \setbox0\box\nextbox
+ \setbox\nextbox\vbox
+ {\hsize\scratchdimen
+ \hfuzz\maxdimen
+ \veryraggedright
+ \strut
+ \ifdone \else
+ \parfillskip\zeropoint
+ \rightskip\zeropoint
+ \hskip\zeropoint \!!plus 1\!!fill % \hsize
+ \fi
+ \unhcopy0}%
+ \ifdim\ht\nextbox>\strutht
+ \setbox\nextbox\vbox % if omitted: missing brace reported
+ {\splittopskip\openstrutheight
+ \ifdone
+ \setbox\nextbox\vsplit\nextbox to \strutht
+ \else
+ \doloop
+ {\setbox0\vsplit\nextbox to \strutht
+ \ifdim\ht\nextbox>\strutht \else \exitloop \fi}%
+ \fi
+ \unvbox\nextbox
+ \setbox\nextbox\lastbox
+ \global\setbox1\hbox
+ {\ifdone
+ \unhbox\nextbox\unskip\kern\zeropoint\box\scratchbox
\else
- \doloop
- {\setbox0\vsplit\nextbox to \strutht
- \ifdim\nextboxht>\strutht \else \exitloop \fi}%
+ \box\scratchbox\unhbox\nextbox
\fi
- \unvbox\nextbox
- \setbox\nextbox\lastbox
- \global\setbox1\normalhbox
- {\ifdone
- \unhbox\nextbox\unskip\kern\zeropoint\box\scratchbox
- \else
- \box\scratchbox\unhbox\nextbox
- \fi
- \unskip}}%
- \unhbox1
- \else
- \unhbox0
- \fi
- \else
- \unhbox\nextbox
- \fi}%
+ \unskip}}%
+ \unhbox1
+ \else
+ \unhbox0
+ \fi
+ \else
+ \unhbox\nextbox
+ \fi
\egroup}
%D We can also limit a text with more control:
@@ -1226,23 +1280,24 @@
%D
%D We build this feature on top of the previous macro.
+% we could move the text argument to the end
+
\let\normallimitatetext\limitatetext
\def\speciallimitatetext#1#2#3#4% text left right placeholder
{%\dontleavehmode
\bgroup
- %\def\speciallimitatetext##1##2##3##4{##1}% \def !
\let\speciallimitatetext\firstoffourarguments
- \setbox0\normalhbox
+ \setbox0\hbox
{\nohyphens
\normallimitatetext{#1}{+#2}{}#4%
\normallimitatetext{#1}{-#3}{}}%
- \setbox2\normalhbox
+ \setbox2\hbox
{#1}%
- \ifdim\wd2<\wd0 #1\else\unhbox0\fi
- \egroup}
+ \ifdim\wd2<\wd0 #1\else\unhbox0\fi
+ \egroup}
-\def\limitatetext#1#2#3% \expanded added 2003/01/16
+\unexpanded\def\limitatetext#1#2#3% \expanded added 2003/01/16
{\expanded{\beforesplitstring#2}\at,\to\leftlimit
\expanded{\aftersplitstring #2}\at,\to\rightlimit
\ifx\rightlimit\empty
@@ -1257,7 +1312,7 @@
%D \limitatefirstline{\input tufte\relax}{10cm}{\unknown}
%D \stoptyping
-\def\limitatefirstline#1#2#3%
+\unexpanded\def\limitatefirstline#1#2#3%
{\hbox\bgroup\strut
\setbox\scratchbox\hbox{\begstrut#1\endstrut}%
\ifdim\wd\scratchbox>#2\relax
@@ -1290,27 +1345,29 @@
%D \startbuffer
%D \processisolatedchars{some more words} \ruledhbox \par
%D \processisolatedchars{and some $x + y = z$ math} \ruledhbox \par
-%D \processisolatedchars{and a \normalhbox{$x + y = z$}} \ruledhbox \par
+%D \processisolatedchars{and a \hbox{$x + y = z$}} \ruledhbox \par
%D \processisolatedwords{some more words} \ruledhbox \par
%D \processisolatedwords{and some $x + y = z$ math} \ruledhbox \par
-%D \processisolatedwords{and a \normalhbox{$x + y = z$}} \ruledhbox \par
+%D \processisolatedwords{and a \hbox{$x + y = z$}} \ruledhbox \par
%D \stopbuffer
%D
%D \typebuffer \blank \getbuffer \blank
% todo: provide variant with #1 picked up as box
-\def\processisolatedchars#1#2%
+\unexpanded\def\processisolatedchars#1#2%
{\dontleavehmode
\begingroup
- \setbox\scratchbox\normalhbox{#1}%
+ \setbox\scratchbox\hbox{\settrialtypesetting#2{\savecurrentattributes{pic}}}%
+ \setbox\scratchbox\hbox{\restorecurrentattributes{pic}#1}%
\ctxcommand{applytochars(\number\scratchbox,"\strippedcsname#2",true)}%
\endgroup}
-\def\processisolatedwords#1#2%
+\unexpanded\def\processisolatedwords#1#2%
{\dontleavehmode
\begingroup
- \setbox\scratchbox\normalhbox{#1}%
+ \setbox\scratchbox\hbox{\settrialtypesetting#2{\savecurrentattributes{pic}}}%
+ \setbox\scratchbox\hbox{\restorecurrentattributes{pic}#1}%
\ctxcommand{applytowords(\number\scratchbox,"\strippedcsname#2",true)}%
\endgroup}
@@ -1321,15 +1378,15 @@
%D The better variant:
-\def\applytocharacters#1%
+\unexpanded\def\applytocharacters#1%
{\dontleavehmode
\dowithnextbox{\ctxcommand{applytochars(\number\nextbox,"\strippedcsname#1",true)}}%
- \normalhbox}
+ \hbox}
-\def\applytowords#1%
+\unexpanded\def\applytowords#1%
{\dontleavehmode
\dowithnextbox{\ctxcommand{applytowords(\number\nextbox,"\strippedcsname#1",true)}}%
- \normalhbox}
+ \hbox}
%D \macros
%D {sbox}
@@ -1348,28 +1405,29 @@
%D
%D Shows up as:
%D
-%D \startvoorbeeld
+%D \startexample
%D \vskip3\baselineskip
%D \getbuffer
-%D \stopvoorbeeld
+%D \stopexample
%D
%D Before displaying the result we added some skip, otherwise
%D the first two lines would have ended up in the text. This
%D macro can be useful when building complicated menus, headers
%D and footers and|/|or margin material.
-\def\sbox% in handleiding, voorbeeld \inleft{xx} \extern..
- {\normalvbox\bgroup % new ! ! !
- \dowithnextbox
- {\setbox\scratchbox\normalhbox
- {\strut
- \nextboxdp\zeropoint
- \lower\strutdepth\flushnextbox}%
- \dp\scratchbox\strutdepth
- \ht\scratchbox\strutheight
- \box\scratchbox
- \egroup}%
- \normalvbox}
+\unexpanded\def\sbox
+ {\vbox\bgroup
+ \dowithnextboxcs\syst_boxes_sbox_finish\vbox}
+
+\unexpanded\def\syst_boxes_sbox_finish
+ {\setbox\nextbox\hbox
+ {\strut
+ \dp\nextbox\zeropoint
+ \lower\strutdepth\box\nextbox}%
+ \dp\nextbox\strutdepth
+ \ht\nextbox\strutheight
+ \box\nextbox
+ \egroup}
%D \macros
%D {struttedbox}
@@ -1377,14 +1435,15 @@
%D This boxing macro limits the height and depth to those of
%D a strut.
-\def\struttedbox
- {\normalhbox\bgroup % new ! ! !
- \dowithnextbox
- {\nextboxdp\strutdepth
- \nextboxht\strutheight
- \flushnextbox
- \egroup}%
- \normalhbox}
+\unexpanded\def\struttedbox
+ {\hbox\bgroup
+ \dowithnextboxcs\syst_boxes_struttedbox_finish\hbox}
+
+\def\syst_boxes_struttedbox_finish
+ {\ht\nextbox\strutdepth
+ \ht\nextbox\strutheight
+ \box\nextbox
+ \egroup}%
%D \macros
%D {topskippedbox}
@@ -1393,14 +1452,14 @@
%D and strutheight. Watch how we preserve the depth when it
%D equals strutdepth.
-\def\topskippedbox
- {\normalhbox\bgroup
- \dowithnextbox
- {\edef\next{\ifdim\strutdepth=\nextboxdp\nextboxdp\the\nextboxdp\fi}%
- \lower\topskip\normalhbox{\raise\strutheight\flushnextbox}%
- \next
- \egroup}%
- \normalhbox}
+\unexpanded\def\topskippedbox
+ {\hbox\bgroup\dowithnextboxcs\syst_boxes_topskippedbox_finish\hbox}
+
+\def\syst_boxes_topskippedbox_finish
+ {\edef\m_boxes_tmp{\ifdim\strutdepth=\dp\nextbox\dp\nextbox\the\dp\nextbox\fi}%
+ \lower\topskip\hbox{\raise\strutheight\box\nextbox}%
+ \m_boxes_tmp
+ \egroup}
%D \macros
%D {centeredbox, centerednextbox}
@@ -1448,26 +1507,26 @@
%D intact. This commands handles positive and negative
%D dimensions (which is why we need two boxes with rules).
-\def\centeredbox#1#% height +/-dimen width +/-dimen
+\unexpanded\def\centeredbox#1#% height +/-dimen width +/-dimen
{\bgroup
- \setbox0\normalvbox to \vsize
+ \setbox0\vbox to \vsize
\bgroup
\dontcomplain
\forgetall
- \setbox0\normalhbox{\vrule\!!width \zeropoint#1}%
- \setbox2\normalvbox{\hrule\!!height\zeropoint#1}%
+ \setbox0\hbox{\vrule\!!width \zeropoint#1}%
+ \setbox2\vbox{\hrule\!!height\zeropoint#1}%
\advance\vsize \ht2
\advance\hsize \wd0
- \normalvbox to \vsize
+ \vbox to \vsize
\bgroup
\vskip-\ht2
\vss
- \normalhbox to \hsize
+ \hbox to \hsize
\bgroup
\dowithnextbox
{\hskip-\wd0
\hss
- \flushnextbox
+ \box\nextbox
\hss
\egroup
\vss
@@ -1477,7 +1536,7 @@
\ht0\vsize
\box0
\egroup}
- \normalhbox}
+ \hbox}
%D For those who don't want to deal with \type {\hsize}
%D and \type {\vsize}, we have:
@@ -1489,14 +1548,14 @@
%D
%D Do you see what we call this one \type {next}?
-\def\centerednextbox#1#%
+\unexpanded\def\centerednextbox#1#%
{\bgroup
\dowithnextbox
- {\hsize\nextboxwd
- \vsize\nextboxht
- \centeredbox#1{\flushnextbox}%
+ {\hsize\wd\nextbox
+ \vsize\ht\nextbox
+ \centeredbox#1{\box\nextbox}%
\egroup}
- \normalhbox}
+ \hbox}
%D \macros
%D {centerbox}
@@ -1510,17 +1569,17 @@
%D When omitted, the current \type {\hsize} and \type
%D {\vsize} are used. Local dimensions are supported.
-\long\def\centerbox#1#% optional height +/-dimen width +/-dimen
+\unexpanded\def\centerbox#1#% optional height +/-dimen width +/-dimen
{\bgroup
\dowithnextbox
{\setlocalhsize
- \setbox\scratchbox\normalhbox{\vrule\!!width \zeropoint#1}%
+ \setbox\scratchbox\hbox{\vrule\!!width \zeropoint#1}%
\ifzeropt\wd\scratchbox\else\hsize\wd\scratchbox\fi
- \setbox\scratchbox\normalvbox{\hrule\!!height\zeropoint#1}%
+ \setbox\scratchbox\vbox{\hrule\!!height\zeropoint#1}%
\ifzeropt\ht\scratchbox\else\vsize\ht\scratchbox\fi
- \normalvbox to \vsize{\vss\normalhbox to \hsize{\hss\flushnextbox\hss}\vss}%
+ \vbox to \vsize{\vss\hbox to \hsize{\hss\box\nextbox\hss}\vss}%
\egroup}%
- \normalhbox}
+ \hbox}
%D \macros
%D {setrigidcolumnhsize,rigidcolumnbalance,rigidcolumnlines}
@@ -1546,7 +1605,7 @@
%D De eerste switch bepaald het uitlijnen, de tweede rekt de
%D individuele kolommen op naar \type{\vsize}.
-\def\setrigidcolumnhsize#1#2#3% todo: \dimexpr
+\unexpanded\def\setrigidcolumnhsize#1#2#3% todo: \dimexpr
{\xdef\savedrigidhsize{\the\hsize}%
\hsize#1\relax
\global\chardef\rigidcolumns#3\relax
@@ -1567,15 +1626,15 @@
\let\rigidcolumnlines\!!zerocount
-\def\rigidcolumnbalance#1%
+\unexpanded\def\rigidcolumnbalance#1%
{\ifnum\rigidcolumns=1 % tzt ook h/d correctie
\ifinner\ifhmode\box\else\unvbox\fi\else\unvbox\fi#1\relax
\else
- \normalvbox
+ \vbox
{\forgetall
\nopenalties
\dontcomplain
- \setbox\rigidcolumnbox\normalvbox
+ \setbox\rigidcolumnbox\vbox
{\line{}\goodbreak\unvbox#1\removebottomthings}%
\splittopskip\openstrutheight
\setbox\scratchbox\vsplit\rigidcolumnbox to \zeropoint
@@ -1604,7 +1663,7 @@
\setbox0=\box\rigidcolumnbox
\doloop
{\setbox\rigidcolumnbox=\copy0
- \setbox\scratchbox\normalhbox to \savedrigidhsize
+ \setbox\scratchbox\hbox to \savedrigidhsize
{\dorecurse\rigidcolumns
{\setbox\scratchbox\vsplit\rigidcolumnbox to \scratchdimen
\dp\scratchbox\openstrutdepth
@@ -1619,10 +1678,10 @@
\hfillneg}%
\ifvoid\rigidcolumnbox\exitloop\else\advance\scratchdimen\lineheight\fi}%
\iftightrigidcolumns
- \setbox\scratchbox\normalhbox{\raise\dp\scratchbox\box\scratchbox}%
+ \setbox\scratchbox\hbox{\raise\dp\scratchbox\box\scratchbox}%
\else
\advance\scratchdimen -\openstrutdepth
- \setbox\scratchbox\normalhbox{\raise\scratchdimen\box\scratchbox}%
+ \setbox\scratchbox\hbox{\raise\scratchdimen\box\scratchbox}%
\dp\scratchbox\openstrutdepth
\ht\scratchbox\scratchdimen
\fi
@@ -1637,14 +1696,14 @@
%D like:
%D
%D \starttyping
-%D \normalvbox
+%D \vbox
%D \bgroup
%D \startvboxtohbox ... \stopvboxtohbox
%D \startvboxtohbox ... \stopvboxtohbox
%D \startvboxtohbox ... \stopvboxtohbox
%D \egroup
%D
-%D \normalvbox
+%D \vbox
%D \bgroup
%D \convertvboxtohbox
%D \egroup
@@ -1653,7 +1712,7 @@
%D These macros are used in reformatting footnotes, so they do
%D what they're meant for.
-\def\setvboxtohbox
+\unexpanded\def\setvboxtohbox
{\bgroup
\ifdim\baselineskip<16pt \relax
\scratchdimen\baselineskip
@@ -1664,36 +1723,36 @@
\fi
\divide\scratchdimen \hsize
\multiply\scratchdimen 64
- \xdef\normalvboxtohboxfactor{\withoutpt\the\scratchdimen}%
+ \xdef\vboxtohboxfactor{\withoutpt\the\scratchdimen}%
\egroup}
-\def\startvboxtohbox
+\unexpanded\def\startvboxtohbox
{\bgroup
\setvboxtohbox
- \setbox\scratchbox\normalhbox\bgroup}
+ \setbox\scratchbox\hbox\bgroup}
-\def\stopvboxtohbox
+\unexpanded\def\stopvboxtohbox
{\egroup
\dp\scratchbox\zeropoint
- \ht\scratchbox\normalvboxtohboxfactor\wd\scratchbox
+ \ht\scratchbox\vboxtohboxfactor\wd\scratchbox
\box\scratchbox
\egroup}
-\def\convertvboxtohbox
+\unexpanded\def\convertvboxtohbox
{\setvboxtohbox
\makehboxofhboxes
- \setbox0\normalhbox{\unhbox0 \removehboxes}%
+ \setbox0\hbox{\unhbox0 \removehboxes}%
\noindent\unhbox0\par}
-\def\makehboxofhboxes
+\unexpanded\def\makehboxofhboxes
{\setbox0\emptyhbox
\loop % \doloop { .. \exitloop .. }
\setbox2\lastbox
\ifhbox2
- \setbox0\normalhbox{\box2\unhbox0}%
+ \setbox0\hbox{\box2\unhbox0}%
\repeat}
-\def\removehboxes
+\unexpanded\def\removehboxes
{\setbox0\lastbox
\ifhbox0
{\removehboxes}\unhbox0
@@ -1710,21 +1769,21 @@
\newdimen \lasthhboxwidth
\newskip \hhboxindent
-\def\unhhbox#1\with#2%
+\unexpanded\def\unhhbox#1\with#2%
{\bgroup
\nopenalties
\dontcomplain
\forgetall
- \setbox\unhhedbox\normalvbox{\hskip\hhboxindent\strut\unhbox#1}% => \hsize
+ \setbox\unhhedbox\vbox{\hskip\hhboxindent\strut\unhbox#1}% => \hsize
\doloop
{\setbox\hhbox\vsplit\unhhedbox to \lineheight
\ifvoid\unhhedbox
- \setbox\hhbox\normalhbox{\strut\normalhboxofvbox\hhbox}%
+ \setbox\hhbox\hbox{\strut\hboxofvbox\hhbox}%
\fi
\ht\hhbox\strutht
\dp\hhbox\strutdp
\ifzeropt\hhboxindent\else % \ifdim\hhboxindent=\zeropoint\else
- \setbox\hhbox\normalhbox{\hskip-\hhboxindent\box\hhbox}%
+ \setbox\hhbox\hbox{\hskip-\hhboxindent\box\hhbox}%
\hhboxindent\zeropoint
\fi
\global\lasthhboxwidth\wd\hhbox
@@ -1737,11 +1796,11 @@
\egroup}
\def\dohboxofvbox
- {\setbox0\normalvbox{\unvbox\scratchcounter\global\setbox1\lastbox}%
+ {\setbox0\vbox{\unvbox\scratchcounter\global\setbox1\lastbox}%
\unhbox1
\egroup}
-\def\normalhboxofvbox
+\unexpanded\def\hboxofvbox
{\bgroup
\afterassignment\dohboxofvbox
\scratchcounter=}
@@ -1753,8 +1812,8 @@
%D headers.
%D
%D \startbuffer
-%D \setbox0=\normalhbox{\input tufte \relax}
-%D \setbox2=\normalhbox{\input knuth \relax}
+%D \setbox0=\hbox{\input tufte \relax}
+%D \setbox2=\hbox{\input knuth \relax}
%D \unhhbox0\with{\ruledhbox{\box\hhbox}}
%D \hskip1em plus 1em minus 1em
%D \hhboxindent=\lasthhboxwidth
@@ -1781,21 +1840,21 @@
%D \doifcontent{pre content}{post content}{no content}\somebox
%D \stoptyping
%D
-%D Where \type{\somebox} is either a \type{\normalhbox} or
-%D \type{\normalvbox}. If the dimension of this box suggest some
+%D Where \type{\somebox} is either a \type{\hbox} or
+%D \type{\vbox}. If the dimension of this box suggest some
%D content, the resulting box is unboxed and surrounded by the
%D first two arguments, else the third arguments is executed.
\unexpanded\def\doifcontent#1#2#3%
{\dowithnextbox
{\ifhbox\nextbox
- \ifdim\nextboxwd>\zeropoint
+ \ifdim\wd\nextbox>\zeropoint
#1\unhbox\nextbox#2\relax
\else
#3\relax
\fi
\else
- \ifdim\nextboxht>\zeropoint
+ \ifdim\ht\nextbox>\zeropoint
#1\unvbox\nextbox#2\relax
\else
#3\relax
@@ -1805,11 +1864,11 @@
%D So when we say:
%D
%D \startbuffer
-%D \doifcontent{[}{]}{}\normalhbox{content sensitive typesetting}
+%D \doifcontent{[}{]}{}\hbox{content sensitive typesetting}
%D
-%D \doifcontent{}{\page}{}\normalvbox{content sensitive typesetting}
+%D \doifcontent{}{\page}{}\vbox{content sensitive typesetting}
%D
-%D \doifcontent{}{}{\message{Didn't you forget something?}}\normalhbox{}
+%D \doifcontent{}{}{\message{Didn't you forget something?}}\hbox{}
%D \stopbuffer
%D
%D \typebuffer
@@ -1827,32 +1886,60 @@
%D The next macro gobble boxes and is for instance used for
%D overlays. First we show the general handler.
-\newbox\processbox
+% we cannot use \futurelet here as we want to skip spaces between
+% boxes (see startoverlay for an example usage)
+
+% \newbox\processbox % public : this is the one where \nextbox's end up in
+%
+% \unexpanded\def\processboxes#1%
+% {\bgroup
+% \def\syst_boxes_process_indeed{#1}% #1 can be redefined halfway
+% \setbox\processbox\emptybox
+% \afterassignment\syst_boxes_process
+% \let\nexttoken}
+%
+% \def\syst_boxes_process
+% {\ifx\nexttoken\bgroup
+% \expandafter\syst_boxes_process_yes
+% \else
+% \expandafter\syst_boxes_process_nop
+% \fi}
+%
+% \def\syst_boxes_process_yes
+% {\dowithnextboxcs\syst_boxes_process_content\hbox\bgroup}
+%
+% \def\syst_boxes_process_content
+% {\removeunwantedspaces
+% \syst_boxes_process_indeed % takes \nextbox makes \processbox
+% \afterassignment\syst_boxes_process
+% \let\nexttoken}
+%
+% \unexpanded\def\syst_boxes_process_nop
+% {\removeunwantedspaces
+% \box\processbox
+% \nexttoken % messy as we are still in the group
+% \egroup}
+
+\newbox\processbox % public : this is the one where \nextbox's end up in
-\def\processboxes#1%
+\unexpanded\def\processboxes#1%
{\bgroup
- \def\doprocessbox{#1}% #1 can be redefined halfway
+ \def\syst_boxes_process_indeed{#1}% #1 can be redefined halfway
\setbox\processbox\emptybox
- \afterassignment\dogetprocessbox\let\next=}
+ \doifnextbgroupelse\syst_boxes_process_yes\syst_boxes_process_nop}
-\def\endprocessboxes
- {\ifhmode\unskip\fi
- \box\processbox
- \next
- \egroup}
+\def\syst_boxes_process_yes
+ {\dowithnextboxcs\syst_boxes_process_content\hbox}
-\def\dogetprocessbox
- {\ifx\next\bgroup
- \expandafter\dodogetprocessbox
- \else
- \expandafter\endprocessboxes
- \fi}
+\def\syst_boxes_process_content
+ {\removeunwantedspaces
+ \syst_boxes_process_indeed % takes \nextbox makes \processbox
+ \doifnextbgroupelse\syst_boxes_process_yes\syst_boxes_process_nop}
-\def\dodogetprocessbox
- {\dowithnextbox
- {\ifhmode\unskip\fi\doprocessbox % takes \nextbox makes \processbox
- \afterassignment\dogetprocessbox\let\next=}
- \normalhbox\bgroup}
+\unexpanded\def\syst_boxes_process_nop
+ {\removeunwantedspaces
+ \box\processbox
+ \egroup}
%D \macros
%D {startoverlay}
@@ -1873,38 +1960,26 @@
%D
%D \leavevmode\getbuffer
-\def\dooverlaybox
- {\ifhmode\unskip\fi
- \scratchdimen\dp
- \ifdim\nextboxdp>\dp\processbox
- \nextbox
- \else
- \processbox
- \fi
- \ifdim\nextboxht>\ht\processbox
- \setbox\processbox\normalvbox to \nextboxht
- {\dp\processbox\zeropoint\vss\box\processbox\vss}%
+\def\syst_boxes_overlay_process
+ {%\removeunwantedspaces % already done
+ \scratchdepth\dp\ifdim\dp\nextbox>\dp\processbox\nextbox\else\processbox\fi
+ \ifdim\ht\nextbox>\ht\processbox
+ \setbox\processbox\vbox to \ht\nextbox {\dp\processbox\zeropoint\vss\box\processbox\vss}%
\else
- \setbox\nextbox\normalvbox to \ht\processbox
- {\nextboxdp\zeropoint\vss\flushnextbox\vss}%
+ \setbox\nextbox \vbox to \ht\processbox{\dp\nextbox \zeropoint\vss\box\nextbox \vss}%
\fi
- \nextboxdp\scratchdimen
- \dp\processbox\scratchdimen
- \scratchdimen\wd
- \ifdim\nextboxwd>\wd\processbox
- \nextbox
- \else
- \processbox
- \fi
- \setbox\processbox\normalhbox to \scratchdimen
- {\normalhbox to \scratchdimen{\hss\box\processbox\hss}%
- \hskip-\scratchdimen
- \normalhbox to \scratchdimen{\hss\flushnextbox\hss}}}
+ \dp\nextbox \scratchdepth
+ \dp\processbox\scratchdepth
+ \scratchwidth\wd\ifdim\wd\nextbox>\wd\processbox\nextbox\else\processbox\fi
+ \setbox\processbox\hbox to \scratchwidth
+ {\hbox to \scratchwidth{\hss\box\processbox\hss}%
+ \hskip-\scratchwidth
+ \hbox to \scratchwidth{\hss\box\nextbox \hss}}}
\unexpanded\def\startoverlay
{\bgroup
\let\stopoverlay\egroup
- \processboxes\dooverlaybox}
+ \processboxes\syst_boxes_overlay_process}
\let\stopoverlay\relax
@@ -1914,24 +1989,24 @@
%D The next macro is a rather silly one, but saves space.
%D
%D \starttyping
-%D \normalhbox{\fakebox0}
+%D \hbox{\fakebox0}
%D \stoptyping
%D
%D returns an empty box with the dimensions of the box
%D specified, here being zero.
-\def\dofakebox
- {\setbox\scratchbox\emptyhbox
+\unexpanded\def\fakebox
+ {\bgroup
+ \afterassignment\syst_boxes_fakebox_finish\scratchcounter}
+
+\def\syst_boxes_fakebox_finish
+ {\setbox\scratchbox\ifhbox\scratchcounter\emptyhbox\else\emptyvbox\fi
\wd\scratchbox\wd\scratchcounter
\ht\scratchbox\ht\scratchcounter
\dp\scratchbox\dp\scratchcounter
- \ifhbox\scratchcounter\normalhbox\else\normalvbox\fi{\box\scratchbox}%
+ \box\scratchbox
\egroup}
-\def\fakebox
- {\bgroup
- \afterassignment\dofakebox\scratchcounter}
-
%D \macros
%D {lbox,rbox,cbox,tbox,bbox}
%D
@@ -1943,21 +2018,20 @@
%D \rbox{text ...}
%D \stoptyping
%D
-%D Are similar to \type {\normalvbox}, which means that they also
+%D Are similar to \type {\vbox}, which means that they also
%D accept something like \type{to 3cm}, but align to the left,
%D middle and right. These box types can be used to typeset
%D paragraphs.
-\def\lbox{\makelrcbox\normalvbox\raggedleft}
-\def\cbox{\makelrcbox\normalvbox\raggedcenter}
-\def\rbox{\makelrcbox\normalvbox\raggedright}
+\def\syst_boxes_lrc_process#1{\bgroup\forgetall\let\\\endgraf#1\let\next}
-\def\ltop{\makelrcbox\normalvtop\raggedleft}
-\def\ctop{\makelrcbox\normalvtop\raggedcenter}
-\def\rtop{\makelrcbox\normalvtop\raggedright}
+\unexpanded\def\lbox#1#{\vbox#1\syst_boxes_lrc_process\raggedleft }
+\unexpanded\def\cbox#1#{\vbox#1\syst_boxes_lrc_process\raggedcenter}
+\unexpanded\def\rbox#1#{\vbox#1\syst_boxes_lrc_process\raggedright }
-\def\makelrcbox#1#2#3#%
- {#1#3\bgroup \forgetall \let\\=\endgraf #2\let\next=}
+\unexpanded\def\ltop#1#{\normalvtop#1\syst_boxes_lrc_process\raggedleft }
+\unexpanded\def\ctop#1#{\normalvtop#1\syst_boxes_lrc_process\raggedcenter}
+\unexpanded\def\rtop#1#{\normalvtop#1\syst_boxes_lrc_process\raggedright }
%D The alternatives \type {\tbox} and \type {\bbox} can be used
%D to properly align boxes, like in:
@@ -1979,34 +2053,41 @@
%D
%D \getbuffer
-\def\tbox{\tbbox\ht\dp}
-\def\bbox{\tbbox\dp\ht}
+\unexpanded\def\tbox{\hbox\bgroup\dowithnextboxcs\syst_boxes_tbox_finish\hbox}
+\unexpanded\def\bbox{\hbox\bgroup\dowithnextboxcs\syst_boxes_bbox_finish\hbox}
+
+\def\syst_boxes_tbox_finish
+ {\scratchdepth\dimexpr\ht\nextbox+\dp\nextbox-\ht\strutbox\relax
+ \ht\nextbox\ht\strutbox
+ \dp\nextbox\scratchdepth
+ \setbox\nextbox\hbox{\lower\dp\nextbox\box\nextbox}%
+ \ht\nextbox\ht\strutbox
+ \dp\nextbox\scratchdepth
+ \box\nextbox
+ \egroup}
-\def\tbbox#1#2%
- {\normalhbox\bgroup
- \dowithnextbox
- {\scratchdimen\dimexpr\nextboxht+\nextboxdp-#1\strutbox\relax
- #1\nextbox#1\strutbox
- #2\nextbox\scratchdimen
- \setbox\nextbox\normalhbox{\lower\nextboxdp\flushnextbox}%
- #1\nextbox#1\strutbox
- #2\nextbox\scratchdimen
- \flushnextbox
- \egroup}
- \normalhbox}
+\def\syst_boxes_bbox_finish
+ {\scratchheight\dimexpr\ht\nextbox+\dp\nextbox-\dp\strutbox\relax
+ \dp\nextbox\dp\strutbox
+ \ht\nextbox\scratchheight
+ \setbox\nextbox\hbox{\lower\dp\nextbox\box\nextbox}%
+ \dp\nextbox\dp\strutbox
+ \ht\nextbox\scratchheight
+ \box\nextbox
+ \egroup}
%D \macros
%D {lhbox,mhbox,rhbox}
%D
%D A few more boxes.
-\def\dodolhbox{\normalhbox to \hsize{\flushnextbox\hss }}
-\def\dodomhbox{\normalhbox to \hsize{\hss\flushnextbox\hss}}
-\def\dodorhbox{\normalhbox to \hsize{\hss\flushnextbox }}
+\def\dodolhbox{\hbox to \hsize{\box\nextbox\hss }}
+\def\dodomhbox{\hbox to \hsize{\hss\box\nextbox\hss}}
+\def\dodorhbox{\hbox to \hsize{\hss\box\nextbox }}
-\def\lhbox{\dowithnextboxcs\dodolhbox\normalhbox}
-\def\mhbox{\dowithnextboxcs\dodomhbox\normalhbox}
-\def\rhbox{\dowithnextboxcs\dodorhbox\normalhbox}
+\unexpanded\def\lhbox{\dowithnextboxcs\dodolhbox\hbox}
+\unexpanded\def\mhbox{\dowithnextboxcs\dodomhbox\hbox}
+\unexpanded\def\rhbox{\dowithnextboxcs\dodorhbox\hbox}
\let\lefthbox \lhbox
\let\midhbox \mhbox
@@ -2020,7 +2101,7 @@
%D additions, we can use:
%D
%D \starttyping
-%D \boxofsize \normalvbox 10cm 3cm -5cm {the text to be typeset}
+%D \boxofsize \vbox 10cm 3cm -5cm {the text to be typeset}
%D \stoptyping
%D
%D This example demonstrates that one can use positive and
@@ -2028,7 +2109,7 @@
\newdimen\sizeofbox
-\def\boxofsize#1%
+\unexpanded\def\boxofsize#1%
{\bgroup
\sizeofbox\zeropoint
\scratchdimen\zeropoint
@@ -2050,25 +2131,25 @@
% \limitvbox
% \limithbox
-\def\limitatelines#1#2% size sentinel
+\unexpanded\def\limitatelines#1#2% size sentinel
{\dowithnextbox
{\dimen0=#1\hsize
- \ifdim\nextboxwd>\dimen0
- \setbox\nextbox\normalhbox
+ \ifdim\wd\nextbox>\dimen0
+ \setbox\nextbox\hbox
{\advance\dimen0 -.1\hsize
\limitatetext{\unhbox\nextbox}{\dimen0}{\nobreak#2}}%
\fi
\unhbox\nextbox}
- \normalhbox}
+ \hbox}
-\def\fittoptobaselinegrid % weg hier
+\unexpanded\def\fittoptobaselinegrid % weg hier
{\dowithnextbox
{\bgroup
\par
- \dimen0\nextboxht
- \nextboxht\strutht
- \nextboxdp\strutdp
- \normalhbox{\flushnextbox}
+ \dimen0\ht\nextbox
+ \ht\nextbox\strutht
+ \dp\nextbox\strutdp
+ \hbox{\box\nextbox}
\prevdepth\strutdp
\doloop
{\advance\dimen0 -\lineheight
@@ -2076,10 +2157,10 @@
\exitloop
\else
\nobreak
- \normalhbox{\strut}
+ \hbox{\strut}
\fi}
\egroup}
- \normalvbox}
+ \vbox}
%D Some more undocumented macros (used in m-chart).
@@ -2087,14 +2168,14 @@
\newbox\fakedboxcursor
-\setbox\fakedboxcursor\normalhbox
+\setbox\fakedboxcursor\hbox
{\vrule\!!width\zeropoint\!!height\zeropoint\!!depth\zeropoint}
-\def\boxcursor % overloaded in core-vis
+\unexpanded\def\boxcursor % overloaded in core-vis
{\iftraceboxplacement
\bgroup
- \scratchdimen2pt
- \setbox\scratchbox\normalhbox to \zeropoint
+ \scratchdimen2\onepoint
+ \setbox\scratchbox\hbox to \zeropoint
{\hss
\vrule
\!!width \scratchdimen
@@ -2107,120 +2188,128 @@
\copy\fakedboxcursor
\fi}
-\def\placedbox
- {\iftraceboxplacement\ruledhbox\else\normalhbox\fi}
+\unexpanded\def\placedbox
+ {\iftraceboxplacement\ruledhbox\else\hbox\fi}
\newdimen\boxoffset
\newdimen\boxhdisplacement
\newdimen\boxvdisplacement
-\def\rightbox#1%
- {\normalhbox
- {\setbox\scratchbox\placedbox{#1}%
- \global\boxhdisplacement\boxoffset
- \global\boxvdisplacement.5\ht\scratchbox
- \global\advance\boxvdisplacement-.5\dp\scratchbox
- \boxcursor\hskip\boxhdisplacement\lower\boxvdisplacement\box\scratchbox}}
-
-\def\leftbox#1%
- {\normalhbox
- {\setbox\scratchbox\placedbox{#1}%
- \global\boxhdisplacement-\wd\scratchbox
- \global\advance\boxhdisplacement-\boxoffset
- \global\boxvdisplacement.5\ht\scratchbox
- \global\advance\boxvdisplacement-.5\dp\scratchbox
- \boxcursor\hskip\boxhdisplacement\lower\boxvdisplacement\box\scratchbox}}
-
-\def\topbox#1%
- {\normalhbox
- {\setbox\scratchbox\placedbox{#1}%
- \global\boxhdisplacement-.5\wd\scratchbox
- \global\boxvdisplacement-\dp\scratchbox
- \global\advance\boxvdisplacement-\boxoffset
- \boxcursor\hskip\boxhdisplacement\raise-\boxvdisplacement\box\scratchbox}}
-
-\def\bottombox#1%
- {\normalhbox
- {\setbox\scratchbox\placedbox{#1}%
- \global\boxhdisplacement-.5\wd\scratchbox
- \global\boxvdisplacement\ht\scratchbox
- \global\advance\boxvdisplacement\boxoffset
- \boxcursor\hskip\boxhdisplacement\lower\boxvdisplacement\box\scratchbox}}
-
-\def\lefttopbox#1%
- {\normalhbox
- {\setbox\scratchbox\placedbox{#1}%
- \global\boxhdisplacement-\wd\scratchbox
- \global\advance\boxhdisplacement-\boxoffset
- \global\boxvdisplacement-\dp\scratchbox
- \global\advance\boxvdisplacement-\boxoffset
- \boxcursor\hskip\boxhdisplacement\raise-\boxvdisplacement\box\scratchbox}}
-
-\def\righttopbox#1%
- {\normalhbox
- {\setbox\scratchbox\placedbox{#1}%
- \global\boxhdisplacement\boxoffset
- \global\boxvdisplacement-\dp\scratchbox
- \global\advance\boxvdisplacement-\boxoffset
- \boxcursor\hskip\boxhdisplacement\raise-\boxvdisplacement\box\scratchbox}}
-
-\def\leftbottombox#1%
- {\normalhbox
- {\setbox\scratchbox\placedbox{#1}%
- \global\boxhdisplacement-\wd\scratchbox
- \global\advance\boxhdisplacement-\boxoffset
- \global\boxvdisplacement\ht\scratchbox
- \global\advance\boxvdisplacement\boxoffset
- \boxcursor\hskip\boxhdisplacement\lower\boxvdisplacement\box\scratchbox}}
-
-\def\rightbottombox#1%
- {\normalhbox
- {\setbox\scratchbox\placedbox{#1}%
- \global\boxhdisplacement\boxoffset
- \global\boxvdisplacement\ht\scratchbox
- \global\advance\boxvdisplacement\boxoffset
- \boxcursor\hskip\boxhdisplacement\lower\boxvdisplacement\box\scratchbox}}
+\unexpanded\def\rightbox {\hbox\bgroup\dowithnextboxcs\syst_boxes_rightbox_finish \placedbox}
+\unexpanded\def\leftbox {\hbox\bgroup\dowithnextboxcs\syst_boxes_leftbox_finish \placedbox}
+\unexpanded\def\topbox {\hbox\bgroup\dowithnextboxcs\syst_boxes_topbox_finish \placedbox}
+\unexpanded\def\bottombox {\hbox\bgroup\dowithnextboxcs\syst_boxes_bottombox_finish \placedbox}
+\unexpanded\def\lefttopbox {\hbox\bgroup\dowithnextboxcs\syst_boxes_lefttopbox_finish \placedbox}
+\unexpanded\def\righttopbox {\hbox\bgroup\dowithnextboxcs\syst_boxes_righttopbox_finish \placedbox}
+\unexpanded\def\leftbottombox {\hbox\bgroup\dowithnextboxcs\syst_boxes_leftbottombox_finish \placedbox}
+\unexpanded\def\rightbottombox{\hbox\bgroup\dowithnextboxcs\syst_boxes_rightbottombox_finish\placedbox}
\let\topleftbox \lefttopbox
\let\toprightbox \righttopbox
\let\bottomleftbox \leftbottombox
\let\bottomrightbox\rightbottombox
-\def\middlebox#1%
- {\normalhbox{\setbox\scratchbox\placedbox{#1}\boxoffset=-.5\wd\scratchbox\rightbox{\box\scratchbox}}}
-
-\def\baselinemiddlebox#1%
- {\normalhbox
- {\setbox\scratchbox\placedbox{#1}%
- \global\boxhdisplacement-.5\wd\scratchbox
- \global\advance\boxhdisplacement-\boxoffset
- \global\boxvdisplacement-\boxoffset
- \boxcursor\hskip\boxhdisplacement\raise-\boxvdisplacement\box\scratchbox}}
-
-\def\baselineleftbox#1%
- {\normalhbox
- {\setbox\scratchbox\placedbox{#1}%
- \global\boxhdisplacement-\wd\scratchbox
- \global\advance\boxhdisplacement-\boxoffset
- \global\boxvdisplacement-\boxoffset
- \boxcursor\hskip\boxhdisplacement\raise-\boxvdisplacement\box\scratchbox}}
-
-\def\baselinerightbox#1%
- {\normalhbox
- {\setbox\scratchbox\placedbox{#1}%
- \global\boxhdisplacement\boxoffset
- \global\boxvdisplacement-\boxoffset
- \boxcursor\hskip\boxhdisplacement\raise-\boxvdisplacement\box\scratchbox}}
+\def\syst_boxes_rightbox_finish
+ {\global\boxhdisplacement\boxoffset
+ \global\boxvdisplacement.5\ht\nextbox
+ \global\advance\boxvdisplacement-.5\dp\nextbox
+ \boxcursor\hskip\boxhdisplacement\lower\boxvdisplacement\box\nextbox
+ \egroup}
+
+\def\syst_boxes_leftbox_finish
+ {\global\boxhdisplacement-\wd\nextbox
+ \global\advance\boxhdisplacement-\boxoffset
+ \global\boxvdisplacement.5\ht\nextbox
+ \global\advance\boxvdisplacement-.5\dp\nextbox
+ \boxcursor\hskip\boxhdisplacement\lower\boxvdisplacement\box\nextbox
+ \egroup}
+
+\def\syst_boxes_topbox_finish
+ {\global\boxhdisplacement-.5\wd\nextbox
+ \global\boxvdisplacement-\dp\nextbox
+ \global\advance\boxvdisplacement-\boxoffset
+ \boxcursor\hskip\boxhdisplacement\raise-\boxvdisplacement\box\nextbox
+ \egroup}
+
+\def\syst_boxes_bottombox_finish
+ {\global\boxhdisplacement-.5\wd\nextbox
+ \global\boxvdisplacement\ht\nextbox
+ \global\advance\boxvdisplacement\boxoffset
+ \boxcursor\hskip\boxhdisplacement\lower\boxvdisplacement\box\nextbox
+ \egroup}
+
+\def\syst_boxes_lefttopbox_finish
+ {\global\boxhdisplacement-\wd\nextbox
+ \global\advance\boxhdisplacement-\boxoffset
+ \global\boxvdisplacement-\dp\nextbox
+ \global\advance\boxvdisplacement-\boxoffset
+ \boxcursor\hskip\boxhdisplacement\raise-\boxvdisplacement\box\nextbox
+ \egroup}
+
+\def\syst_boxes_righttopbox_finish
+ {\global\boxhdisplacement\boxoffset
+ \global\boxvdisplacement-\dp\nextbox
+ \global\advance\boxvdisplacement-\boxoffset
+ \boxcursor\hskip\boxhdisplacement\raise-\boxvdisplacement\box\nextbox
+ \egroup}
+
+\def\syst_boxes_leftbottombox_finish
+ {\global\boxhdisplacement-\wd\nextbox
+ \global\advance\boxhdisplacement-\boxoffset
+ \global\boxvdisplacement\ht\nextbox
+ \global\advance\boxvdisplacement\boxoffset
+ \boxcursor\hskip\boxhdisplacement\lower\boxvdisplacement\box\nextbox
+ \egroup}
+
+\def\syst_boxes_rightbottombox_finish
+ {\global\boxhdisplacement\boxoffset
+ \global\boxvdisplacement\ht\nextbox
+ \global\advance\boxvdisplacement\boxoffset
+ \boxcursor\hskip\boxhdisplacement\lower\boxvdisplacement\box\nextbox
+ \egroup}
+
+\unexpanded\def\middlebox {\hbox\bgroup\dowithnextboxcs\syst_boxes_middlebox_finish \placedbox}
+\unexpanded\def\baselinemiddlebox{\hbox\bgroup\dowithnextboxcs\syst_boxes_baselinemiddlebox_finish\placedbox}
+\unexpanded\def\baselineleftbox {\hbox\bgroup\dowithnextboxcs\syst_boxes_baselineleftbox_finish \placedbox}
+\unexpanded\def\baselinerightbox {\hbox\bgroup\dowithnextboxcs\syst_boxes_baselinerightbox_finish \placedbox}
+
+\def\syst_boxes_middlebox_finish
+ {\global\boxhdisplacement-.5\wd\nextbox
+ \global\boxvdisplacement.5\ht\nextbox
+ \global\advance\boxvdisplacement-.5\dp\nextbox
+ \boxcursor\hskip\boxhdisplacement\lower\boxvdisplacement\box\nextbox
+ \egroup}
+
+\def\syst_boxes_baselinemiddlebox_finish
+ {\global\boxhdisplacement-.5\wd\nextbox
+ \global\advance\boxhdisplacement-\boxoffset
+ \global\boxvdisplacement-\boxoffset
+ \boxcursor\hskip\boxhdisplacement\raise-\boxvdisplacement\box\nextbox
+ \egroup}
+
+\def\syst_boxes_baselineleftbox_finish
+ {\global\boxhdisplacement-\wd\nextbox
+ \global\advance\boxhdisplacement-\boxoffset
+ \global\boxvdisplacement-\boxoffset
+ \boxcursor\hskip\boxhdisplacement\raise-\boxvdisplacement\box\nextbox
+ \egroup}
+
+\def\syst_boxes_baselinerightbox_finish
+ {\global\boxhdisplacement\boxoffset
+ \global\boxvdisplacement-\boxoffset
+ \boxcursor\hskip\boxhdisplacement\raise-\boxvdisplacement\box\nextbox
+ \egroup}
%D \macros
%D {obox}
%D
%D Experimental, not yet frozen:
-\def\lrtbbox#1#2#3#4% l r t b
+\unexpanded\def\lrtbbox#1#2#3#4% l r t b
{\bgroup
\dowithnextboxcontent
- {\advance\hsize-#1\advance\hsize-#2\advance\vsize-#3\advance\vsize-#4\relax}
+ {\advance\hsize-#1\advance\hsize-#2\relax
+ \advance\vsize-#3\advance\vsize-#4\relax}
{\forgetall\vbox to \vsize{\vskip#3\hbox to \hsize{\hskip#1\box\nextbox\hss}\vss}\egroup}
\vbox}
@@ -2229,18 +2318,19 @@
%D
%D See core-tbl.tex for an example of its usage:
-\def\toplinebox
- {\dowithnextbox
- {\ifdim\nextboxdp>\strutdepth
- \scratchdimen\nextboxdp
- \advance\scratchdimen-\strutdepth
- \getnoflines\scratchdimen
- \struttedbox{\flushnextbox}%
- \dorecurse\noflines\verticalstrut
- \else
- \flushnextbox
- \fi}%
- \tbox}
+\unexpanded\def\toplinebox
+ {\dowithnextboxcs\syst_boxes_toplinebox_finish\tbox}
+
+\def\syst_boxes_toplinebox_finish
+ {\ifdim\dp\nextbox>\strutdepth
+ \scratchdimen\dp\nextbox
+ \advance\scratchdimen-\strutdepth
+ \getnoflines\scratchdimen
+ \struttedbox{\box\nextbox}%
+ \dorecurse\noflines\verticalstrut
+ \else
+ \box\nextbox
+ \fi}
%D \macros
%D {initializeboxstack,savebox,foundbox}
@@ -2255,30 +2345,30 @@
%D \savebox{one}{p}{test p}
%D \savebox{one}{q}{test q}
%D
-%D \normalhbox{a:\foundbox{one}{a}} \par
-%D \normalhbox{q:\foundbox{one}{q}} \par
-%D \normalhbox{p:\foundbox{one}{p}} \par
-%D \normalhbox{x:\foundbox{one}{x}} \par
-%D \normalhbox{y:\foundbox{two}{a}} \par
+%D \hbox{a:\foundbox{one}{a}} \par
+%D \hbox{q:\foundbox{one}{q}} \par
+%D \hbox{p:\foundbox{one}{p}} \par
+%D \hbox{x:\foundbox{one}{x}} \par
+%D \hbox{y:\foundbox{two}{a}} \par
%D \stoptyping
\def\@@stackbox{@box@}
\def\@@stacklst{@xob@}
-\def\setstackbox#1#2%
+\unexpanded\def\setstackbox#1#2%
{\ifcsname\@@stackbox:#1:#2\endcsname\else
\expandafter\newbox\csname\@@stackbox:#1:#2\endcsname
\fi
- \global\setbox\csname\@@stackbox:#1:#2\endcsname\normalvbox}
+ \global\setbox\csname\@@stackbox:#1:#2\endcsname\vbox}
-\def\initializeboxstack#1%
+\unexpanded\def\initializeboxstack#1%
{\def\docommand##1{\setstackbox{#1}{##1}{}}%
\ifcsname\@@stacklst#1\endcsname
\processcommacommand[\getvalue{\@@stacklst#1}]\docommand
\fi
\letgvalueempty{\@@stacklst#1}}
-\def\savebox#1#2% stack name
+\unexpanded\def\savebox#1#2% stack name
{% beware, \setxvalue defines the cs beforehand so we cannot use the
% test inside the { }
\ifcsname\@@stacklst#1\endcsname
@@ -2288,13 +2378,13 @@
\fi
\setstackbox{#1}{#2}}
-\def\foundbox#1#2%
- {\normalvbox
+\unexpanded\def\foundbox#1#2%
+ {\vbox
{\ifcsname\@@stackbox:#1:#2\endcsname
\copy\csname\@@stackbox:#1:#2\endcsname
\fi}}
-\long\def\doifboxelse#1#2#3#4%
+\unexpanded\def\doifboxelse#1#2#3#4%
{\ifcsname\@@stackbox:#1:#2\endcsname
\ifvoid\csname\@@stackbox:#1:#2\endcsname#4\else#3\fi
\else
@@ -2308,25 +2398,34 @@
%D \type {\obeydepth} makes sure we have depth. Both macros
%D leave the \type {\prevdepth} untouched.
-\def\removedepth
- {\ifvmode \ifdim\prevdepth>\zeropoint \kern-\prevdepth \fi \fi}
+\unexpanded\def\removedepth
+ {\ifvmode
+ \ifdim\prevdepth>\zeropoint
+ \kern-\prevdepth
+ \fi
+ \fi}
-\def\obeydepth
- {\par \removedepth \ifvmode \kern\strutdp \fi}
+\unexpanded\def\obeydepth
+ {\par
+ \ifvmode
+ \ifdim\prevdepth>\zeropoint
+ \kern-\prevdepth
+ \fi
+ \kern\strutdp
+ \fi}
-\def\undepthed
- {\dowithnextbox{\nextboxdp\zeropoint\flushnextbox}\hbox}
+\unexpanded\def\undepthed
+ {\dowithnextbox{\dp\nextbox\zeropoint\box\nextbox}\hbox}
%D \macros
%D {removebottomthings, removelastskip}
%D
%D A funny (but rather stupid) one, plus a redefinition.
-\def\removebottomthings
+\unexpanded\def\removebottomthings
{\dorecurse5{\unskip\unkern\unpenalty}}
-\def\removelastskip % \ifvmode the plain tex one \fi
-% {\ifvmode\ifdim\lastskip=\zeropoint\else\vskip-\lastskip\fi\fi}
+\unexpanded\def\removelastskip % \ifvmode the plain tex one \fi
{\ifvmode\ifzeropt\lastskip\else\vskip-\lastskip\fi\fi}
%D \macros
@@ -2336,12 +2435,12 @@
%D strut.
\def\domakestrutofbox
- {\ht\registercount\strutht
- \dp\registercount\strutdp
- \wd\registercount\zeropoint}
+ {\ht\c_boxes_register\strutht
+ \dp\c_boxes_register\strutdp
+ \wd\c_boxes_register\zeropoint}
-\def\makestrutofbox
- {\afterassignment\domakestrutofbox\registercount}
+\unexpanded\def\makestrutofbox
+ {\afterassignment\domakestrutofbox\c_boxes_register}
%D \macros
%D {raisebox,lowerbox}
@@ -2351,49 +2450,67 @@
%D article.
%D
%D \starttyping
-%D \raisebox{100pt}\normalhbox{test}
-%D \raisebox50pt\normalhbox{test}
-%D \hsmash{\raisebox{100pt}\normalhbox{test}}
+%D \raisebox{100pt}\hbox{test}
+%D \hsmash{\raisebox{100pt}\hbox{test}}
%D \stoptyping
-\def\doraiselowerbox#1#2% a nice trick us used to accept
- {\def\next % both direct and {} dimensions
- {\dowithnextbox
- {\setbox\nextbox\normalhbox{#1\scratchdimen\flushnextbox}%
- \nextboxht\strutht
- \nextboxdp\strutdp
- \flushnextbox}}%
- \afterassignment\next\scratchdimen=#2}
+\unexpanded\def\raisebox#1{\bgroup\afterassignment\syst_boxes_raise_indeed\scratchdimen#1} % so both 10pt and {10pt} is accepted
+\unexpanded\def\lowerbox#1{\bgroup\afterassignment\syst_boxes_lower_indeed\scratchdimen#1} % so both 10pt and {10pt} is accepted
+
+\def\syst_boxes_raise_indeed{\dowithnextboxcs\syst_boxes_raise_finish}
+\def\syst_boxes_lower_indeed{\dowithnextboxcs\syst_boxes_lower_finish}
+
+\def\syst_boxes_raise_finish
+ {\setbox\nextbox\hbox{\raise\scratchdimen\box\nextbox}%
+ \ht\nextbox\strutht
+ \dp\nextbox\strutdp
+ \box\nextbox
+ \egroup}
-\def\raisebox{\doraiselowerbox\raise}
-\def\lowerbox{\doraiselowerbox\lower}
+\def\syst_boxes_lower_finish
+ {\setbox\nextbox\hbox{\lower\scratchdimen\box\nextbox}%
+ \ht\nextbox\strutht
+ \dp\nextbox\strutdp
+ \box\nextbox
+ \egroup}
% vcenter in text, we kunnen vcenter overloaden
-\def\halfwaybox
- {\dowithnextbox
- {\nextboxdp\zeropoint
- \setbox\nextbox\normalhbox{\lower.5\nextboxht\flushnextbox}%
- \flushnextbox}
- \normalhbox}
+\unexpanded\def\halfwaybox
+ {\hbox\bgroup
+ \dowithnextboxcs\syst_boxes_halfwaybox_finish\hbox}
+
+\def\syst_boxes_halfwaybox_finish
+ {\dp\nextbox\zeropoint
+ \lower.5\ht\nextbox\box\nextbox
+ \egroup}
+
+\unexpanded\def\depthonlybox
+ {\vtop\bgroup
+ \dowithnextboxcs\syst_boxes_depthonlybox_finish\vbox}
+
+\def\syst_boxes_depthonlybox_finish
+ {\hsize\wd\nextbox
+ \kern\zeropoint\box\nextbox
+ \egroup}
%D New:
-\def\setdimentoatleast#1#2%
- {\ifdim#1>\zeropoint\else#1=#2\fi}
+\def\setdimentoatleast#1#2{\ifdim#1>\zeropoint\else#1=#2\fi}
+\def\setdimentoatmost #1#2{\ifdim#1>#2\relax \else#1=#2\fi}
%D And even rawer:
-\let\naturalhbox \normalhbox
-\let\naturalvbox \normalvbox
-\let\naturalvtop \normalvtop
-\let\naturalvcenter \normalvtop
+\let\naturalhbox \hbox
+\let\naturalvbox \vbox
+\let\naturalvtop \normalvtop
+\let\naturalvcenter\normalvtop
\ifdefined\textdir
- \def\naturalhbox{\normalhbox dir TLT}
- \def\naturalvbox{\normalvbox dir TLT}
- %def\naturalvtop{\normalvtop dir TLT}
+ \unexpanded\def\naturalhbox{\hbox dir TLT}
+ \unexpanded\def\naturalvbox{\vbox dir TLT}
+ %\unexpanded\def\naturalvtop{\normalvtop dir TLT}
\fi
@@ -2402,39 +2519,50 @@
%D
%D Also new: tex mode \type {\vcenter}.
-\let\verynormalvcenter \vcenter % since \vcenter can be visualized
+\unexpanded\def\vcenter
+ {\vbox\bgroup
+ \dowithnextboxcs\syst_boxes_vcenter_finish\vbox}
-\def\vcenter
- {\normalvbox\bgroup
- \dowithnextbox{\normalhbox{$\verynormalvcenter{\flushnextbox}$}\egroup}
- \normalvbox}
+\def\syst_boxes_vcenter_finish
+ {\hbox{$\normalvcenter{\box\nextbox}$}%
+ \egroup}
% could be \everymathematics
\prependtoks \let\vcenter\normalvcenter \to \everymath
\prependtoks \let\vcenter\normalvcenter \to \everydisplay
+% \appendtoks \let\vcenter\normalvcenter \to \everymathematics
+
%D \macros
%D {frozenhbox}
%D
-%D A not so well unhboxable bxo can be made with:
+%D A not so well unhboxable box can be made with:
+
+\unexpanded\def\frozenhbox
+ {\hbox\bgroup
+ \dowithnextboxcs\syst_boxes_frozenhbox_finish\hbox}
-\def\frozenhbox
- {\hbox\bgroup\dowithnextbox{\hbox{\hbox{\flushnextbox}}\egroup}\hbox}
+\def\syst_boxes_frozenhbox_finish
+ {\hbox{\hbox{\box\nextbox}}%
+ \egroup}
%D \macros
%D {setboxllx,setboxlly,gsetboxllx,gsetboxlly,getboxllx,getboxlly}
%D
%D A prelude to an extended \TEX:
-\def\setboxllx#1#2{\setevalue{b@@x\number#1}{\the\dimexpr#2\relax}}
-\def\setboxlly#1#2{\setevalue{b@@y\number#1}{\the\dimexpr#2\relax}}
+\unexpanded\def\setboxllx #1#2{\expandafter\edef\csname boxes_x_\number#1\endcsname{\the\dimexpr#2\relax}}
+\unexpanded\def\setboxlly #1#2{\expandafter\edef\csname boxes_y_\number#1\endcsname{\the\dimexpr#2\relax}}
-\def\gsetboxllx{\global\setboxllx}
-\def\gsetboxlly{\global\setboxlly}
+\unexpanded\def\gsetboxllx#1#2{\expandafter\xdef\csname boxes_x_\number#1\endcsname{\the\dimexpr#2\relax}}
+\unexpanded\def\gsetboxlly#1#2{\expandafter\xdef\csname boxes_y_\number#1\endcsname{\the\dimexpr#2\relax}}
-\def\getboxllx#1{\executeifdefined{b@@x\number#1}\zeropoint}
-\def\getboxlly#1{\executeifdefined{b@@y\number#1}\zeropoint}
+\def\getboxllx#1{\ifcsname boxes_x_\number#1\endcsname\csname boxes_x_\number#1\endcsname\else\zeropoint\fi}
+\def\getboxlly#1{\ifcsname boxes_y_\number#1\endcsname\csname boxes_y_\number#1\endcsname\else\zeropoint\fi}
+
+\def\directgetboxllx#1{\csname boxes_x_\number#1\endcsname} % use when sure existence
+\def\directgetboxlly#1{\csname boxes_y_\number#1\endcsname} % use when sure existence
%D \macros
%D {shownextbox}
@@ -2449,7 +2577,7 @@
%D \shownextbox\vbox{\setupwhitespace[big]test\endgraf\thinrule}
%D \stoptyping
-\def\shownextbox
+\unexpanded\def\shownextbox % seldom used
{\dowithnextbox
{\bgroup
\showboxbreadth\maxdimen
@@ -2461,7 +2589,7 @@
\interactionmode\scratchcounter
\egroup}}
-\def\spreadhbox#1% rebuilds \hbox{<box><hss><box><hss><box>}
+\unexpanded\def\spreadhbox#1% rebuilds \hbox{<box><hss><box><hss><box>}
{\bgroup
\ifhbox#1\relax
\setbox2\emptybox
@@ -2499,3 +2627,48 @@
\ruledvbox to \strutheight{\hbox{\strut gans}}
\ruledvbox to \strutheight{\vss\hbox{gans}}
\egroup
+
+% to be considered
+
+% \startluacode
+%
+% local spacer = lpeg.patterns.spacer
+%
+% function commands.withwords(command,str)
+% if str then
+% command = command or "ruledhbox"
+% local done = false
+% local function apply(s)
+% if done then
+% context.space()
+% done = true
+% else
+% context.dontleavehmode()
+% end
+% context[command](s)
+% end
+% lpeg.match(lpeg.splitter(spacer,apply),str)
+% end
+%
+% end
+%
+% \stopluacode
+%
+% \unprotect
+%
+% \unexpanded\def\withwordsinstring#1#2% command str
+% {\ctxcommand{withwords(\!!bs#1\!!es,\!!bs#2\!!es)}}
+%
+% \unexpanded\def\withwordsinfile#1#2% command name
+% {\ctxcommand{withwords(\!!bs#1\!!es,io.loaddata(resolvers.findfile("#2")))}}
+%
+% \protect
+%
+% \starttext
+%
+% \defineframed[colored][foregroundcolor=red,foregroundstyle=\bfc\underbar,location=low]
+%
+% \withwordsinstring{colored}{bla bla}
+% \withwordsinfile{colored}{ward.tex}
+%
+% \stoptext