diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/pack-rul.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/pack-rul.mkiv | 3619 |
1 files changed, 1354 insertions, 2265 deletions
diff --git a/Master/texmf-dist/tex/context/base/pack-rul.mkiv b/Master/texmf-dist/tex/context/base/pack-rul.mkiv index c137aea01a2..f65641b96ca 100644 --- a/Master/texmf-dist/tex/context/base/pack-rul.mkiv +++ b/Master/texmf-dist/tex/context/base/pack-rul.mkiv @@ -5,7 +5,7 @@ %D subtitle=Ruled Content, %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 @@ -13,28 +13,19 @@ \writestatus{loading}{ConTeXt Packaging Macros / Ruled Content} -%D redo framedtexts like framedcontent (parameter stuff) +%D The code here is expanded lots of time as framed is used in +%D many places. This is why the code here is (and gets) optimized +%D as much as possible. Also, by avoiding packaging and expansion +%D we also keep tracing reasonable. For instance, multiple stacked +%D backgrounds can slow down a run if not optimized this way. -%D After a few months testing this solution is now added -%D to the core. This introduces a possible incompatibility -%D between \MKII\ and \MKIV\ but for the better. +% eventually this will use the commandhandler code (same trick as +% with itemize) \registerctxluafile{pack-rul}{1.001} -% old off new -% 4 lines oeps : 3.6 2.8 3.0 -% tufte 7.5 4.1 4.3 - \unprotect -%D We have removed the rather old and out dated raster methods. They -%D have not been used for ages. You can still find the old code in -%D the \MKII\ counterpart of this module. - -%D This module is rather optimized so sometimes readability has been -%D sacrisfied for speed. This is because the framing mechanism is used -%D all over the place. - %D \macros %D {linewidth, setuplinewidth} %D @@ -50,101 +41,276 @@ \newdimen\linewidth -\def\dosetuplinewidth[#1]% - {\assigndimension{#1}\linewidth{.2\points}{.4\points}{.6\points}} - \unexpanded\def\setuplinewidth - {\dosingleargument\dosetuplinewidth} - -%D \macros -%D {ruledlinewidth, inheritruledlinewidth} -%D -%D Inside framed boxed we will use a private dimensions. As -%D an option one can let the linewidth inherit its value from -%D this one. + {\dosingleargument\pack_framed_setup_line_width} -\newdimen\ruledlinewidth \newif\ifinheritruledlinewidth +\def\pack_framed_setup_line_width[#1]% + {\assigndimension{#1}\linewidth{.2\points}{.4\points}{.6\points}} %D \macros %D {setupscreens} %D -%D The previous macro uses a predefined constant -%D \type{\@@rsfactor}. This factor can be set by: +%D Sort of obsolete: %D %D \showsetup{setupscreens} \unexpanded\def\setupscreens {\dodoubleargument\getparameters[\??rs]} -%D We will communicate through module specific variables, current -%D framed parameters and some reserved dimension registers. +%D The parameter handler: -\newdimen \frameddimenwd -\newdimen \frameddimenht -\newdimen \frameddimendp +\installcorenamespace{framed} +\installcorenamespace{framedtop} +\installcorenamespace{framedbottom} +\installcorenamespace{framedleft} +\installcorenamespace{framedright} -%D We don't have to stick to a \TEX\ drawn rule, but -%D also can use rounded or even fancier shapes, as we will -%D see later on. +\let\currentframed\s!unknown % brrr must have a value -\def\dofilledbox - {\bgroup - \edef\@@framedfilledmod{\framedparameter\c!backgroundcorner}% - \ifx\@@framedfilledmod\v!rectangular - \dofilledlinedbox - \else\ifzeropt\dimexpr\framedparameter\c!backgroundradius\relax % just in case of .x\bodyfontsize - \dofilledlinedbox - \else - \dofilledroundbox - \fi\fi - \egroup} +% \def\framedparameter #1{\csname\doframedparameter\currentframed{#1}\endcsname} +% \def\framedparameterhash#1{\doframedparameterhash \currentframed#1} -\def\dophantombox - {\hphantom{\dofilledbox}} +\def\framedparameter #1{\csname\ifcsname\currentframed#1\endcsname\currentframed#1\else\expandafter\doframedparentparameter\csname\currentframed\s!parent\endcsname{#1}\fi\endcsname} +\def\framedparameterhash#1{\ifcsname\currentframed#1\endcsname\currentframed\else\expandafter\doframedparentparameterhash\csname\currentframed\s!parent\endcsname#1\fi} -\def\dofilledlinedbox - {\vrule\!!width\frameddimenwd\!!height\frameddimenht\!!depth\frameddimendp\relax}% +\def\doframedparameter #1#2{\ifcsname#1#2\endcsname#1#2\else\expandafter\doframedparentparameter \csname#1\s!parent\endcsname{#2}\fi} +\def\doframedparameterhash#1#2{\ifcsname#1#2\endcsname #1\else\expandafter\doframedparentparameterhash\csname#1\s!parent\endcsname#2\fi} -\def\dostrokedroundbox - {\doif{\framedparameter\c!frame}\v!on\dodostrokedroundbox} +\def\doframedparentparameter #1#2{\ifx#1\relax\s!empty\else\doframedparameter #1{#2}\fi} +\def\doframedparentparameterhash#1#2{\ifx#1\relax \else\doframedparameterhash#1#2\fi} -\def\dodostrokedroundbox - {\bgroup - \edef\ovalmod{\framedparameter\c!framecorner}% - \ifx\ovalmod\v!round - \let\ovalmod\!!zerocount +\def\doframedparentparameter#1#2{\ifx#1\relax\doframedrootparameter#2\else\doframedparameter#1{#2}\fi} +\def\doframedrootparameter #1{\ifcsname\??framed#1\endcsname\??framed#1\else\s!empty\fi} + +\def\useframedstyleandcolor#1#2% style color + {\edef\currentstyleparameter{\framedparameter#1}% + \edef\currentcolorparameter{\framedparameter#2}% + \ifx\currentstyleparameter\empty\else\dousestyleparameter\currentstyleparameter\fi + \ifx\currentcolorparameter\empty\else\dousecolorparameter\currentcolorparameter\fi} + +\def\frameddimension#1{\the\dimexpr\framedparameter{#1}\relax} + +% \unexpanded\def\installsomebackground#1#2{\inheritlocalframed[\??ma#1#2][\??od]} + +\let\normalframedparameter \framedparameter +\let\normalframedparameterhash\framedparameterhash + +\def\pack_framed_initialize#1% will be inlined + {\inframedtrue + \edef\currentframed{#1}% + \let\framedparameter \normalframedparameter + \let\framedparameterhash\normalframedparameterhash} + +\def\installinheritedframed#1% + {\normalexpanded{\doinstallinheritedframed + \expandafter\noexpand\csname current#1\endcsname + \expandafter\noexpand\csname #1parameter\endcsname + \expandafter\noexpand\csname #1parameterhash\endcsname + \expandafter\noexpand\csname do#1parameter\endcsname + \expandafter\noexpand\csname do#1parentparameter\endcsname + \expandafter\noexpand\csname do#1rootparameter\endcsname + \expandafter\noexpand\csname inherited#1framed\endcsname + \noexpand\??framed}} % if needed we can have a variant + +\unexpanded\def\doinstallinheritedframed#1#2#3#4#5#6#7#8% + {\def#5##1##2{\ifx##1\relax#6{##2}\else#4##1{##2}\fi}% + \def#6##1{\ifcsname#8##1\endcsname#8##1\else\s!empty\fi}% + \unexpanded\def#7% + {\bgroup + \bgroup + \inframedtrue + \let\currentframed #1% not used (more for tracing) + \let\framedparameter #2% + \let\framedparameterhash#3% + \pack_framed_process_indeed}} + +\unexpanded\def\installframedcommandhandler#1#2#3% + {\installcommandhandler{#1}{#2}{#3}% + \installinheritedframed{#2}} + +\unexpanded\def\installframedautocommandhandler#1#2#3% + {\installautocommandhandler{#1}{#2}{#3}% + \installinheritedframed{#2}} + +\unexpanded\def\installsimpleframedcommandhandler#1#2#3% + {\installsimplecommandhandler{#1}{#2}{#3}% + \installinheritedframed{#2}} + +% for regular framed + +\getparameters + [\??framed] + [\c!width=\v!fit, + \c!height=\v!broad, + %\c!lines=, + \c!offset=0.25ex, % \defaultframeoffset + \c!empty=\v!no, + \c!frame=\v!on, + %\c!topframe=, + %\c!bottomframe=, + %\c!leftframe=, + %\c!rightframe=, + \c!radius=.5\bodyfontsize, + \c!rulethickness=\linewidth, + \c!corner=\v!rectangular, + \c!depth=\zeropoint, + %\c!foregroundcolor=, + %\c!foregroundstyle=, + %\c!background=, + %\c!backgroundscreen=, + %\c!backgroundcolor=, + \c!backgroundoffset=\zeropoint, + %\c!framecolor=, + \c!frameoffset=\zeropoint, + \c!backgroundcorner=\framedparameter\c!corner, + \c!backgroundradius=\framedparameter\c!radius, + \c!backgrounddepth=\framedparameter\c!depth, + \c!framecorner=\framedparameter\c!corner, + \c!frameradius=\framedparameter\c!radius, + \c!framedepth=\framedparameter\c!depth, + %\c!component=, + %\c!region=, + %\c!align=, + \c!bottom=\vss, + %\c!top=, + \c!strut=\v!yes, + \c!autostrut=\v!yes, + \c!location=\v!normal, + %\c!orientation=, + \c!autowidth=\v!yes, + %\c!setups= + \c!loffset=\zeropoint, + \c!roffset=\zeropoint, + \c!toffset=\zeropoint, + \c!boffset=\zeropoint] + +% for backgrounds + +\getparameters + [\??od] % for fast version + [\c!frame=\v!off, + \c!depth=\zeropoint, + \c!offset=\v!overlay, + %\c!component=, + %\c!region=, + \c!radius=.5\bodyfontsize, + \c!rulethickness=\linewidth, + \c!corner=\v!rectangular, + \c!backgroundoffset=\zeropoint, + \c!frameoffset=\zeropoint, + \c!backgroundcorner=\framedparameter\c!corner, + \c!backgroundradius=\framedparameter\c!radius, + \c!backgrounddepth=\framedparameter\c!depth, + \c!framecorner=\framedparameter\c!corner, + \c!frameradius=\framedparameter\c!radius, + \c!framedepth=\framedparameter\c!depth, + \c!location=\v!normal, + \c!loffset=\zeropoint, + \c!roffset=\zeropoint, + \c!toffset=\zeropoint, + \c!boffset=\zeropoint] + +%D We will communicate through module specific variables, current +%D framed parameters and some reserved dimension registers. + +\newdimen\d_framed_target_wd +\newdimen\d_framed_target_ht +\newdimen\d_framed_target_dp +\newdimen\d_framed_linewidth + +\let\p_framed_frame \empty % \framedparameter\c!frame +\let\p_framed_backgroundoffset\empty +\let\p_framed_foregroundstyle \empty +\let\p_framed_autostrut \empty +\let\p_framed_location \empty +\let\p_framed_orientation \empty +\let\p_framed_autowidth \empty +\let\p_framed_franalyze \empty +\let\p_framed_backgroundcorner\empty +\let\p_framed_backgroundradius\empty +\let\p_framed_framecorner \empty +\let\p_framed_frameradius \empty +\let\p_framed_lines \empty +\let\p_framed_empty \empty +\let\p_framed_backgroundcolor \empty +\let\p_framed_backgroundscreen\empty +\let\p_framed_framecolor \empty +\let\p_framed_component \empty +\let\p_framed_region \empty +\let\p_framed_background \empty +\let\p_framed_rulethickness \empty +\let\p_framed_foregroundcolor \empty +\let\p_framed_setups \empty + +%D We don't have to stick to a \TEX\ drawn rule, but also can use rounded +%D or even fancier shapes, as we will see later on. + +\def\pack_framed_filled_box + {\edef\p_framed_backgroundcorner{\framedparameter\c!backgroundcorner}% + \ifx\p_framed_backgroundcorner\v!rectangular + \pack_framed_filled_box_normal \else - \edef\ovalmod{\number\ovalmod}% - \fi - \edef\ovalwid{\the\frameddimenwd}% - \edef\ovalhei{\the\frameddimenht}% - \edef\ovaldep{\the\frameddimendp}% - \edef\ovallin{\the\dimexpr\ruledlinewidth}% - \edef\ovalrad{\the\dimexpr\framedparameter\c!frameradius}% - \let\ovalstr\!!plusone - \let\ovalfil\!!zerocount -% \forcecolorhack - \doovalbox\ovalwid\ovalhei\ovaldep\ovallin\ovalrad\ovalstr\ovalfil\ovalmod - \egroup} + \pack_framed_filled_box_radius + \fi} -\def\dofilledroundbox - {\bgroup - \edef\ovalmod{\framedparameter\c!backgroundcorner}% - \ifx\ovalmod\v!round - \let\ovalmod\!!zerocount +\def\pack_framed_filled_box_normal + {\vrule + \!!width \d_framed_target_wd + \!!height\d_framed_target_ht + \!!depth \d_framed_target_dp + \relax} + +\def\pack_framed_filled_box_radius + {\edef\p_framed_backgroundradius{\framedparameter\c!backgroundradius}% + \ifzeropt\dimexpr\p_framed_backgroundradius\relax % just in case of .x\bodyfontsize + \pack_framed_filled_box_normal \else - \edef\ovalmod{\number\ovalmod}% - \fi - \edef\ovalwid{\the\frameddimenwd}% - \edef\ovalhei{\the\frameddimenht}% - \edef\ovaldep{\the\frameddimendp}% - \edef\ovallin{\the\dimexpr\ruledlinewidth\relax}% - \edef\ovalrad{\the\dimexpr\framedparameter\c!backgroundradius\relax}% - \let\ovalstr\!!zerocount - \let\ovalfil\!!plusone -% \forcecolorhack - \doovalbox\ovalwid\ovalhei\ovaldep\ovallin\ovalrad\ovalstr\ovalfil\ovalmod - \egroup} + \pack_framed_filled_box_round + \fi} + +\def\pack_framed_filled_box_round + {\normalexpanded{\doovalbox + {\the\d_framed_target_wd}% + {\the\d_framed_target_ht}% + {\the\d_framed_target_dp}% + {\the\dimexpr\d_framed_linewidth\relax}% + {\the\dimexpr\p_framed_backgroundradius\relax}% + {0}% + {1}% + {\ifx\p_framed_backgroundcorner\v!round0\else\number\p_framed_backgroundcorner\fi}% + }} + +\def\pack_framed_stroked_box + {\edef\p_framed_framecorner{\framedparameter\c!framecorner}% + \ifx\p_framed_framecorner\v!rectangular + \pack_framed_stroked_box_normal + \else + \pack_framed_stroked_box_radius + \fi} + +\def\pack_framed_stroked_box_radius + {\edef\p_framed_frameradius{\framedparameter\c!frameradius}% + \ifzeropt\dimexpr\p_framed_frameradius\relax % just in case of .x\bodyfontsize + \pack_framed_stroked_box_normal + \else + \ifx\p_framed_frame\v!on + \pack_framed_stroked_box_round + \fi + \fi} + +% \pack_framed_stroked_box_normal % later + +\def\pack_framed_stroked_box_round + {\normalexpanded{\doovalbox + {\the\d_framed_target_wd}% + {\the\d_framed_target_ht}% + {\the\d_framed_target_dp}% + {\the\dimexpr\d_framed_linewidth\relax}% + {\the\dimexpr\p_framed_frameradius\relax}% + {1}% + {0}% + {\ifx\p_framed_framecorner\v!round0\else\number\p_framed_framecorner\fi}% + }} % a lot of weird corners % @@ -195,30 +361,27 @@ %D The oval box is drawn using a special macro, depending on %D the driver in use. -\def\dograybox % avoid black rules when no gray - {\doifelsenothing{\framedparameter\c!backgroundscreen} - {\dophantombox} - {\raster[\framedparameter\c!backgroundscreen]{\dofilledbox}}} +\def\pack_framed_background_box_gray % avoid black rules when no gray + {\edef\p_framed_backgroundscreen{\framedparameter\c!backgroundscreen}% + \ifx\p_framed_backgroundscreen\empty \else + \pack_framed_background_box_gray_indeed + \fi} + +\def\pack_framed_background_box_gray_indeed % can be more direct but who cares, just compatibility + {\colored[s=\p_framed_backgroundscreen]{\pack_framed_filled_box}} %D It won't be a surprise that we not only provide gray boxes, %D but also colored ones. Here it is: -\def\dobackgroundcolorbox - {\hbox{\faststartcolor[\framedbackgroundcolor]\dofilledbox\faststopcolor}} - %{\hbox{\doactivatecolor\framedbackgroundcolor\dofilledbox}} - -\def\docolorbox % can be more of \color[] -> \faststartcolor in mkiv - {\ifincolor - \edef\framedbackgroundcolor{\framedparameter\c!backgroundcolor}% - \ifx\framedbackgroundcolor\empty - \dophantombox - \else - \doifcolorelse\framedbackgroundcolor\dobackgroundcolorbox\dophantombox - \fi - \else - \dophantombox +\def\pack_framed_background_box_color + {\edef\p_framed_backgroundcolor{\framedparameter\c!backgroundcolor}% + \ifx\p_framed_backgroundcolor\empty \else + \doifcolor\p_framed_backgroundcolor\pack_framed_background_box_color_indeed \fi} +\def\pack_framed_background_box_color_indeed + {\hbox{\dousecolorparameter\p_framed_backgroundcolor\pack_framed_filled_box}} + %D \macros %D {defineoverlay, doifoverlayelse, overlayoffset, %D overlaywidth, overlayheight, overlaydepth, @@ -279,11 +442,11 @@ \def\overlaywidth {\the\hsize\space} % We preset the variables \def\overlayheight {\the\vsize\space} % to some reasonable default -\let\overlaydepth \!!zeropoint % values. The attributes -\let\overlayoffset \!!zeropoint % of the frame can be (are) -\let\overlaycolor \empty % set somewhere else. -\let\overlaylinewidth \!!zeropoint % -\let\overlaylinecolor \empty % +\def\overlaydepth {0pt } % values. The attributes +\let\overlayoffset \overlaydepth % of the frame can be (are) +\let\overlaylinewidth \overlaydepth % set somewhere else. +\let\overlaycolor \empty +\let\overlaylinecolor \empty %D The next register is used to initialize overlays. @@ -293,148 +456,182 @@ %D can contain text and be executed under an regime where %D interlineskip is off). -\appendtoks \oninterlineskip \to \everyoverlay - -\unexpanded\def\defineoverlay - {\dodoubleargument\dodefineoverlay} +\installcorenamespace{overlay} +\installcorenamespace{overlaybuiltin} -\def\dodefineoverlay[#1][#2]% - {\def\docommand##1{\setvalue{\??ov##1}{\executedefinedoverlay{##1}{#2}}}% - \processcommalist[#1]\docommand} +\appendtoks + \oninterlineskip +\to \everyoverlay \prependtoks - \hsize\overlaywidth - \vsize\overlayheight -\to\everyoverlay + \hsize\overlaywidth + \vsize\overlayheight +\to \everyoverlay -\long\def\executedefinedoverlay#1#2% - {\bgroup - \setlayoutcomponentattribute\v!overlay{#1}% - \edef\overlaywidth {\the\frameddimenwd\space}% - \edef\overlayheight{\the\dimexpr\frameddimenht+\frameddimendp\relax\space}% - \edef\overlaydepth {\the\frameddimendp\space}% - \edef\overlaycolor {\framedparameter\c!backgroundcolor}% - %\edef\overlaycorner{\framedparameter\c!backgroundcorner}% - %\edef\overlayradius{\framedparameter\c!backgroundradius}% - \let\overlayoffset\backgroundoffset % we steal this one - \setbox\scratchbox\hbox{\lower\overlaydepth\hbox{\the\everyoverlay#2}}% +\unexpanded\def\defineoverlay + {\dodoubleargument\pack_framed_define_overlay} + +\def\pack_framed_define_overlay[#1][#2]% + {\def\pack_framed_define_overlay_indeed##1{\setvalue{\??overlay##1}{\executedefinedoverlay{##1}{#2}}}% + \processcommalist[#1]\pack_framed_define_overlay_indeed} + +\unexpanded\def\executedefinedoverlay#1#2% we can share the definitions + {\bgroup % redundant grouping + \setbox\scratchbox\hbox\bgroup + \ifzeropt\d_framed_target_dp + \the\everyoverlay#2% saves wrapping (and lua call) + \else + \lower\d_framed_target_dp + \hbox{\the\everyoverlay#2}% + \fi + \egroup + \setlayoutcomponentattribute{\v!overlay:#1}% \setbox\scratchbox\hbox \layoutcomponentboxattribute - {\hskip-.5\dimexpr\wd\scratchbox-\overlaywidth \relax - \raise-.5\dimexpr\ht\scratchbox-\frameddimenht\relax % not overlayheight ! + {\kern -.5\dimexpr\wd\scratchbox-\d_framed_target_wd\relax % was \overlaywidth + \raise-.5\dimexpr\ht\scratchbox-\d_framed_target_ht\relax % not \overlayheight ! \box\scratchbox}% - \wd\scratchbox\frameddimenwd - \ht\scratchbox\frameddimenht - \dp\scratchbox\frameddimendp + \wd\scratchbox\d_framed_target_wd + \ht\scratchbox\d_framed_target_ht + \dp\scratchbox\d_framed_target_dp \box\scratchbox \egroup} %D \macros %D {overlayfakebox} -\def\overlayfakebox +\unexpanded\def\overlayfakebox {\hbox {\setbox\scratchbox\emptyhbox \wd\scratchbox\overlaywidth \ht\scratchbox\overlayheight \box\scratchbox}} -%D The empty case is: - -\let\executeoverlay\gobblesevenarguments - %D For testing we provide: -\def\doifoverlayelse#1% - {\ifcsname\??ov#1\endcsname +\def\doifoverlayelse#1% only tests external overlays + {\ifcsname\??overlay#1\endcsname \expandafter\firstoftwoarguments \else \expandafter\secondoftwoarguments \fi} -%D We predefine two already familiar backgrounds: - -\setvalue{\??ov\v!screen}{\dograybox } -\setvalue{\??ov\v!color }{\docolorbox} - -% %D After all these preparations, the background macro does no -% %D bring to many surprises. One has to keep in mind that this -% %D macro starts up a call chain, depending on the background -% %D one needs: -% %D -% %D \startitemize[packed] -% %D \item a raster, color or user defined shape -% %D \item square or round corners -% %D \item a \TEX\ or driver based method -% %D \stopitemize -% %D -% %D The macro can be extended by adding commands to the token -% %D list register \type {\everybackgroundbox}. For this -% %D purpose, the name of the current background is available in -% %D \type {\currentbackgound}. - %D The content of the box will be (temporary) saved in a box. We %D also have an extra box for backgrounds. -\newbox\framebox -\newbox\extraframebox +\newbox\b_framed_normal +\newbox\b_framed_extra \newtoks\everybackgroundbox \let\currentbackground\empty -\def\dodobackgroundbox +\def\pack_framed_process_background + {\ifcsname\??overlaybuiltin\currentbackground\endcsname + \pack_framed_process_background_indeed_internal + \else\ifcsname\??overlay\currentbackground\endcsname + \pack_framed_process_background_indeed_external + \fi\fi} + +\def\pack_framed_process_background_indeed_internal % : in name {\bgroup - \ifcsname\??ov\currentbackground\endcsname - \the\everybackgroundbox - \setbox\extraframebox\hbox{\vbox{\moveleft\backgroundoffset\hbox{\csname\??ov\currentbackground\endcsname}}}% - \wd\extraframebox\zeropoint % \backgroundwidth - \ht\extraframebox\backgroundheight - \dp\extraframebox\backgrounddepth - \box\extraframebox % \hskip-\backgroundwidth - \fi + \setbox\b_framed_extra\hbox{%\bgroup + \ifzeropt\framedbackgroundoffset + \csname\??overlaybuiltin\currentbackground\endcsname + \else + \kern-\framedbackgroundoffset + \hbox{\csname\??overlaybuiltin\currentbackground\endcsname}% + \fi + }%\egroup + \wd\b_framed_extra\zeropoint + \ht\b_framed_extra\framedbackgroundheight + \dp\b_framed_extra\framedbackgrounddepth + \box\b_framed_extra + \egroup} + +\def\pack_framed_process_background_indeed_external + {\pack_framed_overlay_initialize + \bgroup + \setbox\b_framed_extra\hbox{%\bgroup + \ifzeropt\framedbackgroundoffset + \csname\??overlay\currentbackground\endcsname + \else + \kern-\framedbackgroundoffset + \hbox{\csname\??overlay\currentbackground\endcsname}% + \fi + }%\egroup + \wd\b_framed_extra\zeropoint + \ht\b_framed_extra\framedbackgroundheight + \dp\b_framed_extra\framedbackgrounddepth + \box\b_framed_extra \egroup} -\def\dododobackgroundbox#1,#2% #2 gobbles spaces +\def\pack_framed_process_backgrounds#1,#2% #2 gobbles spaces (we could avoid one catch if we have nextbackground) {\edef\currentbackground{#1}% - \ifx\currentbackground\s!unknown\else % use $ instead of s!unknown - \dodobackgroundbox\expandafter\dododobackgroundbox + \ifx\currentbackground\s!unknown\else + \pack_framed_process_background + \expandafter\pack_framed_process_backgrounds \fi#2} -\let\backgroundoffset\!!zeropoint -\let\backgrounddepth \!!zeropoint -\def\backgroundwidth {\the\hsize} -\def\backgroundheight{\the\vsize} +% beware, a backgroundbox can be empty which is another reason +% why we set the width to zero instead of back-skipping -\def\normalforegroundbox% fuzzy but needed hack, this \vss, otherwise - {\vbox to \backgroundheight{\vss\box\framebox\vss}}% vertical shift +\newdimen\framedbackgroundwidth +\newdimen\framedbackgroundheight +\newdimen\framedbackgrounddepth +\newdimen\framedbackgroundoffset -\def\dobackedbox - {\setbox\framebox\vbox - {\framedforgetall +\def\pack_framed_background_box_content% fuzzy but needed hack, this \vss, otherwise + {\vbox to \framedbackgroundheight{\vss\box\b_framed_normal\vss}} % vertical shift \backgroundheight + +\def\pack_framed_add_region % experiment + {\anch_mark_region_box\b_framed_normal} + +\def\pack_framed_add_background + {\setbox\b_framed_normal\hbox % was vbox + {\pack_framed_forgetall % can be relaxed \boxmaxdepth\maxdimen - \frameddimenwd\dimexpr\wd\framebox+2\!!framedbackgroundoffset\relax - \frameddimenht\dimexpr\ht\framebox+ \!!framedbackgroundoffset\relax - \frameddimendp\dimexpr\dp\framebox+ \!!framedbackgroundoffset+\framedparameter\c!backgrounddepth\relax - \edef\backgroundoffset{\the\!!framedbackgroundoffset}% - \edef\backgroundwidth {\the\wd\framebox}% - \edef\backgroundheight{\the\ht\framebox}% - \edef\backgrounddepth {\the\dp\framebox}% - %\edef\foregroundbox{\box#1}% - \edef\component{\framedparameter\c!component}% - \ifx\component\empty + \framedbackgroundoffset\d_framed_backgroundoffset + \framedbackgroundwidth \wd\b_framed_normal + \framedbackgroundheight\ht\b_framed_normal + \framedbackgrounddepth \dp\b_framed_normal + \d_framed_target_wd\dimexpr\framedbackgroundwidth +2\framedbackgroundoffset\relax + \d_framed_target_ht\dimexpr\framedbackgroundheight+ \framedbackgroundoffset\relax + \d_framed_target_dp\dimexpr\framedbackgrounddepth + \framedbackgroundoffset+\framedparameter\c!backgrounddepth\relax + \let\pack_framed_overlay_initialize\pack_framed_overlay_initialize_indeed + \ifx\p_framed_component\empty \resetlayoutcomponentattribute \else - \setlayoutcomponentattribute\v!background\component + \setlayoutcomponentattribute{\v!background:\p_framed_component}% \fi - \let\foregroundbox\normalforegroundbox - \hbox \layoutcomponentboxattribute to \backgroundwidth % width in case 'foreground' is used as overlay - {\expandafter\dododobackgroundbox\framedbackground,\s!unknown,\relax % hm, messy .. look into it - \box\framebox\hss}}} + \let\foregroundbox\pack_framed_background_box_content + \hbox \layoutcomponentboxattribute to \framedbackgroundwidth\bgroup % width in case 'foreground' is used as overlay + \the\everybackgroundbox % moved + \expandafter\pack_framed_process_backgrounds\p_framed_background,\s!unknown,\relax % hm, messy .. look into it + \box\b_framed_normal + \hss + \egroup}} + +\def\pack_framed_overlay_initialize_indeed + {%\writestatus{!!!!}{<<<<<}% + \edef\overlaywidth {\the\d_framed_target_wd\space}% + \edef\overlayheight {\the\dimexpr\d_framed_target_ht+\d_framed_target_dp\relax\space}% + \edef\overlaydepth {\the\d_framed_target_dp\space}% + \edef\overlaycolor {\framedparameter\c!backgroundcolor}% let ? + \edef\overlaylinecolor{\framedparameter\c!framecolor}% only needed for layers + \edef\overlaylinewidth{\the\d_framed_linewidth\space}% + %\edef\overlaycorner {\framedparameter\c!backgroundcorner}% + %\edef\overlayradius {\framedparameter\c!backgroundradius}% + \edef\overlayoffset {\the\framedbackgroundoffset\space}% \backgroundoffset % we steal this one + \let\pack_framed_overlay_initialize\relax} %D One can explictly insert the foreground box. For that %D purpose we introduce the overlay \type {foreground}. +%D +%D We predefine two already familiar backgrounds: -\defineoverlay[\v!foreground][\foregroundbox] +\letvalue{\??overlaybuiltin\v!screen }\pack_framed_background_box_gray +\letvalue{\??overlaybuiltin\v!color }\pack_framed_background_box_color +\letvalue{\??overlaybuiltin\v!foreground}\pack_framed_background_box_content % replaces: \defineoverlay[\v!foreground][\foregroundbox] %D We can specify overlays as a comma separated list of %D overlays, a sometimes handy feature. @@ -445,122 +642,94 @@ %D by \TEX\ itself, the latter one depends on the driver. This %D macro also support a negative offset. -\def\dooutlinebox % we needed to move the color command in order to apply attributes properly - {\setbox\framebox\vbox % rules on top of box - {\frameddimenwd\dimexpr\wd\framebox+2\!!framedframeoffset\relax - \frameddimenht\dimexpr\ht\framebox+ \!!framedframeoffset\relax - \frameddimendp\dimexpr\dp\framebox+ \!!framedframeoffset+\framedparameter\c!framedepth\relax - \ifdim\frameddimendp<\zeropoint - \advance\frameddimenht \frameddimendp - \scratchdimen-\frameddimendp - \frameddimendp\zeropoint +\def\pack_framed_add_outline + {\setbox\b_framed_normal\hbox % rules on top of box + {\d_framed_target_wd\dimexpr\wd\b_framed_normal+2\d_framed_frameoffset\relax + \d_framed_target_ht\dimexpr\ht\b_framed_normal+ \d_framed_frameoffset\relax + \d_framed_target_dp\dimexpr\dp\b_framed_normal+ \d_framed_frameoffset+\framedparameter\c!framedepth\relax + \ifdim\d_framed_target_dp<\zeropoint + \advance\d_framed_target_ht \d_framed_target_dp + \scratchdimen-\d_framed_target_dp + \d_framed_target_dp\zeropoint \else \scratchdimen\zeropoint \fi - \setbox\extraframebox\hbox - {\doifsomething{\framedparameter\c!framecolor}{\color[\framedparameter\c!framecolor]}{\dostrokedbox}}% - \setbox\extraframebox\hbox - {\raise\scratchdimen\vbox - {\moveleft\!!framedframeoffset - \box\extraframebox}}% - \wd\extraframebox\wd\framebox - \ht\extraframebox\ht\framebox - \dp\extraframebox\dp\framebox - \hbox{\box\framebox\hskip-\wd\extraframebox\box\extraframebox}}} - -\def\dostrokedbox - {\edef\@@framedcornermod{\framedparameter\c!framecorner}% - \ifx\@@framedcornermod\v!rectangular - \dostrokedlinedbox - \else\ifzeropt\dimexpr\framedparameter\c!frameradius\relax % just in case of .x\bodyfontsize - \dostrokedlinedbox - \else - \dostrokedroundbox - \fi\fi} - -\def\dostrokedlinedbox + \edef\overlaylinecolor{\framedparameter\c!framecolor}% twice, also in background + \setbox\b_framed_extra\hbox + {\kern-\d_framed_frameoffset + \raise\scratchdimen + \hbox{\ifx\overlaylinecolor\empty\else\dousecolorparameter\overlaylinecolor\fi\pack_framed_stroked_box}}% + \wd\b_framed_extra\wd\b_framed_normal + \ht\b_framed_extra\ht\b_framed_normal + \dp\b_framed_extra\dp\b_framed_normal + \wd\b_framed_normal\zeropoint + \box\b_framed_normal + \box\b_framed_extra}} + +\def\pack_framed_stroked_box_normal {\setbox\scratchbox\emptyhbox - \wd\scratchbox\frameddimenwd - \ht\scratchbox\frameddimenht - \dp\scratchbox\frameddimendp + \wd\scratchbox\d_framed_target_wd + \ht\scratchbox\d_framed_target_ht + \dp\scratchbox\d_framed_target_dp \setbox\scratchbox\vbox \bgroup - \csname t\@@frame@@\framedparameter\c!frame\framedparameter\c!topframe \endcsname + \csname \??framedtop\p_framed_frame\framedparameter\c!topframe \endcsname + \nointerlineskip % new (needed for fences) \hbox \bgroup - \csname l\@@frame@@\framedparameter\c!frame\framedparameter\c!leftframe \endcsname + \csname \??framedleft\p_framed_frame\framedparameter\c!leftframe \endcsname \box\scratchbox - \csname r\@@frame@@\framedparameter\c!frame\framedparameter\c!rightframe \endcsname + \csname \??framedright\p_framed_frame\framedparameter\c!rightframe \endcsname \egroup - \csname b\@@frame@@\framedparameter\c!frame\framedparameter\c!bottomframe\endcsname + \nointerlineskip % new (needed for fences) + \csname \??framedbottom\p_framed_frame\framedparameter\c!bottomframe\endcsname \egroup - \wd\scratchbox\frameddimenwd - \ht\scratchbox\frameddimenht - \dp\scratchbox\frameddimendp + \wd\scratchbox\d_framed_target_wd + \ht\scratchbox\d_framed_target_ht + \dp\scratchbox\d_framed_target_dp \box\scratchbox} -\def\@@frame@@{@@frame@@} - -% \setvalue{t\@@frame@@\v!on \v!on}{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth} -% \setvalue{t\@@frame@@\v!off\v!on}{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth} -% \setvalue{t\@@frame@@\v!on }{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth} -% \setvalue{b\@@frame@@\v!on \v!on}{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth} -% \setvalue{b\@@frame@@\v!off\v!on}{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth} -% \setvalue{b\@@frame@@\v!on }{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth} -% \setvalue{l\@@frame@@\v!on \v!on}{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth} -% \setvalue{l\@@frame@@\v!off\v!on}{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth} -% \setvalue{l\@@frame@@\v!on }{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth} -% \setvalue{r\@@frame@@\v!on \v!on}{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth} -% \setvalue{r\@@frame@@\v!off\v!on}{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth} -% \setvalue{r\@@frame@@\v!on }{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth} - -\def\@@frame@@trule{\hrule\!!height\ruledlinewidth\kern-\ruledlinewidth} -\def\@@frame@@brule{\kern-\ruledlinewidth\hrule\!!height\ruledlinewidth} -\def\@@frame@@rrule{\kern-\ruledlinewidth\vrule\!!width\ruledlinewidth} -\def\@@frame@@lrule{\vrule\!!width\ruledlinewidth\kern-\ruledlinewidth} - -\letvalue{t\@@frame@@\v!on \v!on}\@@frame@@trule -\letvalue{t\@@frame@@\v!off\v!on}\@@frame@@trule -\letvalue{t\@@frame@@\v!on }\@@frame@@trule - -\letvalue{b\@@frame@@\v!on \v!on}\@@frame@@brule -\letvalue{b\@@frame@@\v!off\v!on}\@@frame@@brule -\letvalue{b\@@frame@@\v!on }\@@frame@@brule - -\letvalue{l\@@frame@@\v!on \v!on}\@@frame@@lrule -\letvalue{l\@@frame@@\v!off\v!on}\@@frame@@lrule -\letvalue{l\@@frame@@\v!on }\@@frame@@lrule - -\letvalue{r\@@frame@@\v!on \v!on}\@@frame@@rrule -\letvalue{r\@@frame@@\v!off\v!on}\@@frame@@rrule -\letvalue{r\@@frame@@\v!on }\@@frame@@rrule +\def\pack_framed_t_rule{\hrule\!!height\d_framed_linewidth\kern-\d_framed_linewidth} +\def\pack_framed_b_rule{\kern-\d_framed_linewidth\hrule\!!height\d_framed_linewidth} +\def\pack_framed_r_rule{\kern-\d_framed_linewidth\vrule\!!width\d_framed_linewidth} +\def\pack_framed_l_rule{\vrule\!!width\d_framed_linewidth\kern-\d_framed_linewidth} -% no overlapping rules +\letvalue{\??framedtop \v!on \v!on}\pack_framed_t_rule +\letvalue{\??framedtop \v!off\v!on}\pack_framed_t_rule +\letvalue{\??framedtop \v!on }\pack_framed_t_rule + +\letvalue{\??framedbottom\v!on \v!on}\pack_framed_b_rule +\letvalue{\??framedbottom\v!off\v!on}\pack_framed_b_rule +\letvalue{\??framedbottom\v!on }\pack_framed_b_rule -\def\@@frame@@trules{\hbox{\kern\ruledlinewidth\vrule\!!width\dimexpr\frameddimenwd-2\ruledlinewidth\relax\!!height\ruledlinewidth}\nointerlineskip\kern-\ruledlinewidth} -\def\@@frame@@brules{\kern-\ruledlinewidth\nointerlineskip\hbox{\kern\ruledlinewidth\vrule\!!width\dimexpr\frameddimenwd-2\ruledlinewidth\relax\!!height\ruledlinewidth}} -\def\@@frame@@rrules{\kern-\ruledlinewidth\vrule\!!height\dimexpr\frameddimenht-\ruledlinewidth\relax\!!depth-\ruledlinewidth\!!width\ruledlinewidth} -\def\@@frame@@lrules{\vrule\!!height\dimexpr\frameddimenht-\ruledlinewidth\relax\!!depth-\ruledlinewidth\!!width\ruledlinewidth\kern-\ruledlinewidth} +\letvalue{\??framedleft \v!on \v!on}\pack_framed_l_rule +\letvalue{\??framedleft \v!off\v!on}\pack_framed_l_rule +\letvalue{\??framedleft \v!on }\pack_framed_l_rule -% small is relatively new +\letvalue{\??framedright \v!on \v!on}\pack_framed_r_rule +\letvalue{\??framedright \v!off\v!on}\pack_framed_r_rule +\letvalue{\??framedright \v!on }\pack_framed_r_rule -\letvalue{t\@@frame@@\v!small\v!small}\@@frame@@trules -\letvalue{t\@@frame@@\v!off \v!small}\@@frame@@trules -\letvalue{t\@@frame@@\v!small }\@@frame@@trules +% no overlapping rules -\letvalue{b\@@frame@@\v!small\v!small}\@@frame@@brules -\letvalue{b\@@frame@@\v!off \v!small}\@@frame@@brules -\letvalue{b\@@frame@@\v!small }\@@frame@@brules +\def\pack_framed_t_rules{\hbox{\kern\d_framed_linewidth\vrule\!!width\dimexpr\d_framed_target_wd-2\d_framed_linewidth\relax\!!height\d_framed_linewidth}\nointerlineskip\kern-\d_framed_linewidth} +\def\pack_framed_b_rules{\kern-\d_framed_linewidth\nointerlineskip\hbox{\kern\d_framed_linewidth\vrule\!!width\dimexpr\d_framed_target_wd-2\d_framed_linewidth\relax\!!height\d_framed_linewidth}} +\def\pack_framed_r_rules{\kern-\d_framed_linewidth\vrule\!!height\dimexpr\d_framed_target_ht-\d_framed_linewidth\relax\!!depth-\d_framed_linewidth\!!width\d_framed_linewidth} +\def\pack_framed_l_rules{\vrule\!!height\dimexpr\d_framed_target_ht-\d_framed_linewidth\relax\!!depth-\d_framed_linewidth\!!width\d_framed_linewidth\kern-\d_framed_linewidth} -\letvalue{l\@@frame@@\v!small\v!small}\@@frame@@lrules -\letvalue{l\@@frame@@\v!off \v!small}\@@frame@@lrules -\letvalue{l\@@frame@@\v!small }\@@frame@@lrules +\letvalue{\??framedtop \v!small\v!small}\pack_framed_t_rules +\letvalue{\??framedtop \v!off \v!small}\pack_framed_t_rules +\letvalue{\??framedtop \v!small }\pack_framed_t_rules -\letvalue{r\@@frame@@\v!small\v!small}\@@frame@@rrules -\letvalue{r\@@frame@@\v!off \v!small}\@@frame@@rrules -\letvalue{r\@@frame@@\v!small }\@@frame@@rrules +\letvalue{\??framedbottom\v!small\v!small}\pack_framed_b_rules +\letvalue{\??framedbottom\v!off \v!small}\pack_framed_b_rules +\letvalue{\??framedbottom\v!small }\pack_framed_b_rules -%D I condidered using the low level support command -%D \type{\ruledhbox}, but this would slow down processing by a -%D factor~3. +\letvalue{\??framedleft \v!small\v!small}\pack_framed_l_rules +\letvalue{\??framedleft \v!off \v!small}\pack_framed_l_rules +\letvalue{\??framedleft \v!small }\pack_framed_l_rules + +\letvalue{\??framedright \v!small\v!small}\pack_framed_r_rules +\letvalue{\??framedright \v!off \v!small}\pack_framed_r_rules +\letvalue{\??framedright \v!small }\pack_framed_r_rules % \framed % [width=4cm,height=3cm,rulethickness=3mm, @@ -581,20 +750,18 @@ %D start with defining some booleans. These give an impression %D of what we are going to take into account. -\newif\ifboxhasoffset -\newif\ifboxhaswidth -\newif\ifboxhasheight -\newif\ifboxhasformat -\newif\ifboxhasstrut -\newif\ifboxisoverlaid -\newif\ifboxhasframe -\newif\ifdelayedstrut -\newif\ifboxhasextraoffset - -%D We also need a few \DIMENSIONS: +% todo : \c_framed_hasoffset +% faster : \let\c_framed_hasoffset\falseconditional -\newdimen\@@localoffset -\newdimen\@@globalwidth +\newconditional\c_framed_has_offset +\newconditional\c_framed_has_width +\newconditional\c_framed_has_height +\newconditional\c_framed_has_format +\newconditional\c_framed_has_strut +\newconditional\c_framed_is_overlaid +\newconditional\c_framed_has_frame +\newconditional\c_framed_has_extra_offset +\newconditional\c_framed_text_location_none %D \macros %D {framed, setupframed} @@ -616,9 +783,8 @@ \def\defaultframeoffset{.25ex} -\def\presetlocalframed [#1]{\letvalue{#1\s!parent}\??oi} -\def\inheritlocalframed[#1]#2[#3]{\letvalue{#1\s!parent}#3} -\def\copylocalframed [#1]#2[#3]{\setvalue{#1\s!parent}{#3}} +\def\presetlocalframed [#1]{\letvalue {#1\s!parent}\??framed} +\def\inheritlocalframed[#1]#2[#3]{\setevalue{#1\s!parent}{#3}} \presetlocalframed[\??ol] @@ -628,17 +794,28 @@ {\bgroup \advance\framednesting\plusone \expandafter\let\csname\??ol:\the\framednesting\s!parent\endcsname\??ol - \dodoubleempty\dolocalframed[\??ol:\the\framednesting]} + \dodoubleempty\pack_framed_process[\??ol:\the\framednesting]} + +\unexpanded\def\startframed + {\dosingleempty\pack_framed_start_framed} + +\def\pack_framed_start_framed[#1]% + {\bgroup + \advance\framednesting\plusone + \expandafter\let\csname\??ol:\the\framednesting\s!parent\endcsname\??ol + \pack_framed_process[\??ol:\the\framednesting][#1]% + \bgroup} + +\let\stopframed\egroup \unexpanded\def\setupframed {\dodoubleempty\dosetupframed} -% \def\dosetupframed -% {\ifsecondargument -% \@EA\dodoublesetupframed -% \else -% \@EA\dosinglesetupframed -% \fi} +\unexpanded\def\normalframedwithsettings + {\bgroup + \advance\framednesting\plusone + \expandafter\let\csname\??ol:\the\framednesting\s!parent\endcsname\??ol + \pack_framed_process[\??ol:\the\framednesting]} % we can consider setting the parent of the regular framed to % something else in the otr so that we isolate it there @@ -650,17 +827,6 @@ \getparameters[\??ol][#1]% \fi} -% \def\dosinglesetupframed[#1][#2]% -% {\getparameters[\??ol][#1]} - -% \def\dodoublesetupframed[#1][#2]% -% {\bgroup -% \let\dodoubleempty\empty -% \def\doframed[##1]{\gdef\globalredefinedframed{\dodoubleempty\doframed[##1,#2]}}% -% \getvalue{#1}% -% \egroup -% \letvalue{#1}\globalredefinedframed} - %D \startbuffer %D \setupframed [framecolor=yellow] \framed{A} %D \defineframed[myframed] [framecolor=blue] \myframed{B} @@ -695,257 +861,145 @@ \unexpanded\def\fastlocalframed[#1]#2[#3]#4% 3-4 {\bgroup - \inframedtrue - \edef\@@framed{#1}% - \setbox\framebox\hbox{#4}% - \getparameters[\@@framed][#3]% no \expanded ! - \!!framedframeoffset\framedparameter\c!frameoffset - \edef\@@framedbackgroundoffset{\framedparameter\c!backgroundoffset}% - \ifx\@@framedbackgroundoffset\v!frame - \!!framedbackgroundoffset\!!framedframeoffset - \else - \!!framedbackgroundoffset\@@framedbackgroundoffset + \pack_framed_initialize{#1}% + \setbox\b_framed_normal\hbox{#4}% + \edef\p_framed_region{\framedparameter\c!region}% + \ifx\p_framed_region\v!yes % maybe later named + \pack_framed_add_region \fi + \getparameters[\currentframed][#3]% no \expanded ! + \edef\p_framed_rulethickness{\framedparameter\c!rulethickness}% also used in backgrounds + \d_framed_frameoffset\framedparameter\c!frameoffset\relax % also used in backgrounds + \edef\p_framed_frame{\framedparameter\c!frame}% + \edef\p_framed_background{\framedparameter\c!background}% % not here, in calling macro: setups - \removeframedboxdepth -% \edef\framedforegroundcolor{\framedparameter\c!foregroundcolor}% -% \ifx\framedforegroundcolor\empty\else\docolorframebox\fi - \edef\overlaylinecolor{\framedparameter\c!framecolor}% - \edef\overlaylinewidth{\the\ruledlinewidth}% - \edef\@@localframing {\framedparameter\c!frame}% - \ifx\@@localframing\v!overlay \else \ifx\@@localframing\v!none \else - \edef\framedrulethickness{\framedparameter\c!rulethickness}% - \ifx\framedrulethickness\empty\else - \ruledlinewidth\framedrulethickness\relax - \ifinheritruledlinewidth\linewidth\ruledlinewidth\fi + \pack_framed_remove_depth + \ifx\p_framed_frame\v!overlay \else \ifx\p_framed_frame\v!none \else + \ifx\p_framed_rulethickness\empty\else + \d_framed_linewidth\p_framed_rulethickness\relax \fi - \dooutlinebox % real or invisible frame + \pack_framed_add_outline % real or invisible frame \fi \fi - \edef\framedbackground{\framedparameter\c!background}% - \ifx\framedbackground\empty\else\dobackedbox\fi - \restoreframedboxdepth - \box\framebox + \fi + \ifx\p_framed_background\empty \else + \edef\p_framed_backgroundoffset{\framedparameter\c!backgroundoffset}% + \d_framed_backgroundoffset + \ifx\p_framed_backgroundoffset\v!frame + \d_framed_frameoffset + \else + \p_framed_backgroundoffset + \fi + \edef\p_framed_component{\framedparameter\c!component}% + \pack_framed_add_background + \fi + \pack_framed_restore_depth + \box\b_framed_normal \egroup} -%D Here is another fast one: - -\def\localbackgroundframed#1#2#3#4% tag box wd ht - {\setbox#2\vbox\bgroup - \inframedtrue - \edef\@@framed{\??ma#1}% - \expandafter\def\csname\??ma#1\c!component\endcsname{#1}% - \expandafter\def\csname\??ma#1\c!width \endcsname{#3}% - \expandafter\def\csname\??ma#1\c!height \endcsname{#4}% - \!!framedframeoffset\framedparameter\c!frameoffset - \edef\@@framedbackgroundoffset{\framedparameter\c!backgroundoffset}% - \ifx\@@framedbackgroundoffset\v!frame - \!!framedbackgroundoffset\!!framedframeoffset - \else - \!!framedbackgroundoffset\@@framedbackgroundoffset +%D The next macro uses a box and takes its natural width and +%D height so these can better be correct. + +\def\localbackgroundframed#1#2#3% namespace component box + {\bgroup + \pack_framed_initialize{#1}% + \setbox\b_framed_normal\box#3% + \edef\p_framed_region{\framedparameter\c!region}% + \ifx\p_framed_region\v!yes % maybe later named + \pack_framed_add_region \fi - \setbox\framebox\box#2% - \dp\framebox\zeropoint -% \removeframedboxdepth -% \edef\framedforegroundcolor{\framedparameter\c!foregroundcolor}% -% \ifx\framedforegroundcolor\empty\else\docolorframebox\fi - \edef\overlaylinecolor{\framedparameter\c!framecolor}% - \edef\overlaylinewidth{\the\ruledlinewidth}% - \edef\@@localframing {\framedparameter\c!frame}% - \ifx\@@localframing\v!overlay \else \ifx\@@localframing\v!none \else - \edef\framedrulethickness{\framedparameter\c!rulethickness}% - \ifx\framedrulethickness\empty\else - \ruledlinewidth\framedrulethickness\relax - \ifinheritruledlinewidth\linewidth\ruledlinewidth\fi + \edef\p_framed_rulethickness{\framedparameter\c!rulethickness}% also used in backgrounds + \d_framed_frameoffset\framedparameter\c!frameoffset\relax % also used in backgrounds + \edef\p_framed_frame{\framedparameter\c!frame}% + \edef\p_framed_background{\framedparameter\c!background}% + \ifx\p_framed_frame\v!overlay \else \ifx\p_framed_frame\v!none \else + \ifx\p_framed_rulethickness\empty \else + \d_framed_linewidth\p_framed_rulethickness\relax \fi - \dooutlinebox % real or invisible frame + \pack_framed_add_outline % real or invisible frame \fi \fi - \edef\framedbackground{\framedparameter\c!background}% - \ifx\framedbackground\empty\else\dobackedbox\fi -% \restoreframedboxdepth - \box\framebox + \ifx\p_framed_background\empty \else + \edef\p_framed_backgroundoffset{\framedparameter\c!backgroundoffset}% + \d_framed_backgroundoffset + \ifx\p_framed_backgroundoffset\v!frame + \d_framed_frameoffset + \else + \p_framed_backgroundoffset + \fi + \edef\p_framed_component{#2}% + \pack_framed_add_background + \fi + \box\b_framed_normal \egroup} -%D Before we go into details, we present (and implement) the -%D main framing routine. I saw no real reason for splitting the -%D next two macros into smaller pieces. The content will be -%D collected in a horizontal or vertical box with fixed or free -%D dimensions and specific settings concerning aligment and -%D offsets. -%D -%D In the first few lines, we pre||expand the frame and -%D background offsets. We do so, because the can be defined in -%D terms of the main offset. However, see for instance page -%D backgrounds, when \type {#2} sets the offset to \type -%D {overlay}, both offsets become invalid. -%D -%D Because it is used so often the he next macro is (and -%D looks) rather optimized. - -% \def\s!root{root} % maybe configurable - \let\postprocessframebox\relax -\let\@@framed\s!unknown - -% \def\framedparameter #1{\csname\doframedparameter\@@framed#1\endcsname} -% \def\framedparameterhash#1{\doframedparameterhash \@@framed#1} -% -% \def\doframedparameter #1#2{\ifcsname#1#2\endcsname#1#2\else\expandafter\doframedparentparameter \csname#1\s!parent\endcsname#2\fi} -% \def\doframedparameterhash#1#2{\ifcsname#1#2\endcsname #1\else\expandafter\doframedparentparameterhash\csname#1\s!parent\endcsname#2\fi} -% -% \def\doframedparentparameter #1#2{\ifx#1\relax\s!empty\else\doframedparameter #1#2\fi} -% \def\doframedparentparameterhash#1#2{\ifx#1\relax \else\doframedparameterhash#1#2\fi} -% -% \def\doframedparentparameter#1#2{\ifx#1\relax\doframedrootparameter#2\else\doframedparameter#1#2\fi} -% \def\doframedrootparameter #1{\ifcsname\??oi#1\endcsname\??oi#1\else\s!empty\fi} - -\def\framedparameter #1{\csname\doframedparameter\@@framed{#1}\endcsname} -\def\framedparameterhash#1{\doframedparameterhash \@@framed#1} - -\def\doframedparameter #1#2{\ifcsname#1#2\endcsname#1#2\else\expandafter\doframedparentparameter \csname#1\s!parent\endcsname{#2}\fi} -\def\doframedparameterhash#1#2{\ifcsname#1#2\endcsname #1\else\expandafter\doframedparentparameterhash\csname#1\s!parent\endcsname#2\fi} - -\def\doframedparentparameter #1#2{\ifx#1\relax\s!empty\else\doframedparameter #1{#2}\fi} -\def\doframedparentparameterhash#1#2{\ifx#1\relax \else\doframedparameterhash#1#2\fi} - -\def\doframedparentparameter#1#2{\ifx#1\relax\doframedrootparameter#2\else\doframedparameter#1{#2}\fi} -\def\doframedrootparameter #1{\ifcsname\??oi#1\endcsname\??oi#1\else\s!empty\fi} - -\def\frameddimension#1{\the\dimexpr\framedparameter{#1}\relax} - -\def\dosetframedattributes#1#2% style color - {\edef\fontattributehash {\framedparameterhash#1}% - \edef\colorattributehash{\framedparameterhash#2}% - \ifx\fontattributehash \empty\else\dosetfontattribute \fontattributehash #1\fi - \ifx\colorattributehash\empty\else\dosetcolorattribute\colorattributehash#2\fi} - -% defaults, kind of isolated now - -\getparameters - [\??oi] - [\c!width=\v!fit, - \c!height=\v!broad, - %\c!lines=, - \c!offset=0.25ex, % \defaultframeoffset - \c!empty=\v!no, - \c!frame=\v!on, - %\c!topframe=, - %\c!bottomframe=, - %\c!leftframe=, - %\c!rightframe=, - \c!radius=.5\bodyfontsize, - \c!rulethickness=\linewidth, - \c!corner=\v!rectangular, - \c!depth=\zeropoint, - %\c!foregroundcolor=, - %\c!foregroundstyle=, - %\c!background=, - %\c!backgroundscreen=, - %\c!backgroundcolor=, - \c!backgroundoffset=\zeropoint, - %\c!framecolor=, - \c!frameoffset=\zeropoint, - \c!backgroundcorner=\framedparameter\c!corner, - \c!backgroundradius=\framedparameter\c!radius, - \c!backgrounddepth=\framedparameter\c!depth, - \c!framecorner=\framedparameter\c!corner, - \c!frameradius=\framedparameter\c!radius, - \c!framedepth=\framedparameter\c!depth, - %\c!component=, - %\c!align=, - \c!bottom=\vss, - %\c!top=, - \c!strut=\v!yes, - \c!autostrut=\v!yes, - \c!location=\v!normal, - %\c!orientation=, - \c!autowidth=\v!yes, - %\c!setups= -] - -\getparameters - [\??od] % for fast version - [\c!frame=\v!off, - \c!depth=\zeropoint, - \c!offset=\v!overlay, - %\c!component=, - \c!radius=.5\bodyfontsize, - \c!rulethickness=\linewidth, - \c!corner=\v!rectangular, - \c!backgroundoffset=\zeropoint, - \c!frameoffset=\zeropoint, - \c!backgroundcorner=\framedparameter\c!corner, - \c!backgroundradius=\framedparameter\c!radius, - \c!backgrounddepth=\framedparameter\c!depth, - \c!framecorner=\framedparameter\c!corner, - \c!frameradius=\framedparameter\c!radius, - \c!framedepth=\framedparameter\c!depth, - \c!location=\v!normal] - -% so far - -\newdimen\!!framedwidth -\newdimen\!!framedheight -\newdimen\!!framedscratch % so that users can use \scratchdimen -\newdimen\!!framedframeoffset -\newdimen\!!framedbackgroundoffset +%D A nice example by Aditya: +%D +%D \starttyping +%D \setupframed +%D [loffset=\framedparameter{hoffset}, +%D roffset=\framedparameter{hoffset}, +%D hoffset=\zeropoint] +%D +%D \defineframed[test][hoffset=1cm] +%D \stoptyping -\let\setextraframedoffsets \relax -\let\applyextraframedoffsets\relax +\newdimen\d_framed_width +\newdimen\d_framed_height +\newdimen\d_framed_frameoffset +\newdimen\d_framed_backgroundoffset +\newdimen\d_framed_local_offset % todo: protect local \framednames \unexpanded\def\localframed {\bgroup - \dodoubleempty\dolocalframed} + \dodoubleempty\pack_framed_process} -\unexpanded\def\dolocalframed[#1][#2]% assumes a \dodoubleempty (slows down), also should have leading \bgroup +\unexpanded\def\pack_framed_process[#1][#2]% assumes a \dodoubleempty (slows down), also should have leading \bgroup {\bgroup - \inframedtrue - \edef\@@framed{#1}% + \pack_framed_initialize{#1}% \ifsecondargument % faster - \getparameters[\@@framed][#2]% here ! + \getparameters[\currentframed][#2]% here ! \fi - \dodolocalframed} + \pack_framed_process_indeed} \unexpanded\def\directlocalframed[#1]% no optional {\bgroup \bgroup - \inframedtrue - \edef\@@framed{#1}% - \dodolocalframed} + \pack_framed_initialize{#1}% + \pack_framed_process_indeed} \unexpanded\def\localframedwithsettings[#1][#2]% no checking (so no spaces between) {\bgroup \bgroup - \inframedtrue - \edef\@@framed{#1}% - \getparameters[\@@framed][#2]% here ! - \dodolocalframed} + \pack_framed_initialize{#1}% + \getparameters[\currentframed][#2]% here ! + \pack_framed_process_indeed} + +% done \def\c!fr!analyze{fr:analyze} % private option % we can make macros for the offset, width, and height branches or do an \csname -\unexpanded\def\dodolocalframed - {\!!framedframeoffset\framedparameter\c!frameoffset - \edef\@@framedbackgroundoffset{\framedparameter\c!backgroundoffset}% - \ifx\@@framedbackgroundoffset\v!frame - \!!framedbackgroundoffset\!!framedframeoffset - \else - \!!framedbackgroundoffset\@@framedbackgroundoffset - \fi +\unexpanded\def\pack_framed_process_indeed + {\d_framed_frameoffset\framedparameter\c!frameoffset + \edef\p_framed_backgroundoffset{\framedparameter\c!backgroundoffset}% + \d_framed_backgroundoffset + \ifx\p_framed_backgroundoffset\v!frame + \d_framed_frameoffset + \else + \p_framed_backgroundoffset + \fi % new, experimental dirty hook \framedparameter\c!extras % to get the right spacing - \edef\fontattributehash{\framedparameterhash\c!foregroundstyle}% - \ifx\fontattributehash\empty\else\dosetfontattribute\fontattributehash\c!foregroundstyle\fi + \edef\p_framed_foregroundstyle{\framedparameter\c!foregroundstyle}% + \ifx\p_framed_foregroundstyle\empty\else\dousestyleparameter\p_framed_foregroundstyle\fi % beware, both the frame and background offset can be overruled % - \edef\doframedsetups{\framedparameter\c!setups}% - \ifx\doframedsetups\empty\else - \edef\doframedsetups{\noexpand\setups[\doframedsetups]}% - \fi + \edef\p_framed_setups{\framedparameter\c!setups}% % the next macros are visible \edef\localoffset{\framedparameter\c!offset}% \edef\localwidth {\framedparameter\c!width}% @@ -953,130 +1007,132 @@ \edef\localformat{\framedparameter\c!align}% \edef\localstrut {\framedparameter\c!strut}% % these are not - \edef\@@localautostrut {\framedparameter\c!autostrut}% - \edef\@@localframing {\framedparameter\c!frame}% - \edef\@@locallocation {\framedparameter\c!location}% - \edef\@@localorientation{\framedparameter\c!orientation}% + \edef\p_framed_autostrut {\framedparameter\c!autostrut}% + \edef\p_framed_frame {\framedparameter\c!frame}% + \edef\p_framed_location {\framedparameter\c!location}% + \edef\p_framed_orientation{\framedparameter\c!orientation}% % - \edef\@@localautowidth {\framedparameter\c!autowidth}% - \edef\@@localfranalyze {\framedparameter\c!fr!analyze}% experimental option + \edef\p_framed_autowidth {\framedparameter\c!autowidth}% + \edef\p_framed_franalyze {\framedparameter\c!fr!analyze}% experimental option % - \ifx\@@localframing\v!overlay % no frame, no offset, no framewidth - \boxhasframefalse + \ifx\p_framed_frame\v!overlay % no frame, no offset, no framewidth + \setfalse\c_framed_has_frame \let\localoffset\v!overlay - \else\ifx\@@localframing\v!none % no frame, no framewidth - \boxhasframefalse + \else\ifx\p_framed_frame\v!none % no frame, no framewidth + \setfalse\c_framed_has_frame \else - \boxhasframetrue + \settrue\c_framed_has_frame \fi\fi - \ifboxhasframe - \edef\framedrulethickness{\framedparameter\c!rulethickness}% - \ifx\framedrulethickness\empty\else - \ruledlinewidth\framedrulethickness\relax - \ifinheritruledlinewidth\linewidth\ruledlinewidth\fi + \ifconditional\c_framed_has_frame + \edef\p_framed_rulethickness{\framedparameter\c!rulethickness}% + \ifx\p_framed_rulethickness\empty\else + \d_framed_linewidth\p_framed_rulethickness\relax \fi \else - \ruledlinewidth\zeropoint + \d_framed_linewidth\zeropoint \fi \ifx\localformat\empty - \boxhasformatfalse + \setfalse\c_framed_has_format \else - \boxhasformattrue - \dosetraggedcommand\localformat - \edef\dobeforeframedbox{\raggedtopcommand\framedparameter\c!top}% - \edef\doafterframedbox {\framedparameter\c!bottom\raggedbottomcommand}% + \settrue\c_framed_has_format + \dosetraggedcommand\localformat % not that fast \fi \ifx\localoffset\v!none - \boxhasoffsetfalse - \boxhasstrutfalse - \boxisoverlaidfalse - \@@localoffset\ruledlinewidth + \setfalse\c_framed_has_offset + \setfalse\c_framed_has_strut + \setfalse\c_framed_is_overlaid + \d_framed_local_offset\d_framed_linewidth \else\ifx\localoffset\v!overlay - % \ifx\@@localframing\v!no \boxhasframefalse \fi % test first - \boxhasoffsetfalse - \boxhasstrutfalse - \boxisoverlaidtrue - \@@localoffset\zeropoint + % \ifx\p_framed_frame\v!no \setfalse\c_framed_has_frame \fi % test first + \setfalse\c_framed_has_offset + \setfalse\c_framed_has_strut + \settrue \c_framed_is_overlaid + \d_framed_local_offset\zeropoint +% \else\ifx\localoffset\v!strut +% \setfalse\c_framed_has_offset +% \settrue \c_framed_has_strut +% \settrue \c_framed_is_overlaid +% \d_framed_local_offset\zeropoint \else - \boxhasoffsettrue - \boxhasstruttrue - \boxisoverlaidfalse + \settrue \c_framed_has_offset + \settrue \c_framed_has_strut + \setfalse\c_framed_is_overlaid \ifx\localoffset\v!default % new per 2-6-2000 \let\localoffset\defaultframeoffset - \expandafter\let\csname\@@framed\c!offset\endcsname\defaultframeoffset + \letframedparameter\c!offset\defaultframeoffset % brrr \else \let\defaultframeoffset\localoffset \fi - \@@localoffset\dimexpr\localoffset+\ruledlinewidth\relax - \fi\fi - \!!framedheight\zeropoint - \!!framedwidth \zeropoint + \d_framed_local_offset\dimexpr\localoffset+\d_framed_linewidth\relax + \fi\fi % \fi + \d_framed_height\zeropoint + \d_framed_width \zeropoint \ifx\localwidth\empty % fallback to fit - \ifboxhasformat - \boxhaswidthtrue - \!!framedwidth\hsize + \ifconditional\c_framed_has_format + \settrue\c_framed_has_width + \d_framed_width\hsize \else - \boxhaswidthfalse + \setfalse\c_framed_has_width \fi \else\ifx\localwidth\v!fit - \ifboxhasformat - \boxhaswidthtrue - \!!framedwidth\hsize + \ifconditional\c_framed_has_format + \settrue\c_framed_has_width + \d_framed_width\hsize \else - \boxhaswidthfalse + \setfalse\c_framed_has_width \fi \else\ifx\localwidth\v!fixed % equals \v!fit but no shapebox - \ifboxhasformat - \boxhaswidthtrue - \!!framedwidth\hsize + \ifconditional\c_framed_has_format + \settrue\c_framed_has_width + \d_framed_width\hsize \else - \boxhaswidthfalse + \setfalse\c_framed_has_width \fi \else\ifx\localwidth\v!broad - \boxhaswidthtrue - \!!framedwidth\hsize + \settrue\c_framed_has_width + \d_framed_width\hsize \else\ifx\localwidth\v!local - \boxhaswidthtrue + \settrue\c_framed_has_width \setlocalhsize - \!!framedwidth\localhsize + \d_framed_width\localhsize \else - \boxhaswidthtrue - \!!framedwidth\localwidth + \settrue\c_framed_has_width + \d_framed_width\localwidth \fi\fi\fi\fi\fi \ifx\localheight\empty % fallback to fit - \boxhasheightfalse + \setfalse\c_framed_has_height \else\ifx\localheight\v!fit - \boxhasheightfalse % no longer: \boxhasstrutfalse + \setfalse\c_framed_has_height \else\ifx\localheight\v!broad - \boxhasheightfalse + \setfalse\c_framed_has_height \else - \boxhasheighttrue - \!!framedheight\localheight + \settrue\c_framed_has_height + \d_framed_height\localheight \fi\fi\fi - \ifboxhasheight + \ifconditional\c_framed_has_height % obey user set height, also downward compatible \else - \edef\@@framedlines{\framedparameter\c!lines}% - \ifx\@@framedlines\empty\else - \ifcase\@@framedlines\else - \!!framedheight\@@framedlines\lineheight - \edef\localheight{\the\!!framedheight}% - \boxhasheighttrue + \edef\p_framed_lines{\framedparameter\c!lines}% + \ifx\p_framed_lines\empty\else + \ifcase\p_framed_lines\else + \d_framed_height\p_framed_lines\lineheight + \edef\localheight{\the\d_framed_height}% + \settrue\c_framed_has_height \fi \fi \fi % this is now an option: width=local % - % \ifdim\!!framedwidth=\hsize + % \ifdim\d_framed_width=\hsize % \parindent\zeropoint % \setlocalhsize - % \!!framedwidth\localhsize + % \d_framed_width\localhsize % \fi % i.e. disable (colsetbackgroundproblemintechniek) - \advance\!!framedwidth -2\@@localoffset - \advance\!!framedheight -2\@@localoffset + \advance\d_framed_width -2\d_framed_local_offset + \advance\d_framed_height -2\d_framed_local_offset \ifx\localstrut\v!no - \boxhasstrutfalse + \setfalse\c_framed_has_strut \else\ifx\localstrut\v!global \setstrut \else\ifx\localstrut\v!local @@ -1084,7 +1140,7 @@ \else \setstrut \fi\fi\fi - \ifboxhasstrut + \ifconditional\c_framed_has_strut \let\localbegstrut\begstrut \let\localendstrut\endstrut \let\localstrut \strut @@ -1092,12 +1148,12 @@ \let\localbegstrut\pseudobegstrut % was: \relax \let\localendstrut\pseudoendstrut % was: \relax \let\localstrut \pseudostrut % was: \relax - %\ifboxhasheight\ifdim\!!framedheight<\strutht % saveguard + %\ifconditional\c_framed_has_height\ifdim\d_framed_height<\strutht % saveguard % \let\localbegstrut\relax % but not that % \let\localstrut \relax % save after all %\fi\fi \fi - \ifx\@@localautostrut\v!yes + \ifx\p_framed_autostrut\v!yes \let\delayedbegstrut\relax \let\delayedendstrut\relax \let\delayedstrut \relax @@ -1109,64 +1165,66 @@ \let\localendstrut \relax \let\localstrut \relax \fi - \ifboxhasheight - \let\\\vboxednewline - \ifboxhaswidth - \let\hairline\vboxedhairline - \ifboxhasformat - \let\next\doformatboxSomeFormat + \ifconditional\c_framed_has_height + \let\\\pack_framed_vboxed_newline + \ifconditional\c_framed_has_width + \let\hairline\pack_framed_vboxed_hairline + \ifconditional\c_framed_has_format + \let\next\pack_framed_format_format_yes \else - \let\next\doformatboxNoFormat + \let\next\pack_framed_format_format_nop \fi \else - \let\hairline\hboxedhairline - \ifboxhasformat - \let\next\doformatboxHeight + \let\hairline\pack_framed_hboxed_hairline + \ifconditional\c_framed_has_format + \let\next\pack_framed_format_format_height \else - \let\next\doformatboxVSize + \let\next\pack_framed_format_format_vsize \fi \fi \else - \ifboxhaswidth - \ifboxhasformat - \let\hairline\vboxedhairline - \let\\\vboxednewline - \let\next\doformatboxWidth + \ifconditional\c_framed_has_width + \ifconditional\c_framed_has_format + \let\hairline\pack_framed_vboxed_hairline + \let\\\pack_framed_vboxed_newline + \let\next\pack_framed_format_format_width \else - \let\hairline\hboxedhairline - \let\\\hboxednewline - \let\next\doformatboxHSize + \let\hairline\pack_framed_hboxed_hairline + \let\\\pack_framed_hboxed_newline + \let\next\pack_framed_format_format_hsize \fi \else - \let\hairline\hboxedhairline - \let\\\hboxednewline - \let\next\doformatboxNoSize + \let\hairline\pack_framed_hboxed_hairline + \let\\\pack_framed_hboxed_newline + \let\next\pack_framed_format_format_no_size \fi \fi - \setextraframedoffsets - \edef\framedbackground{\framedparameter\c!background}% - \ifx\framedbackground\empty - \let\framedforgetall\forgetall + \pack_framed_check_extra_offsets + \edef\p_framed_background{\framedparameter\c!background}% + \ifx\p_framed_background\empty + \let\pack_framed_forgetall\forgetall \else - \let\framedforgetall\relax + \let\pack_framed_forgetall\relax \forgetall \fi - \edef\framedwidth {\ifdim\!!framedwidth >\zeropoint\the\!!framedwidth \else\!!zeropoint\fi}% a new feature, visible for user - \edef\framedheight{\ifdim\!!framedheight>\zeropoint\the\!!framedheight\else\!!zeropoint\fi}% a new feature, visible for user - \edef\framedoffset{\the\dimexpr\ifboxhasoffset\localoffset\else\zeropoint\fi}% - \@@startframedorientation - \afterassignment\dodowithframebox - \setbox\framebox\next} + \edef\framedwidth {\ifdim\d_framed_width >\zeropoint\the\d_framed_width \else\!!zeropoint\fi}% a new feature, visible for user + \edef\framedheight{\ifdim\d_framed_height>\zeropoint\the\d_framed_height\else\!!zeropoint\fi}% a new feature, visible for user + \edef\framedoffset{\the\dimexpr\ifconditional\c_framed_has_offset\localoffset\else\zeropoint\fi}% + \ifx\p_framed_orientation\empty + \let\pack_framed_stop_orientation\relax + \else + \pack_framed_start_orientation + \fi + \afterassignment\pack_framed_restart + \setbox\b_framed_normal\next} -\def\dowithframebox - {% moved : \let\postprocessframebox\relax - \finishlocalframed} +\let\pack_framed_stop_orientation\relax -\def\dodowithframebox - {\aftergroup\dowithframebox} +\def\pack_framed_restart + {\aftergroup\pack_framed_finish} -\let\doafterframedbox \relax -\let\dobeforeframedbox\relax +\def\pack_framed_do_top {\raggedtopcommand\framedparameter\c!top} +\def\pack_framed_do_bottom{\framedparameter\c!bottom\raggedbottomcommand} %D Carefull analysis of this macro will learn us that not all %D branches in the last conditionals can be encountered, that @@ -1175,7 +1233,7 @@ %D future extensions. %D \macros -%D {\doassigncheckedframeoffset} +%D {doassigncheckedframeoffset} %D %D Offset helper (see menus): @@ -1217,122 +1275,150 @@ %D ...,bottom=\kern0pt,... %D \stoptyping -% experiment ... \@@localfranalyze -> we could support 'first' as location key +% experiment ... \p_framed_franalyze -> we could support 'first' as location key % option but then we will always do an analysis and reimplement the location % options (btw, beware of location settings of derived functionality that bleed % into this -\def\finishlocalframeda +\def\pack_framed_finish_a {\ifreshapeframebox - \doreshapeframedbox - \else\ifx\@@localfranalyze\v!yes - \doanalyzeframedbox + \pack_framed_reshape_process + \else\ifx\p_framed_franalyze\v!yes + \pack_framed_reshape_analyze \else - \resetshapeframebox + \pack_framed_reshape_reset \fi\fi - \boxhaswidthfalse} + \setfalse\c_framed_has_width} -\def\finishlocalframedb - {\ifx\@@localfranalyze\v!yes - \doanalyzeframedbox +\def\pack_framed_finish_b + {\ifx\p_framed_franalyze\v!yes + \pack_framed_reshape_analyze \else - \resetshapeframebox + \pack_framed_reshape_reset \fi - \boxhaswidthfalse} + \setfalse\c_framed_has_width} -\def\finishlocalframedc - {\ifx\@@localfranalyze\v!yes - \doanalyzeframedbox +\def\pack_framed_finish_c + {\ifx\p_framed_franalyze\v!yes + \pack_framed_reshape_analyze \else - \resetshapeframebox + \pack_framed_reshape_reset \fi} -\unexpanded\def\finishlocalframed - {\dontshowcomposition - \@@stopframedorientation % hm, wrong place ! should rotate the result (after reshape) - \handleframedlocator\c!before\@@locallocation - \ifboxhasformat - \ifx\@@localautowidth\v!force - \finishlocalframeda +\unexpanded\def\pack_framed_finish + {\pack_framed_stop_orientation % hm, wrong place ! should rotate the result (after reshape) + \pack_framed_locator_before\p_framed_location + \ifconditional\c_framed_has_format + \ifx\p_framed_autowidth\v!force + \pack_framed_finish_a \else\ifx\localwidth\v!fit - \ifx\@@localautowidth\v!yes - \finishlocalframeda + \ifx\p_framed_autowidth\v!yes + \pack_framed_finish_a \else - \finishlocalframedb + \pack_framed_finish_b \fi \else\ifx\localwidth\v!fixed - \finishlocalframedb + \pack_framed_finish_b \else - \finishlocalframedc + \pack_framed_finish_c \fi\fi\fi \ifconditional\boxcontentneedsprocessing - \mkdoprocessboxcontents\framebox + \mkdoprocessboxcontents\b_framed_normal \fi \else - \finishlocalframedc + \pack_framed_finish_c + \fi + \ifconditional\c_framed_has_width + \wd\b_framed_normal\d_framed_width \fi - \ifboxhaswidth - \wd\framebox\!!framedwidth + \ifconditional\c_framed_has_height + \ht\b_framed_normal\d_framed_height \fi - \ifboxhasheight - \ht\framebox\!!framedheight + \edef\p_framed_empty{\framedparameter\c!empty}% + \ifx\p_framed_empty\v!yes + \pack_framed_fake_box \fi - \doif{\framedparameter\c!empty}\v!yes\dosetfakedframebox - \ifboxhasextraoffset - \applyextraframedoffsets + \iftrialtypesetting \else + \edef\p_framed_region{\framedparameter\c!region}% + \ifx\p_framed_region\v!yes % maybe later named + \pack_framed_add_region + \fi \fi - \ifboxhasoffset - \dooffsetframebox + \d_framed_applied_offset + \ifconditional\c_framed_is_overlaid + \zeropoint + \else + \d_framed_linewidth + \fi + \ifconditional\c_framed_has_offset + \advance\d_framed_applied_offset\localoffset \fi - \ifboxisoverlaid \else - \dolocateframebox + \ifconditional\c_framed_has_extra_offset + \pack_framed_apply_extra_offsets % includes \d_framed_applied_offset + \else + \ifzeropt\d_framed_applied_offset + \else + \pack_framed_widen_box + \fi \fi + % \ifx\postprocessframebox\relax \else \let\next\postprocessframebox \let\postprocessframebox\relax % prevent nesting - \next\framebox + \next\b_framed_normal \fi - \edef\overlaylinecolor{\framedparameter\c!framecolor}% - \edef\overlaylinewidth{\the\ruledlinewidth}% \@@... - \ifboxhasframe % real or invisible frame - \dooutlinebox + \iftrialtypesetting + % new + \else + \ifconditional\c_framed_has_frame % real or invisible frame + \pack_framed_add_outline + \fi + \ifx\p_framed_background\empty \else + \edef\p_framed_component{\framedparameter\c!component}% + \pack_framed_add_background + \fi \fi - \ifx\framedbackground\empty\else\dobackedbox\fi - \handleframedlocator\c!after\@@locallocation - \box\framebox + \pack_framed_locator_after\p_framed_location + \box\b_framed_normal + \global\frameddimensionstate % global so to be used directly afterwards ! + \ifconditional\c_framed_has_width + \ifconditional\c_framed_has_height \plusthree \else \plusone \fi + \else + \ifconditional\c_framed_has_height \plustwo \else \zerocount \fi + \fi \egroup \egroup} -\def\dosetfakedframebox - {\setbox\scratchbox\emptyhbox - \wd\scratchbox\wd\framebox - \ht\scratchbox\ht\framebox - \dp\scratchbox\dp\framebox - \setbox\framebox\box\scratchbox} +\installcorenamespace{framedlocatorbefore} +\installcorenamespace{framedlocatorafter} -% test: (saves one forgetall) -% -% \edef\framedbackground{\framedparameter\c!background}% -% \ifx\framedbackground\empty -% \let\framedforgetall\forgetall -% \else -% \let\framedforgetall\relax -% \forgetall -% \fi +\newconstant\frameddimensionstate % global state: 0=unknown 1=width 2=height 3=both + +\def\pack_framed_fake_box + {\setbox\scratchbox\emptyhbox + \wd\scratchbox\wd\b_framed_normal + \ht\scratchbox\ht\b_framed_normal + \dp\scratchbox\dp\b_framed_normal + \setbox\b_framed_normal\box\scratchbox} \def\installframedlocator#1#2#3% - {\setvalue{\??oi:\c!location:\c!before:#1}{#2}% - \setvalue{\??oi:\c!location:\c!after :#1}{#3}} + {\setvalue{\??framedlocatorbefore#1}{#2}% + \setvalue{\??framedlocatorafter #1}{#3}} -\def\handleframedlocator#1#2% - {\csname\??oi:\c!location:#1:#2\endcsname} +\def\pack_framed_locator_before#1{\csname\??framedlocatorbefore#1\endcsname} +\def\pack_framed_locator_after #1{\csname\??framedlocatorafter #1\endcsname} -\def\doprelocframedbox#1% - {\scratchdimen\dimexpr#1+\ruledlinewidth\relax - \ifboxhasoffset - \advance\scratchdimen \framedparameter\c!offset - \fi - \scratchskip\dimexpr\ht\framebox-\scratchdimen\relax} +\newdimen\d_framed_locator_ht +\newdimen\d_framed_locator_dp + +\def\pack_framed_locater_set#1% + {\d_framed_locator_ht\dimexpr + #1+\d_framed_linewidth + \ifconditional\c_framed_has_offset + +\framedparameter\c!offset + \fi + \relax + \d_framed_locator_dp\dimexpr\ht\b_framed_normal-\d_framed_locator_ht\relax} % \ruledhbox % {A @@ -1358,99 +1444,100 @@ \installframedlocator \v!hanging % best with strut=no {} - {\dp\framebox\ht\framebox - \ht\framebox\zeropoint} + {\dp\b_framed_normal\ht\b_framed_normal + \ht\b_framed_normal\zeropoint} \installframedlocator \v!depth {} - {\ht\framebox\dimexpr\ht\framebox-\strutdp\relax - \dp\framebox\strutdp - \box\framebox} + {\ht\b_framed_normal\dimexpr\ht\b_framed_normal-\strutdp\relax + \dp\b_framed_normal\strutdp + \box\b_framed_normal} \installframedlocator \v!height {} - {\dp\framebox\dimexpr\ht\framebox-\strutht\relax - \ht\framebox\strutht - \box\framebox} + {\dp\b_framed_normal\dimexpr\ht\b_framed_normal-\strutht\relax + \ht\b_framed_normal\strutht + \box\b_framed_normal} \installframedlocator \v!high {} - {\doprelocframedbox\strutht - \setbox\framebox\hbox{\lower\scratchskip\box\framebox}% - \ht\framebox\strutht - \dp\framebox\strutdp - \hbox{\box\framebox}} + {\pack_framed_locater_set\strutht + \setbox\b_framed_normal\hbox{\lower\d_framed_locator_dp\box\b_framed_normal}% + \ht\b_framed_normal\strutht + \dp\b_framed_normal\strutdp + \hbox{\box\b_framed_normal}} \installframedlocator \v!line {} - {\setbox\framebox\hbox{\lower.5\ht\framebox\box\framebox}% - \ht\framebox.5\lineheight - \dp\framebox.5\lineheight - \hbox{\box\framebox}} + {\setbox\b_framed_normal\hbox{\lower.5\ht\b_framed_normal\box\b_framed_normal}% + \ht\b_framed_normal.5\lineheight + \dp\b_framed_normal.5\lineheight + \hbox{\box\b_framed_normal}} \installframedlocator \v!low {} - {\doprelocframedbox\strutdp - \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}% - \ht\framebox\strutht - \dp\framebox\strutdp - \box\framebox} + {\pack_framed_locater_set\strutdp + \setbox\b_framed_normal\hbox{\lower\d_framed_locator_ht\box\b_framed_normal}% + \ht\b_framed_normal\strutht + \dp\b_framed_normal\strutdp + \box\b_framed_normal} \installframedlocator \v!top {} - {\doprelocframedbox\strutht - \setbox\framebox\hbox{\lower\scratchskip\box\framebox}% - \ht\framebox\scratchdimen - \dp\framebox\scratchskip - \hbox{\box\framebox}} + {\pack_framed_locater_set\strutht + \setbox\b_framed_normal\hbox{\lower\d_framed_locator_dp\box\b_framed_normal}% + \ht\b_framed_normal\d_framed_locator_ht + \dp\b_framed_normal\d_framed_locator_dp + \hbox{\box\b_framed_normal}} \installframedlocator \v!middle {} - {\scratchdimen.5\ht\framebox - \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}% - \ht\framebox\scratchdimen - \dp\framebox\scratchdimen - \hbox{\box\framebox}} + {\scratchdimen.5\ht\b_framed_normal + \setbox\b_framed_normal\hbox{\lower\scratchdimen\box\b_framed_normal}% + \ht\b_framed_normal\scratchdimen + \dp\b_framed_normal\scratchdimen + \hbox{\box\b_framed_normal}} \installframedlocator \v!lohi - {\handleframedlocator\c!before\v!middle} - {\handleframedlocator\c!after \v!middle} + {\pack_framed_locator_before\v!middle} + {\pack_framed_locator_after \v!middle} \installframedlocator \v!bottom {} - {\doprelocframedbox\strutdp - \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}% - \ht\framebox\scratchskip - \dp\framebox\scratchdimen - \hbox{\box\framebox}} + {\pack_framed_locater_set\strutdp + \setbox\b_framed_normal\hbox{\lower\d_framed_locator_ht\box\b_framed_normal}% + \ht\b_framed_normal\d_framed_locator_dp + \dp\b_framed_normal\d_framed_locator_ht + \hbox{\box\b_framed_normal}} \installframedlocator \v!keep % retains height/depth - {\removeframedboxdepth} - {\restoreframedboxdepth} + {\pack_framed_remove_depth} + {\pack_framed_restore_depth} % also used in fastlocalframed -\newdimen\originalframedwd -\newdimen\originalframedht -\newdimen\originalframeddp - -\def\removeframedboxdepth - {\originalframedwd\wd\framebox - \originalframedht\ht\framebox - \originalframeddp\dp\framebox - \ifzeropt\originalframeddp\else\setbox\framebox\hbox{\raise\originalframeddp\box\framebox}\fi - \wd\framebox\originalframedwd - \ht\framebox\dimexpr\originalframedht+\originalframeddp\relax - \dp\framebox\zeropoint} +\newdimen\d_framed_original_wd +\newdimen\d_framed_original_ht +\newdimen\d_framed_original_dp -\def\restoreframedboxdepth - {\ifzeropt\originalframeddp\else\setbox\framebox\hbox{\lower\originalframeddp\box\framebox}\fi - \wd\framebox\originalframedwd - \ht\framebox\originalframedht - \dp\framebox\originalframeddp} +\def\pack_framed_remove_depth + {\d_framed_original_wd\wd\b_framed_normal + \d_framed_original_ht\ht\b_framed_normal + \d_framed_original_dp\dp\b_framed_normal + \ifzeropt\d_framed_original_dp\else + \setbox\b_framed_normal\hbox{\raise\d_framed_original_dp\box\b_framed_normal}% + \fi + \wd\b_framed_normal\d_framed_original_wd + \ht\b_framed_normal\dimexpr\d_framed_original_ht+\d_framed_original_dp\relax + \dp\b_framed_normal\zeropoint} -% \let\@@startframedorientation\relax -% \let\@@stopframedorientation \relax +\def\pack_framed_restore_depth + {\ifzeropt\d_framed_original_dp \else + \setbox\b_framed_normal\hbox{\lower\d_framed_original_dp\box\b_framed_normal}% + \fi + \wd\b_framed_normal\d_framed_original_wd + \ht\b_framed_normal\d_framed_original_ht + \dp\b_framed_normal\d_framed_original_dp} % \framed[width=12cm,height=3cm,orientation=0]{\input ward\relax} % \framed[width=12cm,height=3cm,orientation=90]{\input ward\relax} @@ -1460,53 +1547,47 @@ % \framed[width=12cm,height=3cm,orientation=-180]{\input ward\relax} % \framed[width=12cm,height=3cm,orientation=-270]{\input ward\relax} -\def\@@startframedorientation - {\let\@@stopframedorientation \relax - \ifx\@@localorientation\empty\else - \ifcase\@@localorientation\else - \scratchcounter\@@localorientation - \divide\scratchcounter\plustwo - \ifodd\scratchcounter - \swapmacros\framedwidth \framedheight - \swapmacros\localwidth \localheight - \swapdimens\!!framedheight\!!framedwidth - \def\@@stopframedorientation{\@@dostopframedorientation\plusone}% - \else - \def\@@stopframedorientation{\@@dostopframedorientation\zerocount}% - \fi +\def\pack_framed_start_orientation + {\ifcase\p_framed_orientation + \let\pack_framed_stop_orientation\relax + \else + \scratchcounter\p_framed_orientation % weird .. why + \divide\scratchcounter\plustwo + \ifodd\scratchcounter + \let\pack_framed_stop_orientation\pack_framed_stop_orientation_odd + \else + \let\pack_framed_stop_orientation\pack_framed_stop_orientation_even \fi \fi} -\def\@@dostopframedorientation#1% - {\ifcase#1\else - \swapmacros\framedwidth \framedheight - \swapmacros\localwidth \localheight - \swapdimens\!!framedheight\!!framedwidth - \fi - \setbox\framebox\hbox{\dorotatebox\@@localorientation\hbox{\box\framebox}}} +\def\pack_framed_stop_orientation_odd + {\swapmacros\framedwidth\framedheight + \swapmacros\localwidth\localheight + \swapdimens\d_framed_height\d_framed_width + \pack_framed_stop_orientation_even} + +\def\pack_framed_stop_orientation_even + {\setbox\b_framed_normal\hbox{\dorotatebox\p_framed_orientation\hbox{\box\b_framed_normal}}} %D The last conditional takes care of the special situation of %D in||line \inframed[height=3cm]{framed} boxes. Such boxes have %D to be \inframed{aligned} with the running text. -\def\doinframed[#1]% we could omit #1] but readibility ... - {\framed[\c!location=\v!low,#1]} - \unexpanded\def\inframed - {\dosingleempty\doinframed} + {\dosingleempty\pack_framed_inline} + +% \def\pack_framed_inline[#1]% +% {\framed[\c!location=\v!low,#1]} +% +% or: + +\def\pack_framed_inline[% + {\framed[\c!location=\v!low,} %D When we set \type{empty} to \type{yes}, we get %D ourselves a frame and/or background, but no content, so %D actually we have a sort of phantom framed box. -%D Because color marks and specials can interfere with -%D spacing, we provide a way to specify a foregroundcolor. - -\def\docolorframebox - {\doifcolor\framedforegroundcolor - {\setbox\framebox\hbox{\faststartcolor[\framedforegroundcolor]\box\framebox\faststopcolor}}} - %{\setbox\framebox\hbox{\doactivatecolor\framedforegroundcolor\box\framebox}}} - %D \macros %D {mframed, minframed} %D @@ -1547,25 +1628,54 @@ %D Still better is the next alternative, if only because it %D takes care of setting the super- and subscripts styles -\newcount\mframedstyle +\newcount\c_framed_mstyle -\def\doinlinemframed[#1]#2% - {\begingroup - \mframedstyle\mathstyle\relax - \inframed[#1]{\Ustartmath\triggermathstyle\mframedstyle#2\Ustopmath}% - \endgroup} +\unexpanded\def\pack_framed_math_strut + {\Ustartmath + \triggermathstyle\c_framed_mstyle + \vphantom{(}% + \Ustopmath} -\def\funnymathstrut{\Ustartmath\triggermathstyle\mframedstyle\vphantom{(}\Ustopmath} +% \unexpanded\def\mframed {\dosingleempty\pack_framed_math_display} +% \unexpanded\def\inmframed{\dosingleempty\pack_framed_math_inline } +% +% \def\pack_framed_math_inline[#1]#2% +% {\begingroup +% \c_framed_mstyle\mathstyle +% \inframed[#1]{\Ustartmath\triggermathstyle\c_framed_mstyle#2\Ustopmath}% +% \endgroup} +% +% \def\pack_framed_math_display[#1]#2% +% {\begingroup +% \c_framed_mstyle\mathstyle +% \let\normalstrut\pack_framed_math_strut +% \framed[#1]{\Ustartmath\triggermathstyle\c_framed_mstyle#2\Ustopmath}% +% \endgroup} + +\installcorenamespace{mathframed} + +\installframedcommandhandler \??mathframed {mathframed} \??mathframed -\def\dodisplaymframed[#1]#2% +\appendtoks + \setuevalue{\currentmathframed}{\pack_framed_mathframed{\currentmathframed}}% +\to \everydefinemathframed + +\unexpanded\def\pack_framed_mathframed#1% {\begingroup - \mframedstyle\mathstyle\relax - \let\normalstrut\funnymathstrut - \framed[#1]{\Ustartmath\triggermathstyle\mframedstyle#2\Ustopmath}% + \edef\currentmathframed{#1}% + \dosingleempty\pack_framed_mathframed_indeed} + +\def\pack_framed_mathframed_indeed[#1]#2% no fancy nesting supported here + {\iffirstargument + \setupcurrentmathframed[#1]% + \fi + \c_framed_mstyle\mathstyle + \doifnot{\mathframedparameter\c!location}\v!low{\let\normalstrut\pack_framed_math_strut}% + \inheritedmathframedframed{\Ustartmath\triggermathstyle\c_framed_mstyle#2\Ustopmath}% \endgroup} -\def\mframed {\dosingleempty\dodisplaymframed} -\def\inmframed{\dosingleempty\doinlinemframed } +\definemathframed[mframed] +\definemathframed[inmframed][\c!location=\v!low] %D So instead of the rather versatile \type {\framed}, we ue %D the \type {\mframed}. @@ -1577,12 +1687,9 @@ %D \stopformula %D \stopbuffer %D -%D \typebuffer -%D -%D \getbuffer +%D \typebuffer \getbuffer %D -%D However, we got into troubles when we want to nest sub- and -%D superscripts, like in +%D And: %D %D \startbuffer %D \startformula @@ -1590,23 +1697,7 @@ %D \stopformula %D \stopbuffer %D -%D \typebuffer -%D -%D \getbuffer -%D -%D Therefore, we can best use \type {\super} and \type {\suber} -%D instead of \type {^} and \type {_}. Both commands take care -%D of proper font switching. -%D -%D \startbuffer -%D \startformula -%D x \times \mframed{y} \times y\super{\mframed{z}\suber{\mframed{z}}} -%D \stopformula -%D \stopbuffer -%D -%D \typebuffer -%D -%D \getbuffer +%D \typebuffer \getbuffer %D %D As usual, one can specify in what way the text should be %D framed. One should be aware of the fact that, inorder to @@ -1616,13 +1707,11 @@ %D %D \startbuffer %D \startformula -%D x \times y\super{\mframed[framecolor=red]{z}\suber{z}} +%D x \times y^{\mframed[framecolor=red]{z}_{z}} %D \stopformula %D \stopbuffer %D -%D \typebuffer -%D -%D \getbuffer +%D \typebuffer \getbuffer %D %D For inline use, we also provide the \type {\inmframed} %D alternative: we want $x \times \inmframed{y}$ in inline @@ -1632,12 +1721,43 @@ %D putting rules around boxes, inserting offsets and aligning %D text. Each step is handled by separate macros. -\def\dowidenframebox#1% - {\setbox\framebox\vbox - {\kern#1\hbox{\kern#1\box\framebox\kern#1}\kern#1}} +\newdimen\d_framed_applied_offset +\newdimen\d_framed_loffset +\newdimen\d_framed_roffset +\newdimen\d_framed_toffset +\newdimen\d_framed_boffset + +\def\pack_framed_check_extra_offsets + {\setfalse\c_framed_has_extra_offset + \d_framed_loffset\framedparameter\c!loffset\relax + \d_framed_roffset\framedparameter\c!roffset\relax + \d_framed_toffset\framedparameter\c!toffset\relax + \d_framed_boffset\framedparameter\c!boffset\relax + \ifzeropt\d_framed_loffset\else \advance\d_framed_width -\d_framed_loffset \settrue\c_framed_has_extra_offset \fi + \ifzeropt\d_framed_roffset\else \advance\d_framed_width -\d_framed_roffset \settrue\c_framed_has_extra_offset \fi + \ifzeropt\d_framed_toffset\else \advance\d_framed_height-\d_framed_toffset \settrue\c_framed_has_extra_offset \fi + \ifzeropt\d_framed_boffset\else \advance\d_framed_height-\d_framed_boffset \settrue\c_framed_has_extra_offset \fi} + +\def\pack_framed_apply_extra_offsets + {\setbox\b_framed_normal\vbox\bgroup + \advance\d_framed_toffset\d_framed_applied_offset + \advance\d_framed_boffset\d_framed_applied_offset + \advance\d_framed_loffset\d_framed_applied_offset + \advance\d_framed_roffset\d_framed_applied_offset + \kern\d_framed_toffset + \hbox\bgroup + \kern\d_framed_loffset + \box\b_framed_normal + \kern\d_framed_roffset + \egroup + \kern\d_framed_boffset + \egroup} -\def\dooffsetframebox{\dowidenframebox\localoffset} -\def\dolocateframebox{\dowidenframebox\ruledlinewidth} +\def\pack_framed_widen_box + {\setbox\b_framed_normal\vbox + {\kern\d_framed_applied_offset + \hbox{\kern\d_framed_applied_offset\box\b_framed_normal\kern\d_framed_applied_offset}% + \kern\d_framed_applied_offset}} %D Let's hope that the next few examples show us enough of %D what needs to be done by the auxiliary macros. @@ -1724,55 +1844,79 @@ \fi} \def\dodoformatonelinerbox - {\dowithnextboxcontent - {\ignorespaces} - {\hbox to \hsize - {\ifcase\raggedstatus\or\hss\or\hss\fi - \unhbox\nextbox \removeunwantedspaces - \ifcase\raggedstatus\or \or\hss\or\hss\fi}% - \egroup} - \hbox} + {\afterassignment\redoformatonelinerbox + \setbox\nextbox\hbox} + +\def\redoformatonelinerbox + {\aftergroup\dododoformatonelinerbox + \ignorespaces} + +\def\dododoformatonelinerbox + {\hbox to \hsize + {\ifcase\raggedstatus\or\hss\or\hss \fi + \unhbox\nextbox \removeunwantedspaces + \ifcase\raggedstatus\or \or\hss\or\hss\fi}% + \egroup} \def\nodoformatonelinerbox % grabs { {\let\next=} %D The handlers: -\def\framedforgetall{\forgetall} +\def\pack_framed_forgetall{\forgetall} + +% test: (saves one forgetall) +% +% \edef\framedbackground{\framedparameter\c!background}% +% \ifx\framedbackground\empty +% \let\pack_framed_forgetall\forgetall +% \else +% \let\pack_framed_forgetall\relax +% \forgetall +% \fi + +\def\pack_framed_set_foregroundcolor + {\edef\p_framed_foregroundcolor{\framedparameter\c!foregroundcolor}% + \ifx\p_framed_foregroundcolor\empty\else\dousecolorparameter\p_framed_foregroundcolor\fi} -\def\setframedforegroundcolor - {\edef\colorattributehash{\framedparameterhash\c!foregroundcolor}% - \ifx\colorattributehash\empty\else\dosetcolorattribute\colorattributehash\c!foregroundcolor\fi} +\def\pack_framed_do_setups + {\ifx\p_framed_setups\empty \else + \setups[\p_framed_setups]% \texsetup + \fi} -\def\doformatboxSomeFormat - {\vbox to \!!framedheight +\def\pack_framed_format_format_yes + {\vbox to \d_framed_height \bgroup \let\postprocessframebox\relax - \framedforgetall - \setframedforegroundcolor + \pack_framed_forgetall + \iftrialtypesetting \else + \pack_framed_set_foregroundcolor + \fi \oninterlineskip - \hsize\!!framedwidth - \vsize\!!framedheight - \doframedsetups + \hsize\d_framed_width + \vsize\d_framed_height + \pack_framed_do_setups \raggedcommand - \dobeforeframedbox + \pack_framed_do_top \bgroup \localbegstrut \aftergroup\localendstrut - \aftergroup\doafterframedbox + \aftergroup\pack_framed_do_bottom \aftergroup\egroup \doformatonelinerbox} -\def\doformatboxNoFormat - {\vbox to \!!framedheight +\def\pack_framed_format_format_nop + {\vbox to \d_framed_height \bgroup \let\postprocessframebox\relax - \framedforgetall - \setframedforegroundcolor + \pack_framed_forgetall + \iftrialtypesetting \else + \pack_framed_set_foregroundcolor + \fi \oninterlineskip - \hsize\!!framedwidth - \vsize\!!framedheight - \doframedsetups + \hsize\d_framed_width + \vsize\d_framed_height + \pack_framed_do_setups \raggedcenter \vss \bgroup @@ -1782,14 +1926,16 @@ \aftergroup\egroup \doformatonelinerbox} -\def\doformatboxHeight - {\vbox to \!!framedheight +\def\pack_framed_format_format_height + {\vbox to \d_framed_height \bgroup \let\postprocessframebox\relax - \framedforgetall - \setframedforegroundcolor + \pack_framed_forgetall + \iftrialtypesetting \else + \pack_framed_set_foregroundcolor + \fi \oninterlineskip - \doframedsetups + \pack_framed_do_setups \raggedcommand \vss \bgroup @@ -1799,32 +1945,36 @@ \localbegstrut \doformatonelinerbox} -\def\doformatboxWidth +\def\pack_framed_format_format_width {\vbox \bgroup \let\postprocessframebox\relax - \framedforgetall - \setframedforegroundcolor + \pack_framed_forgetall + \iftrialtypesetting \else + \pack_framed_set_foregroundcolor + \fi \oninterlineskip - \hsize\!!framedwidth - \doframedsetups + \hsize\d_framed_width + \pack_framed_do_setups \raggedcommand - \dobeforeframedbox + \pack_framed_do_top \bgroup \localbegstrut \aftergroup\localendstrut - \aftergroup\doafterframedbox + \aftergroup\pack_framed_do_bottom \aftergroup\egroup \doformatonelinerbox} -\def\doformatboxVSize - {\vbox to \!!framedheight +\def\pack_framed_format_format_vsize + {\vbox to \d_framed_height \bgroup \let\postprocessframebox\relax - \framedforgetall - \setframedforegroundcolor - \vsize\!!framedheight - \doframedsetups + \pack_framed_forgetall + \iftrialtypesetting \else + \pack_framed_set_foregroundcolor + \fi + \vsize\d_framed_height + \pack_framed_do_setups \vss \bgroup \aftergroup\vss @@ -1835,13 +1985,15 @@ \localstrut \doformatonelinerbox} -\def\doformatboxHSize - {\hbox to \!!framedwidth +\def\pack_framed_format_format_hsize + {\hbox to \d_framed_width \bgroup \let\postprocessframebox\relax - \framedforgetall - \setframedforegroundcolor - \doframedsetups + \pack_framed_forgetall + \iftrialtypesetting \else + \pack_framed_set_foregroundcolor + \fi + \pack_framed_do_setups \hss \localstrut \bgroup @@ -1849,17 +2001,17 @@ \aftergroup\egroup \doformatonelinerbox} -\def\doformatboxNoSize +\def\pack_framed_format_format_no_size {\hbox \bgroup - \setframedforegroundcolor + \iftrialtypesetting \else + \pack_framed_set_foregroundcolor + \fi \let\postprocessframebox\relax - \doframedsetups + \pack_framed_do_setups \localstrut \doformatonelinerbox} -\let\doframedsetups\relax - %D On the next page we show some examples of how these macros %D come into action. The examples show us how %D \type {fit}, \type {broad} dimensions influence the @@ -1870,44 +2022,49 @@ %D \bgroup %D \showstruts %D \dontcomplain -%D \startlinecorrection -%D \halign{#\enskip&#\enskip&#\enskip&#\enskip&#\enskip&#\cr -%D \framed[width=.2\hsize, height=.2\hsize, align=] {a\par b\par c}& -%D \framed[width=.2\hsize, height=broad, align=] {a\par b\par c}& -%D \framed[width=.2\hsize, height=fit, align=] {a\par b\par c}& -%D \framed[width=fit, height=.2\hsize, align=] {a\par b\par c}& -%D \framed[width=fit, height=broad, align=] {a\par b\par c}& -%D \framed[width=fit, height=fit, align=] {a\par b\par c}\cr -%D \noalign{\vskip1em} -%D \framed[width=.2\hsize, height=.2\hsize, align=yes] {a\par b\par c}& -%D \framed[width=.2\hsize, height=broad, align=yes] {a\par b\par c}& -%D \framed[width=.2\hsize, height=fit, align=yes] {a\par b\par c}& -%D \framed[width=fit, height=.2\hsize, align=yes] {a\par b\par c}& -%D \framed[width=fit, height=broad, align=yes] {a\par b\par c}& -%D \framed[width=fit, height=fit, align=yes] {a\par b\par c}\cr -%D \noalign{\vskip1em} -%D \framed[width=.2\hsize, height=.2\hsize, align=right] {a\par b\par c}& -%D \framed[width=.2\hsize, height=broad, align=right] {a\par b\par c}& -%D \framed[width=.2\hsize, height=fit, align=right] {a\par b\par c}& -%D \framed[width=fit, height=.2\hsize, align=right] {a\par b\par c}& -%D \framed[width=fit, height=broad, align=right] {a\par b\par c}& -%D \framed[width=fit, height=fit, align=right] {a\par b\par c}\cr -%D \noalign{\vskip1em} -%D \framed[width=.2\hsize, height=.2\hsize, align=left] {a\par b\par c}& -%D \framed[width=.2\hsize, height=broad, align=left] {a\par b\par c}& -%D \framed[width=.2\hsize, height=fit, align=left] {a\par b\par c}& -%D \framed[width=fit, height=.2\hsize, align=left] {a\par b\par c}& -%D \framed[width=fit, height=broad, align=left] {a\par b\par c}& -%D \framed[width=fit, height=fit, align=left] {a\par b\par c}\cr -%D \noalign{\vskip1em} -%D \framed[width=.2\hsize, height=.2\hsize, align=middle] {a\par b\par c}& -%D \framed[width=.2\hsize, height=broad, align=middle] {a\par b\par c}& -%D \framed[width=.2\hsize, height=fit, align=middle] {a\par b\par c}& -%D \framed[width=fit, height=.2\hsize, align=middle] {a\par b\par c}& -%D \framed[width=fit, height=broad, align=middle] {a\par b\par c}& -%D \framed[width=fit, height=fit, align=middle] {a\par b\par c}\cr} -%D \stoplinecorrection -%D \blank[2*big] +%D \starttabulate[|c|c|c|c|c|c|] +%D % \HL +%D \NC \framed[width=.2\hsize, height=.2\hsize, align=] {a\endgraf b\endgraf c} +%D \NC \framed[width=.2\hsize, height=broad, align=] {a\endgraf b\endgraf c} +%D \NC \framed[width=.2\hsize, height=fit, align=] {a\endgraf b\endgraf c} +%D \NC \framed[width=fit, height=.2\hsize, align=] {a\endgraf b\endgraf c} +%D \NC \framed[width=fit, height=broad, align=] {a\endgraf b\endgraf c} +%D \NC \framed[width=fit, height=fit, align=] {a\endgraf b\endgraf c} +%D \NC \NR +%D % \HL +%D \NC \framed[width=.2\hsize, height=.2\hsize, align=yes] {a\endgraf b\endgraf c} +%D \NC \framed[width=.2\hsize, height=broad, align=yes] {a\endgraf b\endgraf c} +%D \NC \framed[width=.2\hsize, height=fit, align=yes] {a\endgraf b\endgraf c} +%D \NC \framed[width=fit, height=.2\hsize, align=yes] {a\endgraf b\endgraf c} +%D \NC \framed[width=fit, height=broad, align=yes] {a\endgraf b\endgraf c} +%D \NC \framed[width=fit, height=fit, align=yes] {a\endgraf b\endgraf c} +%D \NC \NR +%D % \HL +%D \NC \framed[width=.2\hsize, height=.2\hsize, align=right] {a\endgraf b\endgraf c} +%D \NC \framed[width=.2\hsize, height=broad, align=right] {a\endgraf b\endgraf c} +%D \NC \framed[width=.2\hsize, height=fit, align=right] {a\endgraf b\endgraf c} +%D \NC \framed[width=fit, height=.2\hsize, align=right] {a\endgraf b\endgraf c} +%D \NC \framed[width=fit, height=broad, align=right] {a\endgraf b\endgraf c} +%D \NC \framed[width=fit, height=fit, align=right] {a\endgraf b\endgraf c} +%D \NC \NR +%D % \HL +%D \NC \framed[width=.2\hsize, height=.2\hsize, align=left] {a\endgraf b\endgraf c} +%D \NC \framed[width=.2\hsize, height=broad, align=left] {a\endgraf b\endgraf c} +%D \NC \framed[width=.2\hsize, height=fit, align=left] {a\endgraf b\endgraf c} +%D \NC \framed[width=fit, height=.2\hsize, align=left] {a\endgraf b\endgraf c} +%D \NC \framed[width=fit, height=broad, align=left] {a\endgraf b\endgraf c} +%D \NC \framed[width=fit, height=fit, align=left] {a\endgraf b\endgraf c} +%D \NC \NR +%D % \HL +%D \NC \framed[width=.2\hsize, height=.2\hsize, align=middle] {a\endgraf b\endgraf c} +%D \NC \framed[width=.2\hsize, height=broad, align=middle] {a\endgraf b\endgraf c} +%D \NC \framed[width=.2\hsize, height=fit, align=middle] {a\endgraf b\endgraf c} +%D \NC \framed[width=fit, height=.2\hsize, align=middle] {a\endgraf b\endgraf c} +%D \NC \framed[width=fit, height=broad, align=middle] {a\endgraf b\endgraf c} +%D \NC \framed[width=fit, height=fit, align=middle] {a\endgraf b\endgraf c} +%D \NC \NR +%D % \HL +%D \stoptabulate %D \egroup %D \stoppostponing @@ -1921,18 +2078,20 @@ \newcount\framednoflines \newdimen\framedfirstheight \newdimen\framedlastdepth +\newdimen\framedminwidth +\newdimen\framedmaxwidth +\newdimen\framedaveragewidth -\def\resetshapeframebox - {\framednoflines \zerocount - \framedfirstheight\zeropoint - \framedlastdepth \zeropoint} +\def\pack_framed_reshape_reset + {\framednoflines \zerocount + \framedfirstheight \zeropoint + \framedlastdepth \zeropoint + \framedminwidth \zeropoint + \framedmaxwidth \zeropoint + \framedaveragewidth\zeropoint} -\let\framedboxwidth \!!zeropoint -\let\framedboxheight\!!zeropoint -\let\framedboxdepth \!!zeropoint - -\def\doreshapeframedbox{\ifvbox\framebox\ctxcommand{doreshapeframedbox(\number\framebox)}\fi} -\def\doanalyzeframedbox{\ifvbox\framebox\ctxcommand{doanalyzeframedbox(\number\framebox)}\fi} +\def\pack_framed_reshape_process{\ifvbox\b_framed_normal\ctxcommand{doreshapeframedbox(\number\b_framed_normal)}\fi} +\def\pack_framed_reshape_analyze{\ifvbox\b_framed_normal\ctxcommand{doanalyzeframedbox(\number\b_framed_normal)}\fi} % torture test / strange case (much depth) / method 2 needed % @@ -2002,41 +2161,6 @@ %D \egroup %D \stoppostponing -%D When typesetting the framed box inline, we have to keep the -%D baseline intact outside as well as inside the framed box. - -\def\doinlineframedbox - {\scratchdimen\dimexpr\strutdp+\ruledlinewidth\relax - \ifboxhasoffset - \advance\scratchdimen \framedparameter\c!offset - \fi - \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}% - \ht\framebox\strutht - \dp\framebox\strutdp - \box\framebox} - -%D We can also lower the box over the natural depth of the -%D line. - -\def\doloweredframedbox - {\ht\framebox\dimexpr\ht\framebox+\dp\framebox-\strutdp\relax - \dp\framebox\strutdp - \box\framebox} - -%D Hanging the content is mainly meant for cases like the -%D following: -%D -%D \starttyping -%D \framed[strut=no] -%D {\framed[height=2cm,location=hanging]{test}% -%D \framed[height=1cm,location=hanging]{test}} -%D \stoptyping - -\def\dohangingframedbox % best with strut=no - {\scratchdimen\dimexpr\ht\framebox+\dp\framebox\relax - \ht\framebox\zeropoint - \dp\framebox\scratchdimen} - %D We can draw lines from left to right and top to bottom by %D using the normal \type{\hairline} command. Both directions %D need a different treatment. @@ -2057,32 +2181,55 @@ %D possible to the circumstances and act as natural as %D possible. -\def\vboxedhairline - {\bgroup - \dimen2=\ifboxhasoffset \localoffset \else \zeropoint \fi - \dimen4=\dimexpr\dimen2+\ruledlinewidth\relax - \setbox0\vbox - {\advance\hsize 2\dimen4 - \vskip\dimen2 - \hrule - \!!height\ruledlinewidth - \!!depth\zeropoint - \!!width\hsize - \vskip\dimen2}% - %\endgraf\nointerlineskip\endgraf - %\moveleft\dimen4\box0 - %\endgraf\nointerlineskip\localbegstrut - \endgraf\obeydepth\nointerlineskip - \moveleft\dimen4\box0 - \endgraf\nointerlineskip\localbegstrut % beware, we might kill it in a style using \vskip\lineheight - \egroup} % so this must not be changed - -\def\hboxedhairline % use framed dimen +% \unexpanded\def\pack_framed_vboxed_hairline +% {\bgroup +% \dimen2=\ifconditional\c_framed_has_offset \localoffset \else \zeropoint \fi +% \dimen4=\dimexpr\dimen2+\d_framed_linewidth\relax +% \setbox0\vbox +% {\advance\hsize 2\dimen4 +% \vskip\dimen2 +% \hrule +% \!!height\d_framed_linewidth +% \!!depth\zeropoint +% \!!width\hsize +% \vskip\dimen2}% +% \endgraf\obeydepth\nointerlineskip +% \moveleft\dimen4\box0 +% \endgraf\nointerlineskip\localbegstrut % beware, we might kill it in a style using \vskip\lineheight +% \egroup} % so this must not be changed + +\unexpanded\def\pack_framed_vboxed_hairline % nasty overlay mess .. needed for autowidth + {\begingroup + \scratchoffset\ifconditional\c_framed_has_offset \localoffset \else \zeropoint \fi + \scratchwidth \dimexpr\scratchoffset+\d_framed_linewidth\relax + \par + \nointerlineskip + \kern\scratchoffset + \dontleavehmode + \hrule\!!height\d_framed_linewidth\!!depth\zeropoint + \par + \kern-\d_framed_linewidth + \dontleavehmode + \hbox to \zeropoint{\normalhss\vrule\!!height\d_framed_linewidth\!!depth\zeropoint\!!width\scratchwidth}% + \hfill + \hbox to \zeropoint{\vrule\!!height\d_framed_linewidth\!!depth\zeropoint\!!width\scratchwidth\normalhss}% + \par + \nointerlineskip + \kern\scratchoffset + \nointerlineskip + \endgraf + \nointerlineskip + \localbegstrut + \endgroup} + +% todo: + +\unexpanded\def\pack_framed_hboxed_hairline % use framed dimen {\bgroup - \dimen2=\ifboxhasoffset \localoffset \else \zeropoint \fi - \ifboxhasheight - \dimen4\dimexpr\localheight/2+\strutdp-2\ruledlinewidth\relax - \dimen6\dimexpr\localheight/2-\strutdp+2\ruledlinewidth\relax + \dimen2=\ifconditional\c_framed_has_offset \localoffset \else \zeropoint \fi + \ifconditional\c_framed_has_height + \dimen4\dimexpr\localheight/2+\strutdp-2\d_framed_linewidth\relax + \dimen6\dimexpr\localheight/2-\strutdp+2\d_framed_linewidth\relax \else \dimen4\dimexpr\strutht+\dimen2\relax \dimen6\dimexpr\strutdp+\dimen2\relax @@ -2090,7 +2237,7 @@ \unskip \setbox\scratchbox\hbox {\hskip\dimen2 - \vrule\!!height\dimen4\!!depth\dimen6\!!width\ruledlinewidth + \vrule\!!height\dimen4\!!depth\dimen6\!!width\d_framed_linewidth \hskip\dimen2}% \ht\scratchbox\strutht \dp\scratchbox\strutdp @@ -2102,10 +2249,10 @@ %D sort of newline signal. In horizontal boxes it expands to a %D space. -\unexpanded\def\vboxednewline +\unexpanded\def\pack_framed_vboxed_newline {\endgraf\ignorespaces} -\unexpanded\def\hboxednewline +\unexpanded\def\pack_framed_hboxed_newline {\unskip\normalspace\ignorespaces} %D We can set each rule on or off. The default setting is @@ -2149,487 +2296,6 @@ %D \egroup %D \macros -%D {setupblackrules} -%D -%D The graphic capabilities of \TEX\ do not go beyond simple -%D filled rules, except of course when using specials. Let's -%D start with a warning: using this commands is far more slower -%D than using the \TEX\ primitives \type{\hrule} and -%D \type{\vrule}, but they save us some tokens. The -%D characteristics of these rule drawing command can be set by: -%D -%D \showsetup{setupblackrules} - -\unexpanded\def\setupblackrules - {\dodoubleargument\getparameters[\??bj]} - -%D \macros -%D {blackrule} -%D -%D The simple command draws only one rule. Its optional -%D argument can be used to specify the dimensions. By setting -%D the width, height or depth to \type {max}, one gets the -%D natural dimensions. -%D -%D \showsetup{blackrule} - -\definecomplexorsimple\blackrule - -\unexpanded\def\complexblackrule[#1]% - {\hbox\bgroup\getparameters[\??bj][#1]\domakeblackrule\egroup} - -\unexpanded\def\simpleblackrule - {\hbox\bgroup\domakeblackrule\egroup} - -\def\domakeblackrule - {\doif\@@bjwidth \v!max{\def\@@bjwidth {1em}}% - \doif\@@bjheight\v!max{\setstrut\let\setstrut\relax\def\@@bjheight{\strutht}}% - \doif\@@bjdepth \v!max{\setstrut\def\@@bjdepth {\strutdp}}% - \startcolor[\@@bjcolor]% can be made faster, just direct attr - \vrule - \!!width \@@bjwidth - \!!height\@@bjheight - \!!depth \@@bjdepth - \stopcolor} - -%D \macros -%D {blackrules} -%D -%D One can call for a sequence of black rules, if needed -%D equally spaced over the given width. -%D -%D \showsetup{blackrules} -%D -%D The two alternative calls are therefore: -%D -%D \startbuffer -%D Tell me, is this according to the \blackrules[n=6]? -%D These \blackrules[alternativevariant=b,n=10,distance=.2em,width=4cm] are quite clear. -%D \stopbuffer -%D -%D \typebuffer -%D -%D or: -%D -%D \startvoorbeeld -%D \startlines -%D \getbuffer -%D \stoplines -%D \stopvoorbeeld -%D -%D We could of course have implemented this macro using -%D \type{\leaders}, but this would probably have taken more -%D tokens. - -\def\doblackrules[#1]% - {\hbox\bgroup - \getparameters[\??bj][#1]% - \!!widtha\@@bjwidth - \!!widthb\@@bjdistance - \doif\@@bjalternative\c!b - {\scratchcounter\@@bjn - \ifnum\scratchcounter=\plusone - \!!widthb\zeropoint - \else - \advance\scratchcounter \minusone - \advance\!!widtha -\scratchcounter\!!widthb - \divide \!!widtha \@@bjn - \fi}% - \startcolor[\@@bjcolor]% - \dorecurse\@@bjn - {\vrule - \!!width \!!widtha - \!!height\@@bjheight - \!!depth \@@bjdepth - \hskip\!!widthb}% - \unskip - \stopcolor - \egroup} - -\unexpanded\def\blackrules - {\dosingleempty\doblackrules} - -%D The next commands can be used to draw margin rules. We -%D support two methods: \marginrule{one for in||line use} and -%D one that acts on a paragraph. Drawing a margin rule is -%D rather straightforward because we can use the commands that -%D put text in the margin. - -\def\dodrawmarginrule - {\setbox\scratchbox\hbox - {\vrule\!!depth\strutdepth\!!height\strutheight\!!width\@@karulethickness}% - \smashbox\scratchbox % no \vsmash !!! - \box\scratchbox} - -\def\drawmarginrule - {\strut\inleft{\dodrawmarginrule}} - -%D \macros -%D {marginrule} -%D -%D The first method gobbles words and simply puts a bar in the -%D margin. This method is not entirely robust. -%D -%D \showsetup{marginrule} - -\definecomplexorsimple\marginrule - -\def\simplemarginrule - {\let\processword\drawmarginrule - \processwords} - -\def\complexmarginrule[#1]% - {\ifnum#1<\@@kalevel\relax \else - \def\@@kadefaultwidth{#1}% - \expandafter\simplemarginrule - \fi} - -%D We need an auxiliary variable - -\def\@@kadefaultwidth{1} - -%D \macros -%D {setupmarginrules} -%D -%D This macro definitions show us that we can pass an optional -%D level, which is matched against the previous set one. The -%D level can be set up with -%D -%D \showsetup{setupmarginrules} - -\unexpanded\def\setupmarginrules - {\dodoubleargument\getparameters[\??ka]} - -%D \macros -%D {startmarginrule} -%D -%D The second method collects text and reformats it afterwards, -%D using the shapebox macros. We prevent local margin rules. -%D -%D \showsetup{startmarginrule} - -\definecomplexorsimple\startmarginrule - -\def\simplestartmarginrule - {\bgroup - \let\drawmarginrule\relax - \let\stopmarginrule\dostopmarginrule - \beginofshapebox} - -\def\complexstartmarginrule[#1]% - {\bgroup - \let\drawmarginrule\relax - \ifnum#1<\@@kalevel\relax - \let\stopmarginrule\egroup - \else - \def\@@kadefaultwidth{#1}% - \let\stopmarginrule\dostopmarginrule - \expandafter\beginofshapebox - \fi} - -\def\dostopmarginrule - {\endofshapebox - \reshapebox - {\hbox{\inleftmargin{\dodrawmarginrule}\box\shapebox}}% - \flushshapebox - \egroup} - -%D \startbuffer -%D \setupmarginrules[level=5] -%D -%D \startmarginrule[1] -%D First we set the level at~5. Next we typeset this first -%D paragraph as a level~1 one. As expected no rule show up. -%D \stopmarginrule -%D -%D \startmarginrule[5] -%D The second paragraph is a level~5 one. As we can see here, -%D the marginal rule gets a width according to its level. -%D \stopmarginrule -%D -%D \startmarginrule[8] -%D It will of course be no surprise that this third paragraph -%D has a even thicker margin rule. This behavior can be -%D overruled by specifying the width explictly. -%D \stopmarginrule -%D \stopbuffer -%D -%D In next example we show most features. Watch the rule -%D thickness adapting itself to the level. -%D -%D \startvoorbeeld -%D \getbuffer -%D \stopvoorbeeld -%D -%D We just said: -%D -%D \typebuffer - -%D \macros -%D {vl, hl} -%D -%D The command \type{\vl} draws a vertical rule \vl\ with strut -%D dimensions, multiplied with the factor specified in the -%D optional argument. The height and depth are clipped \vl[3] -%D to the baselinedistance. Its horizontal counterpart -%D \type{\hl} draws a horizontal rule \hl\ with a width of 1em, -%D multiplied with the optional factor. The horizontal rule is -%D drawn on top of the baseline. -%D -%D \showsetup{vl} -%D \showsetup{hl} - -\def\dovlwdhtdp#1#2#3% - {\bgroup - \setbox\scratchbox\hbox - {\vrule - \!!width #1\linewidth - \!!height#2\strutht - \!!depth #3\strutdp}% - \dp\scratchbox\strutdp - \ht\scratchbox\strutht - \box\scratchbox - \egroup} - -\def\complexvl[#1]% - {\dovlwdhtdp\plusone{#1}{#1}} - -\def\complexhl[#1]% - {\hbox - {\vrule - \!!width #1\s!em - \!!height\linewidth - \!!depth \zeropoint}} - -\definecomplexorsimple\vl \def\simplevl{\complexvl[1]} -\definecomplexorsimple\hl \def\simplehl{\complexhl[1]} - -%D \macros -%D {hairline, thinrule, thinrules, setupthinrules} -%D -%D Drawing thin lines can of course easily be accomplished by -%D the \TEX\ primitives \type{\hrule} and \type{\vrule}. The -%D next few macros however free us from some specifications. -%D -%D \startbuffer -%D some text -%D -%D \hairline -%D -%D some more text -%D -%D \thinrule -%D -%D more and more text -%D -%D hi \thinrule\ there -%D -%D and then the final text -%D \stopbuffer -%D -%D \typebuffer -%D -%D becomes -%D -%D \startvoorbeeld -%D \getbuffer -%D \stopvoorbeeld -%D -%D So we've got -%D -%D \showsetup{hairline} -%D \showsetup{thinrule} -%D -%D Both can be set up with: -%D -%D \showsetup{setupthinrules} -%D -%D We also have -%D -%D \showsetup{thinrules} -%D -%D which looks like: \thinrules[n=2] - -\newconstant\ruletype - -\def\thinrule - {\strut - \bgroup - \ruletype\plusone - \processaction - [\@@dlalternative] - [ \v!a=>\ruletype\zerocount,% no line - %\v!b=>\ruletype\plusone ,% height/depth - \v!c=>\ruletype\plustwo ,% topheight/botdepth - % 11=>\ruletype\plusone ,% fallback for backgrounds - 0=>\ruletype\zerocount,% compatible with backgrounds - % 1=>\ruletype\plusone ,% compatible with backgrounds - 2=>\ruletype\plustwo ]% compatible with backgrounds - \doifsomething\@@dlrulethickness - {\linewidth\@@dlrulethickness}% - \ifdim\linewidth=\zeropoint - \ruletype\zerocount - \else - \doifnot\@@dlframe\v!on{\ruletype\zerocount}% - \fi - \ifnum\ruletype=\plusone - \doif\@@dlheight\v!max{\let\@@dlheight\!!plusone}% - \doif\@@dldepth \v!max{\let\@@dldepth \!!plusone}% - \else - \let\@@dlheight\!!plusone - \let\@@dldepth\!!plusone - \fi - \freezedimensionwithunit\@@dlheight\strutht - \freezedimensionwithunit\@@dldepth\strutdp - \divide\linewidth \plustwo - \doifelse\@@dlbackground\v!color - {\startcolor[\@@dlbackgroundcolor]% - \ifnum\ruletype=\plustwo % prevent overshoot due to rounding - \leaders - \hrule - \!!height\dimexpr\@@dlheight-.5\linewidth\relax - \!!depth \dimexpr\@@dldepth -.5\linewidth\relax - \hfill - \else - \leaders - \hrule - \!!height\@@dlheight - \!!depth \@@dldepth - \hfill - \fi - \stopcolor - \ifcase\ruletype - % no rule - \or - \startcolor[\@@dlcolor]% - \hfillneg - \leaders\hrule\!!height\linewidth\!!depth\linewidth\hfill - \stopcolor - \or - \startcolor[\@@dlcolor]% - \hfillneg\leaders\hrule\!!height\dimexpr-\@@dldepth+\linewidth\relax\!!depth\@@dldepth\hfill - \hfillneg\leaders\hrule\!!height\@@dlheight\!!depth\dimexpr-\@@dlheight+\linewidth\relax\hfill - \stopcolor - \fi} - {\ifcase\ruletype \else - \startcolor[\@@dlcolor]% - \leaders\hrule\!!height\@@dlheight\!!depth\@@dldepth\hfill - \stopcolor - \fi}% - \strut - \carryoverpar\egroup} - -\def\hairline - {\endgraf - \thinrule - \endgraf} - -\def\dosetupthinrules[#1]% - {\getparameters[\??dl][#1]} - -\unexpanded\def\setupthinrules - {\dosingleargument\dosetupthinrules} - -\def\dothinrules[#1]% - {\bgroup - \dosetupthinrules[#1]% - \@@dlbefore - \assignvalue\@@dlinterlinespace\@@dlinterlinespace{1.0}{1.5}{2.0}% - \spacing\@@dlinterlinespace - \dorecurse\@@dln - {\ifnum\recurselevel=\@@dln \dothinrulesnobreak \else - \ifnum\recurselevel=2 \dothinrulesnobreak \fi\fi - \thinrule - \ifnum\recurselevel<\@@dln\relax - % test needed, else messed up whitespace - \ifx\@@dlinbetween\empty - \softbreak - \else - \endgraf - \nowhitespace - \@@dlinbetween - \fi - \fi}% - \doifelsenothing\@@dlafter - {\carryoverpar\egroup} - {\@@dlafter\egroup}} - -\def\thinrules - {\dosingleempty\dothinrules} - -%D A couple of examples are given below. -%D -%D \startbuffer -%D \setupthinrules[n=3,inbetween=,color=gray] -%D -%D test test \thinrules\ test test \par -%D test test \thinrules [color=green] test test \par -%D test test \thinrules [height=max, depth=max] test test \par -%D -%D \setupthinrules[height=.9,depth=.9] -%D -%D test test \thinrules\ test test \par -%D test test \thinrules [alternativevariant=b] test test \par -%D test test \thinrules [alternativevariant=c] test test \par -%D test test \thinrules [alternativevariant=c,inbetween=\vskip2ex] test test \par -%D \stopbuffer -%D -%D \typebuffer {\getbuffer} -%D -%D There are a couple of alternative ways to visualize rules -%D using backgrounds. At first sight these may look strange, -%D but they make sense in educational settings. The -%D alternatives are more or less compatible with the more -%D advanced \METAPOST\ based implementation. -%D -%D \startbuffer[a] -%D \setupthinrules -%D [n=2, -%D backgroundcolor=gray , -%D rulethickness=1pt, -%D colorkleur=donkerblauw, -%D after=\blank, -%D before=\blank] -%D \stopbuffer -%D -%D \typebuffer[a] -%D -%D \startbuffer[b] -%D \thinrules[alternativevariant=a] -%D \thinrules[alternativevariant=b] -%D \thinrules[alternativevariant=c] -%D \stopbuffer -%D -%D \typebuffer[b] \getbuffer[a,b] -%D -%D \startbuffer[b] -%D \thinrules[alternativevariant=a,background=color] -%D \thinrules[alternativevariant=b,background=color] -%D \thinrules[alternativevariant=c,background=color] -%D \stopbuffer -%D -%D \typebuffer[b] \getbuffer[a,b] -%D -%D \startbuffer[b] -%D \thinrules[alternativevariant=a,height=.8,depth=.8,background=color] -%D \thinrules[alternativevariant=b,height=.8,depth=.8,background=color] -%D \thinrules[alternativevariant=c,height=.8,depth=.8,background=color] -%D \stopbuffer -%D -%D \typebuffer[b] \getbuffer[a,b] - -%D \macros -%D {optimizethinrules} -%D -%D By saying \type {\thinrulestrue} or \type {-false}, we -%D can influence the way dangling lines are handled. - -\newif\ifoptimizethinrules \optimizethinrulestrue - -\def\dothinrulesnobreak - {\ifoptimizethinrules\penalty500\fi} - -%D \macros %D {startframedtext, setupframedtexts, defineframedtext} %D %D The general framing command we discussed previously, is not @@ -2713,11 +2379,12 @@ %D %D The next definition shows the defaults. -\installcommandhandler \??kd {framedtext} \??kd +\installcorenamespace{framedtext} +\installcorenamespace{framedtextlocation} -\let\setupframedtexts\setupframedtext +\installframedcommandhandler \??framedtext {framedtext} \??framedtext -\presetlocalframed[\??kd] +\let\setupframedtexts\setupframedtext \setupframedtext [\c!width=0.75\hsize, @@ -2753,119 +2420,120 @@ \c!margin=\v!standard] \appendtoks - \setuevalue{\e!start\currentframedtext}{\dostartframedtext{\currentframedtext}}% - \setuevalue{\e!stop \currentframedtext}{\dostopframedtext }% - \setuevalue {\currentframedtext}{\doframedtext {\currentframedtext}}% + \setuevalue{\e!start\currentframedtext}{\pack_framed_text_start {\currentframedtext}}% + \setuevalue{\e!stop \currentframedtext}{\pack_framed_text_stop }% + \setuevalue {\currentframedtext}{\pack_framed_text_direct{\currentframedtext}}% \to \everydefineframedtext -\unexpanded\def\dostartframedtext#1% +\setvalue{\??framedtextlocation\v!left }{\letframedtextparameter\c!left \relax + \letframedtextparameter\c!right\hfill} + +\setvalue{\??framedtextlocation\v!right }{\letframedtextparameter\c!left \hfill + \letframedtextparameter\c!right\relax} + +\setvalue{\??framedtextlocation\v!middle}{\letframedtextparameter\c!left \hfill + \letframedtextparameter\c!right\hfill} + +\setvalue{\??framedtextlocation\v!none }{\letframedtextparameter\c!left \relax + \letframedtextparameter\c!right\relax + \settrue\c_framed_text_location_none} + +\unexpanded\def\pack_framed_text_start#1% {\bgroup \edef\currentframedtext{#1}% - \dodoubleempty\dodostartframedtext} + \dodoubleempty\pack_framed_text_start_indeed} -\def\dodostartframedtext[#1][#2]% +\def\pack_framed_text_start_indeed[#1][#2]% {\doifassignmentelse{#1} - {\dododostartframedtext[][#1]} - {\dododostartframedtext[#1][#2]}} + {\pack_framed_text_start_continue\empty{#1}} + {\pack_framed_text_start_continue{#1}{#2}}} -\def\dododostartframedtext[#1][#2]% #2 only passed to framed, not to framedtext +\def\pack_framed_text_start_continue#1#2% {\setupframedtexts[\currentframedtext][#2]% \doifsomething{#1}{\setframedtextparameter\c!location{#1}}% does not listen to #3 - \setfalse\framedtextlocationnone - % somewhat messy ... needs to be redone - \processaction % \v!low en \v!depth are already taken ! - [\framedtextparameter\c!location] - [ \v!left=>\letframedtextparameter\c!left \relax - \letframedtextparameter\c!right\hfill, - \v!right=>\letframedtextparameter\c!left \hfill - \letframedtextparameter\c!right\relax, - \v!middle=>\letframedtextparameter\c!left \hfill - \letframedtextparameter\c!right\hfill, - \v!none=>\letframedtextparameter\c!left \relax % new - \letframedtextparameter\c!right\relax % new - \settrue\framedtextlocationnone]% + \setfalse\c_framed_text_location_none + \csname\??framedtextlocation\framedtextparameter\c!location\endcsname \resetframedtextparameter\c!location - % removed 06/2001 - % \forgetparindent - % added 06/2001 [see demo-bbv] - \localhsize\hsize \checkframedtext - % so far - \setbox\framebox\vbox + \pack_framed_text_check + \setbox\b_framed_normal\vbox \startboxedcontent \hsize\localhsize % \insidefloattrue % ? better - \normalexpanded{\noexpand\switchtobodyfont[\framedtextparameter\c!bodyfont]}% - \startcolor[\framedtextparameter\c!color]% - \localframed[\??kd\currentframedtext][\c!strut=\v!no]% todo: use delayedstrut - \bgroup + \normalexpanded{\switchtobodyfont[\framedtextparameter\c!bodyfont]}% +% \startcolor[\framedtextparameter\c!color]% + \letframedtextparameter\c!strut\v!no + \inheritedframedtextframed\bgroup \let\\=\endgraf \framedtextparameter\c!inner % oud spul - \doif{\framedtextparameter\c!depthcorrection}\v!on\doftstartdepthcorrection - \doinhibitblank % \blank[\v!disable]% plaatst signal + \doif{\framedtextparameter\c!depthcorrection}\v!on\pack_framed_text_start_depth_correction + \doinhibitblank \setupindenting[\framedtextparameter\c!indenting]% - %\doconvertfont{\framedtextparameter\c!style}\empty} %%%%% todo: attr setter - \dosetframedtextattributes\c!style\c!color} + \useframedtextstyleandcolor\c!style\c!color} %D The \type {none} option is handy for nested usage, as %D in the presentation styles, where we don't want %D interference. -\defineplacement[\??kd][\s!parent=\??kd\currentframedtext] +\defineplacement[\??framedtext][\s!parent=\??framedtext\currentframedtext] -\unexpanded\def\dostopframedtext % no \baselinecorrection, see faq docs +\unexpanded\def\pack_framed_text_stop % no \baselinecorrection, see faq docs {\endgraf \removelastskip - \doif{\framedtextparameter\c!depthcorrection}\v!on\doftstopdepthcorrection + \doif{\framedtextparameter\c!depthcorrection}\v!on\pack_framed_text_stop_depth_correction \stopboxedcontent - \stopcolor - \ifconditional\framedtextlocationnone +% \stopcolor + \ifconditional\c_framed_text_location_none \egroup - \box\framebox + \box\b_framed_normal \else\ifinsidefloat \egroup - \box\framebox + \box\b_framed_normal \else \egroup - \placement[\??kd][\c!depthcorrection=\v!off]{\box\framebox}% + \placement[\??framedtext][\c!depthcorrection=\v!off]{\box\b_framed_normal}% \fi\fi \egroup} %D We define the general (and original) case by just saying: -\setfalse\framedtextlocationnone - -\def\checkframedtext % messy dependency - {\ifinsidefloat - \localhsize\hsize - \else\ifdim\sidefloatvsize>\zeropoint % will be proper handle +\def\pack_framed_text_check % messy dependency + {\localhsize\hsize + \ifinsidefloat \else \ifdim\d_page_sides_vsize>\zeropoint % also possible: \c_page_sides_checks_done>\zeropoint % \strut % rather clean way to invoke the sidefloat OTR % \setbox0=\lastbox % and get the widths set, so from now on we % \setlocalhsize % can have framed texts alongside sidefloats \checksidefloat \setlocalhsize - \else - \localhsize\hsize - \fi\fi} + \fi \fi} -\def\doftstartdepthcorrection +\def\pack_framed_text_start_depth_correction {\bgroup - \verticalstrut - % we need \nowhitespace in case of setups setting whitespace - % nb, not safe, text vs \vbox as next - \vskip-\struttotal - \nowhitespace} % na vskip ! new 20/05/2004, fails with next content being box (\scale{..}) - -\def\doftstopdepthcorrection - {\forgetall - \vskip-\struttotal - \verticalstrut - \egroup - \forgetall % brrr too often - \vskip-\lineheight - % will be an option, not default - % \setbaselinecorrections - % \donegbotbaselinecorrection - \verticalstrut} + \ifhmode + \par + \fi + \ifvmode + \verticalstrut + % we need \nowhitespace in case of setups setting whitespace + % nb, not safe, text vs \vbox as next + \vskip-\struttotal + \nowhitespace + \fi} % na vskip ! new 20/05/2004, fails with next content being box (\scale{..}) + +\def\pack_framed_text_stop_depth_correction + {\ifhmode + \par + \fi + \ifvmode + \forgetall + \vskip-\struttotal + \verticalstrut + \egroup + \forgetall % brrr too often + \vskip-\lineheight + \verticalstrut + \else + \egroup + \fi} %D Placement can be ignored: %D @@ -2885,26 +2553,28 @@ %D The simple brace (or group) delimited case is typeset %D slightly different and is not aligned. -\unexpanded\def\doframedtext#1% +\unexpanded\def\pack_framed_text_direct#1% {\bgroup \edef\currentframedtext{#1}% - \dosingleempty\dodoframedtext} + \dosingleempty\pack_framed_text_start_direct} -\def\dodoframedtext[#1]% beware! - {\normalexpanded{\noexpand\switchtobodyfont[\\framedtextparameter\c!bodyfont]}% - \localframed[\??kd\currentframedtext][\c!strut=\v!no,#1]% +\def\pack_framed_text_start_direct[#1]% + {\normalexpanded{\switchtobodyfont[\framedtextparameter\c!bodyfont]}% + \letframedtextparameter\c!strut\v!no + \iffirstargument + \setupcurrentframedtext[#1]% + \fi + \inheritedframedtextframed\bgroup + \blank[\v!disable]% + \let\\=\endgraf + \framedtextparameter\c!inner + \useframedtextstyleandcolor\c!style\c!color \bgroup - \blank[\v!disable]% - \let\\=\endgraf - \framedtextparameter\c!inner - \dosetframedtextattributes\c!style\c!color - \bgroup - \aftergroup\docloseframedtext - \let\next=} + \aftergroup\pack_framed_text_stop_direct + \let\next=} -\def\docloseframedtext +\def\pack_framed_text_stop_direct {\removelastskip - \dostopattributes \egroup \egroup} @@ -2922,24 +2592,44 @@ %D also simplified the \type {\setupframed} command. There are %D certainly more places where such improvements can be made. -\def\defineframed - {\dodoubleempty\dodefineframed} +% actually, this can be another command handler .. todo -\def\dodefineframed[#1][#2]% +\unexpanded\def\defineframed + {\dotripleempty\pack_framed_define} + +\def\pack_framed_define[#1][#2][#3]% {\ifcsname\??ol:#1\endcsname % already defined, keeps settings \else \expandafter\newcount\csname\??ol:#1\endcsname % \the\everypresetframed \fi - \getparameters[\??ol#1][\s!parent=\??ol,#2]% - \setuvalue{#1}{\doframed[#1]}}% % \the\everydefineframed + \ifsecondargument + \doifassignmentelse{#2} + {\getparameters[\??ol#1][\s!parent=\??ol,#2]}% + {\ifcsname#2\endcsname + \getparameters[\??ol#1][\s!parent=\??ol#2,#3]% + \else + \getparameters[\??ol#1][\s!parent=\??ol,#3]% + \fi}% + \else + \getparameters[\??ol#1][\s!parent=\??ol,#2]% + \fi + \setuvalue{#1}{\pack_framed_defined_process[#1]}}% % \the\everydefineframed + +\newcount\c_framed_crap -\def\doframed[#1]% +\unexpanded\def\pack_framed_defined_process[#1]% official (not much checking, todo: parent) {\bgroup - \expandafter\let\expandafter\tempframedcount\csname\??ol:#1\endcsname - \advance\tempframedcount\plusone - \expandafter\def\csname\??ol#1:\the\tempframedcount\s!parent\endcsname{\??ol#1}% \copylocalframed - \dodoubleempty\dolocalframed[\??ol#1:\the\tempframedcount]} + \ifcsname\??ol:#1\endcsname + \expandafter\let\expandafter\c_framed_temp\csname\??ol:#1\endcsname + \else + \let\c_framed_temp\c_framed_crap + \fi + \advance\c_framed_temp\plusone + \expandafter\def\csname\??ol#1:\the\c_framed_temp\s!parent\endcsname{\??ol#1}% \inheritlocalframed + \dodoubleempty\pack_framed_process[\??ol#1:\the\c_framed_temp]} + +\let\placeframed\pack_framed_defined_process % new per 2012/04/23 %D We can do: %D @@ -2949,464 +2639,6 @@ %D %D but the existing one is ok as well (less csname messy too). -%D \macros -%D {textrule, starttextrule, setuptextrules} -%D -%D Putting rules before and after a paragraph is very space -%D sensitive, but the next command handles that quite well. It -%D comes in two disguises: -%D -%D \startbuffer -%D \textrule[top]{fragments} -%D \input reich -%D \textrule -%D \stopbuffer -%D -%D \bgroup \typebuffer \getbuffer \egroup -%D -%D \startbuffer -%D \setuptextrules -%D [width=90pt,distance=12pt,rulecolor=blue, -%D bodyfont=small,style=\sc,color=red] -%D -%D \starttextrule{Ship Building Tools} -%D \nl \setuptolerance[tolerant] \input materie -%D \stoptextrule -%D \stopbuffer -%D -%D \bgroup \typebuffer \getbuffer \egroup -%D -%D \startbuffer -%D \setuptextrules -%D [location=inmargin, -%D bodyfont=small,style=slantedbold] -%D -%D \starttextrule{wonderful} -%D \input tufte -%D \stoptextrule -%D \stopbuffer -%D -%D \bgroup \typebuffer \getbuffer \egroup -%D -%D The formal definition of these commands is: -%D -%D \showsetup{textrule} -%D \showsetup{starttextrule} -%D \showsetup{setuptextrules} -%D -%D The implementation looks a bit complicated due to the -%D optional arguments. - -\unexpanded\def\setuptextrules - {\dodoubleargument\getparameters[\??tl]} - -\def\complextextrule[#1]% if needed we can make it installable - {\let\next\dobottomtextrule - \processaction - [#1] - [ \v!top=>\let\next\dotoptextrule, - \v!middle=>\let\next\domiddletextrule, - \v!bottom=>\let\next\dobottomtextrule]% - \dosinglegroupempty\next} - -\definecomplexorsimple\textrule - -\def\simpletextrule - {\dosinglegroupempty\dounknowntextrule} - -\def\docomplextextrule#1% - {\bgroup - \advance\hsize\dimexpr-\rightskip-\leftskip\relax - \setbox\scratchbox\hbox to \hsize - {\dimen4\dimexpr .5ex+.5\linewidth\relax - \dimen6\dimexpr-.5ex+.5\linewidth\relax - \doifsomething{#1} - {\doifelse\@@tllocation\v!inmargin - {\llap{\doattributes\??tl\c!style\c!color{#1}\hskip\leftmargindistance}} - {\color[\@@tlrulecolor] - {\vrule\!!height\dimen4\!!depth\dimen6\!!width\@@tlwidth}% - \hbox spread 2\dimexpr\@@tldistance\relax - {\hss\doattributes\??tl\c!style\c!color{\strut#1}\hss}}}% - \color[\@@tlrulecolor] - {\leaders\hrule\!!height\dimen4\!!depth\dimen6\hfill}}% - \ht\scratchbox\strutht - \dp\scratchbox\strutdp - \noindent\box\scratchbox -%\nobreak\verticalstrut\kern-\struttotal -% evt \witruimte - \egroup} - -\def\dotoptextrule#1% - {\page[\v!preference] % interferes - %\whitespace % no - \@@tlbefore - \docomplextextrule{#1}% -% todo, option: \doifnothing{#1}{\ruledvskip-.5ex} - \nowhitespace - \@@tlinbetween - \endgraf} - -\def\dodobottomtextrule#1#2% - {\ifhmode - \endgraf - \fi - \dimen0\strutdp - \ifdim\prevdepth>\strutdp\else % was <\strutdp - \ifdim\prevdepth>\zeropoint - \advance\dimen0 -\prevdepth - \fi - \fi - \advance\dimen0 .5ex - \vskip\dimen0 -% == -% \vskip\dimexpr \strutdp + .5ex -% \ifdim\prevdepth>\strutdp\else\ifdim\prevdepth>\zeropoint-\prevdepth\fi\fi\relax -% - \@@tlinbetween - \doifelsenothing{#2} - {\bgroup - \advance\hsize\dimexpr-\rightskip-\leftskip\relax - \nointerlineskip - \moveleft-\leftskip\vbox - {\color[\@@tlrulecolor] - {\hrule\!!depth\linewidth\!!height\zeropoint\!!width\hsize}}% - \egroup} - {\docomplextextrule{#2}}% - \ifvmode\prevdepth\zeropoint\fi - #1% - \page[\v!preference]} - -\def\dobottomtextrule - {\dodobottomtextrule\@@tlafter} - -\def\domiddletextrule - {\dodobottomtextrule\@@tlinbetween} - -\def\dounknowntextrule - {\iffirstargument - \@EA\dotoptextrule - \else - \@EA\dobottomtextrule\@EA\empty - \fi} - -%D The grouped commands also supports bodyfont switching: - -\unexpanded\def\starttextrule#1% - {\bgroup - \def\dounknowntextrule{\domiddletextrule} - \dotoptextrule{#1} - \bgroup - \doifsomething\@@tlbodyfont{\switchtobodyfont[\@@tlbodyfont]}} - -\unexpanded\def\stoptextrule - {\par - \egroup - \dobottomtextrule\empty - \egroup} - -%D \macros -%D {fillinrules, setupfillinrules} -%D -%D The next few commands do not really deserve a place in a -%D core module, because they deal with specific typography. -%D Nevertheless I decided to make them part of the core, -%D because they permit us to make questionaires. Let's start -%D with some examples. -%D -%D \fillinrules[n=2,width=fit]{first} -%D \fillinrules[n=2,width=broad]{first} -%D \fillinrules[n=2,width=3cm]{first} -%D \fillinrules[n=2,width=3cm,distance=.5em,separator=:]{first} -%D \fillinrules[n=2]{first}{last} -%D \fillintext{first}{last} \input reich \par -%D -%D The main command is \type{\fillinrules}. This command takes -%D one and an optional second argument and sets a paragraph with -%D empty visualized lines. -%D -%D \showsetup{fillinrules} -%D \showsetup{setupfillinrules} - -\unexpanded\def\setupfillinrules - {\dodoubleargument\getparameters[\??il]} - -\definecomplexorsimpleempty\fillinrules - -\def\complexfillinrules[#1]% - {\def\docomplexfillinrules##1##2% - {\dodocomplexfillinrules[#1]{##1}{##2}{\thinrules - [\c!n=\@@iln,\c!interlinespace=\@@ilinterlinespace,\c!before=,\c!after=]}}% - \dodoublegroupempty\docomplexfillinrules} - -\def\dodocomplexfillinrules[#1]#2#3#4% - {\endgraf - \@@ilbefore - \begingroup - \setupfillinrules[#1]% - \noindent - \doifsomething{#2} - {\doifelse\@@ilwidth\v!fit - {\let\@@ildistance\!!zeropoint - \hbox} - {\doifelse\@@ilwidth\v!broad - {\hbox} - {\hbox to \@@ilwidth}}% - \bgroup - \doattributes\??il\c!style\c!color{\strut#2\hfill\@@ilseparator}% - \hskip\@@ildistance - \egroup}% - %\hangindent=\wd0\relax % tzt hang=yes,n - %\parindent=\hangindent - %\box0\relax - \setupwhitespace[\v!big]% - \ignorespaces - #4% - \doifsomething{#3} - {\kern\@@ildistance - \doattributes\??il\c!style\c!color{#3\strut}}% - \endgroup - \endgraf - \@@ilafter} - -%D \macros -%D {fillintext} -%D -%D To provide compatible layouts when texts and lines are -%D mixed, one can typeset a paragraph by using the command -%D \type{\fillintext}. -%D -%D \showsetup{fillintext} - -\definecomplexorsimpleempty\fillintext - -\def\complexfillintext[#1]% rather rough, using an \unhbox is suboptimal - {\def\docomplexfillintext##1##2% - {\dowithnextbox - {\dodocomplexfillinrules[#1]{##1}{\hfill##2}{\unhbox\nextbox\unskip}}% - \hbox\bgroup\let\par\egroup\ignorespaces}% - \dodoublegroupempty\docomplexfillintext} - -%D \macros -%D {fillinline, setupfillinlines} -%D -%D Another member of the family takes care of putting a (often -%D small) rule after a piece of text, like -%D -%D \startbuffer -%D \fillinline \input reich \par -%D \fillinline[margin=0cm] \input reich \par -%D \stopbuffer -%D -%D \startvoorbeeld -%D \getbuffer -%D \stopvoorbeeld -%D -%D which was typeset by saying: -%D -%D \typebuffer -%D -%D The two commands that take care of this are: -%D -%D \showsetup{fillinline} -%D \showsetup{setupfillinlines} - -\unexpanded\def\setupfillinlines - {\dodoubleargument\getparameters[\??iv]} - -\definecomplexorsimpleempty\fillinline - -\def\complexfillinline[#1]% - {%\endgraf % interferes with \definedescription cum suis - \@@ivbefore - \begingroup - \setupfillinlines[#1]% - \advance\rightskip \@@ivmargin - \parfillskip\zeropoint - \def\par % very dangerous - {\let\par\endgraf % -) - \ifhmode\unskip\hfill\fi - \scratchdimen\dimexpr\@@ivwidth-\@@ivdistance\relax - \ifdim\scratchdimen>\@@ivmargin\else\expandafter\rlap\fi - {\kern\@@ivdistance - \vrule - \!!width \scratchdimen - \!!height.5\linewidth - \!!depth .5\linewidth}% - \endgraf % ! - \endgroup - \endgraf % ! - \@@ilafter}} - -%D \stopdocumentation -%D \bgroup -%D -%D \setupframedtexts -%D [setuptext] -%D [background=color,backgroundcolor=white] -%D -%D \startbuffer -%D \setupbackground -%D [backgroundoffset=4pt, -%D background=screen, -%D frame=on, -%D framecolor=red, -%D leftoffset=2pt] -%D \stopbuffer -%D -%D \getbuffer -%D -%D \startbackground -%D -%D \macros -%D {setupbackground,startbackground,background} -%D -%D The section deals with backgrounds in the running text. This -%D means that texts is to be collected and split over pages. To -%D show what can be done, we provide this part of the -%D documentation with some gray background and a red frame. -%D Both the background and frame can have all characteristics -%D of \type{\framed}. This time we used the setting: -%D -%D \typebuffer -%D -%D The implementation is not that sophisticated, but suffices. -%D The main problem with this kind of functionality is to get -%D the spacing all right. - -%D Specifying the background is more or less the same as -%D specifying a framed box. -%D -%D \showsetup{setupbackground} - -\presetlocalframed[\??ag] - -\def\dosetupbackground[#1]% - {\getparameters[\??ag][#1]% - \doifelse\@@agstate\v!start - {\let\startbackground\dostartbackground - \let\stopbackground \dostopbackground - \let\background \dobackground} - {\let\startbackground\relax - \let\stopbackground \relax - \let\background \relax}} - -\unexpanded\def\setupbackground - {\dosingleargument\dosetupbackground} - -%D Actually typesetting the background is implemented rather -%D straightforward. We need to handle some spacing as well as -%D the (often) a bit smaller horizontal size. -%D -%D \showsetup{startbackground} -%D -%D Although we could have used a scratch one, we first -%D declare a boolean. - -% 0=no-split, 1=no-split+indent, 2=split, 3=split+indent - -\setnewconstant\backgroundsplitmode\plusthree - -%D The \type{\vbox to \lineheight{}\vskip\zeropoint} -%D construction gives the first real line a decent height by -%D adding a dummy line. - -\def\dostartbackground - {\endgraf - \bgroup - \setbox0\vbox\bgroup - \vbox to \lineheight{}\vskip\zeropoint - \blank[\v!disable] - % \advance\hsize -\@@agleftoffset - % \advance\hsize -\@@agrightoffset - \leftskip \@@agleftoffset % new ** - \rightskip\@@agrightoffset} % new ** - -%D This dummy line is removed by \type{\setbox2=\vsplit0 to -%D \lineheight}. That way \type{\topskip} takes care of the -%D lineheight. I'll probably forget to apply this trick -%D elsewhere. - -\def\dostopbackground % improved version (i hope) - {\endgraf - \removelastskip - \egroup - \dimen2\leftskip % new ** - \forgetall - \ifinsidefloat - \backgroundsplitmode\zerocount - \fi - \ifcase\backgroundsplitmode - \localframed[\??ag][\c!offset=\v!overlay]{\box0}% - \or - \hskip\dimen2 - \localframed[\??ag][\c!offset=\v!overlay]{\box0}% - \else - \splitmaxdepth\boxmaxdepth - \splittopskip\topskip - \setbox2\vsplit0 to \lineheight % get rid of fake line - \loop - \ifdim\pagetotal=\zeropoint % empty page - \scratchdimen\textheight - \backgroundsplitmode\plusone % split to max height - \else - \setbox\scratchbox\vbox{\@@agbefore}% - \scratchdimen\dimexpr\pagegoal-\ht\scratchbox-\pagetotal\relax - \backgroundsplitmode\plustwo % split to partial height - \fi - \advance\scratchdimen\dimexpr-\@@agtopoffset-\@@agbottomoffset\relax - \ifdim\scratchdimen>2\lineheight\relax % reasonable, will be configurable - \ifdim\ht0>\scratchdimen % larger than page - \setbox2\vsplit0 to \scratchdimen - \else - \setbox2\box0 - \backgroundsplitmode\zerocount % no split - \fi - \setbox2\vbox \ifcase\backgroundsplitmode\or to \textheight \fi % max split - {\vskip\@@agtopoffset - \unvcopy2 - \prevdepth\dp2 - \obeydepth - \vskip\@@agbottomoffset - \vfill} - \@@agbefore - \ifcase\backgroundsplitmode\or\or % partial split - \ifdim\pagegoal<\maxdimen - \pagegoal=1.2\pagegoal % be a bit more tolerant - \fi - \fi - \startlinecorrection - %\localframed[\??ag][\c!offset=\v!overlay]{\hskip\@@agleftoffset\box2\hskip\@@agrightoffset}% - \ifnum\backgroundsplitmode=\plusthree \hskip\dimen2 \fi % - \localframed[\??ag][\c!offset=\v!overlay]{\box2}% new ** - \stoplinecorrection - \ifcase\backgroundsplitmode % no split - \@@agafter - \else % some split - \vfill\eject % geen \page ! - \fi - \else - \page - \fi - \ifdim\ht0>\zeropoint \repeat - \fi - \egroup - \endgraf} - -%D As a bonus we also have a short command, that is of not -%D much use, but kept there for historic reasons. -%D -%D \showsetup{background} - -\def\dobackground - {\bgroup - \dowithnextbox - {\localframed[\??ag][\c!offset=\v!overlay]{\flushnextbox}\egroup} - \vbox} - -%D \stopdocumentation -%D \stopbackground -%D \egroup - %D New, for the moment private; let's see when GB finds out %D about this one and its obscure usage. It's used in: %D @@ -3442,9 +2674,12 @@ %D %D \typebuffer -\def\framedcontentparameter #1{\csname\doframedcontentparameter{\??fc\@@framedcontent}#1\endcsname} +% to be redone + +\def\framedcontentparameter #1{\csname\doframedcontentparameter{\??fc\currentframedcontent}#1\endcsname} \def\doframedcontentparameter #1#2{\ifcsname#1#2\endcsname#1#2\else\expandafter\doframedcontentparentparameter\csname#1\s!parent\endcsname#2\fi} \def\doframedcontentparentparameter#1#2{\ifx#1\relax\s!empty\else\doframedcontentparameter#1#2\fi} +\def\letframedcontentparameter #1{\expandafter\let\csname\??fc\currentframedcontent#1\endcsname} \presetlocalframed[\??fc] @@ -3461,9 +2696,6 @@ %\c!width=\v!fit, \c!offset=\v!overlay] -\def\letframedcontentparameter#1% - {\letvalue{\??fc\@@framedcontent#1}} - \unexpanded\def\defineframedcontent {\dodoubleempty\dodefineframedcontent} @@ -3478,17 +2710,20 @@ \processcommacommand[#1]\docommand} \unexpanded\def\startframedcontent - {\dosingleempty\dostartframedcontent} + {\dosingleempty\pack_framed_start_content} -\def\dostartframedcontent[#1]% +\def\pack_framed_start_content[#1]% {\bgroup - \edef\@@framedcontent{#1}% - \let\stopframedcontent\egroup - \doifnot{#1}\v!off{\dodostartframedcontent{#1}}} + \edef\currentframedcontent{#1}% + \ifx\currentframedcontent\v!off + \let\stopframedcontent\egroup + \else + \let\stopframedcontent\pack_framed_stop_content_indeed + \expandafter\pack_framed_start_content_indeed + \fi} -\def\dodostartframedcontent#1% - {\unexpanded\def\stopframedcontent{\dostopframedcontent{#1}}% - \setbox\framebox\hbox\bgroup +\def\pack_framed_start_content_indeed + {\setbox\b_framed_normal\hbox\bgroup \setlocalhsize \hsize\localhsize \advance\hsize\dimexpr-\framedcontentparameter\c!leftoffset-\framedcontentparameter\c!rightoffset \relax @@ -3500,7 +2735,7 @@ \forgetall \blank[\v!disable]} -\def\dostopframedcontent#1% +\def\pack_framed_stop_content_indeed {\removelastskip \egroup \vskip\framedcontentparameter\c!bottomoffset @@ -3517,46 +2752,12 @@ % plaats ? \ifdone\startlinecorrection\fi \framedcontentparameter\c!left % new - \localframed[\??fc#1]{\box\framebox}% + \localframed[\??fc\currentframedcontent]{\box\b_framed_normal}% hm \framedcontentparameter\c!right % new \ifdone\stoplinecorrection\fi \egroup} -%D \macros -%D {backgroundline} -%D -%D For the moment an undocumented feature, but a cancidate -%D for going public. - -\def\backgroundline[#1]% - %{\doifsomething{#1}{\dobackgroundline{#1}}\hbox} - {\doifcolorelse{#1}{\dobackgroundline{#1}\hbox}\hbox} - -% \def\backgroundline[#1]% -% {\doifcolor{#1}{\dobackgroundline{#1}}\hbox} - -\def\dobackgroundline#1% - {\dowithnextbox - {\hbox - {\startcolor[#1]% - \vrule - \!!width \nextboxwd - \!!height\nextboxht - \!!depth \nextboxdp - \stopcolor - \hskip-\nextboxwd - \flushnextbox}}} - -%D \macros -%D {encircled} -%D -%D Some not so robust left||overs (borrowed from Knuth, -%D \TEX Book\ page 356): - -\def\encircled#1% - {{\ooalign{\hfil\raise0.07ex\hbox{{\tx#1}}\hfil\crcr\mathhexbox20D}}} - -\let\omcirkeld\encircled +% A shared setting. \setuplinewidth [\v!medium] @@ -3567,163 +2768,51 @@ \setupframed [\c!width=\v!fit, \c!height=\v!broad, - \c!lines=, + %\c!lines=, \c!offset=0.25ex, % \defaultframeoffset \c!empty=\v!no, \c!frame=\v!on, - \c!topframe=, - \c!bottomframe=, - \c!leftframe=, - \c!rightframe=, + %\c!topframe=, + %\c!bottomframe=, + %\c!leftframe=, + %\c!rightframe=, \c!radius=.5\bodyfontsize, \c!rulethickness=\linewidth, \c!corner=\v!rectangular, \c!depth=\zeropoint, - \c!foregroundcolor=, - \c!foregroundstyle=, - \c!background=, + %\c!foregroundcolor=, + %\c!foregroundstyle=, + %\c!background=, \c!backgroundscreen=\@@rsscreen, - \c!backgroundcolor=, + %\c!backgroundcolor=, \c!backgroundoffset=\zeropoint, - \c!framecolor=, + %\c!framecolor=, \c!frameoffset=\zeropoint, + % somewhat messy \c!backgroundcorner=\framedparameter\c!corner, \c!backgroundradius=\framedparameter\c!radius, \c!backgrounddepth=\framedparameter\c!depth, \c!framecorner=\framedparameter\c!corner, \c!frameradius=\framedparameter\c!radius, \c!framedepth=\framedparameter\c!depth, - \c!component=, - \c!align=, + % + %\c!component=, + %\c!region=, + %\c!align=, \c!bottom=\vss, - \c!top=, + %\c!top=, \c!autostrut=\v!yes, \c!location=\v!normal, - \c!orientation=, + %\c!orientation=, \c!autowidth=\v!yes, - \c!setups=, - \c!strut=\v!yes] + %\c!setups=, + \c!strut=\v!yes, + %\c!loffset=\zeropoint, + %\c!roffset=\zeropoint, + %\c!toffset=\zeropoint, + ]%\c!boffset=\zeropoint] \setupscreens - [%\c!factor=1.0, % obsolete - %\c!method=\v!external, % obsolete - \c!screen=0.95] - -\setupblackrules - [\c!n=3, - \c!width=1em, - \c!height=1ex, - \c!depth=\!!zeropoint, - \c!alternative=\c!a, - \c!distance=.25ex, - \c!color=] - -\setupmarginrules - [\c!level=0, - \c!rulethickness=\@@kadefaultwidth\linewidth] - -\setupthinrules - [\c!interlinespace=\v!small, - \c!n=3, - \c!before=, - \c!inbetween={\blank[\v!white]}, - \c!after=, - \c!color=, - \c!height=.5\linewidth, - \c!depth=.5\linewidth, - \c!frame=\v!on, % compatible with textbackgrounds - \c!alternative=\v!b, - \c!backgroundcolor=, - \c!background=, - \c!rulethickness=] - -\setuptextrules - [\c!location=\v!left, - \c!before=\blank, - \c!after=\blank, - \c!inbetween=, - \c!width=2em, - \c!style=\v!bold, - \c!color=, - \c!rulecolor=, - \c!bodyfont=, - \c!distance=.5em] - -\setupfillinrules - [\c!width=\v!broad, - \c!distance=1em, - \c!before=\blank, - \c!after=\blank, - \c!n=1, - \c!interlinespace=\v!small, - \c!separator=, - \c!style=\v!normal, - \c!color=] - -\setupfillinlines - [\c!width=3cm, - \c!margin=\@@ivwidth, - \c!distance=1em, - \c!before=\blank, - \c!after=\blank] - -\setupbackground - [\c!leftoffset=.5\bodyfontsize, - \c!rightoffset=\@@agleftoffset, - \c!topoffset=\!!zeropoint, - \c!bottomoffset=\@@agtopoffset, - \c!state=\v!start, - \c!radius=.5\bodyfontsize, - \c!corner=\v!rectangular, - \c!frame=\v!off, - \c!color=, - \c!depth=\!!zeropoint, - \c!background=\v!screen, - \c!backgroundcolor=\@@agcolor, - \c!screen=\@@rsscreen, - \c!before=, - \c!after=] - -% Experimental extension: - -\def\c!loffset{loffset} -\def\c!roffset{roffset} -\def\c!toffset{toffset} -\def\c!boffset{boffset} - -\getparameters - [\??oi] - [\c!loffset=\zeropoint, - \c!roffset=\zeropoint, - \c!toffset=\zeropoint, - \c!boffset=\zeropoint] - -\newdimen\!!framedloffset -\newdimen\!!framedroffset -\newdimen\!!framedtoffset -\newdimen\!!framedboffset - -\def\setextraframedoffsets - {\boxhasextraoffsetfalse - \!!framedloffset\framedparameter\c!loffset - \!!framedroffset\framedparameter\c!roffset - \!!framedtoffset\framedparameter\c!toffset - \!!framedboffset\framedparameter\c!boffset - \relax - \ifzeropt\!!framedloffset\else \advance\!!framedwidth -\!!framedloffset \boxhasextraoffsettrue \fi - \ifzeropt\!!framedroffset\else \advance\!!framedwidth -\!!framedroffset \boxhasextraoffsettrue \fi - \ifzeropt\!!framedtoffset\else \advance\!!framedheight-\!!framedtoffset \boxhasextraoffsettrue \fi - \ifzeropt\!!framedboffset\else \advance\!!framedheight-\!!framedboffset \boxhasextraoffsettrue \fi} - -\def\applyextraframedoffsets - {\setbox\framebox\vbox\bgroup - \vskip\!!framedtoffset - \hbox\bgroup - \hskip\!!framedloffset - \box\framebox - \hskip\!!framedroffset - \egroup - \vskip\!!framedboffset - \egroup} + [\c!screen=0.95] \protect \endinput |