summaryrefslogtreecommitdiff
path: root/tex/context/base/strc-flt.mkvi
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/strc-flt.mkvi')
-rw-r--r--tex/context/base/strc-flt.mkvi1912
1 files changed, 1912 insertions, 0 deletions
diff --git a/tex/context/base/strc-flt.mkvi b/tex/context/base/strc-flt.mkvi
new file mode 100644
index 000000000..c247e4941
--- /dev/null
+++ b/tex/context/base/strc-flt.mkvi
@@ -0,0 +1,1912 @@
+%D \module
+%D [ file=strc-flt,
+%D version=2008.10.20,
+%D title=\CONTEXT\ Structure Macros,
+%D subtitle=Float Numbering,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%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
+%C details.
+
+\writestatus{loading}{ConTeXt Structure Macros / Float Numbering}
+
+\registerctxluafile{strc-flt}{1.001}
+
+\unprotect
+
+%D This module is being converted into a mkvi one.
+%D
+%D - rename macros
+%D - get rid of dead code
+%D - less gobal mess
+%D - more mkiv-ish
+
+\installframedcommandhandler \??fl {float} \??fl
+\installframedcommandhandler \??kj {floatcaption} \??kj
+
+\let\setupfloats \setupfloat
+\let\setupcaption \setupfloatcaption
+\let\setupcaptions\setupfloatcaption
+
+\def\dohandlenextfloatindent
+ {\checknextindentation[\floatparameter\c!indentnext]%
+ \dorechecknextindentation}
+
+\setupcaptions
+ [\c!location=\v!bottom,
+ \c!grid=,
+ \c!before=, % not used (yet)
+ \c!inbetween={\blank[\v!medium]},
+ \c!after=, % not used (yet)
+ \c!spacebefore=,
+ \c!spaceinbetween=, % replaces fuzzy inbetween dual usage
+ \c!spaceafter=,
+ \c!width=\v!fit,
+ \c!minwidth=\v!fit, % id est: the width of the floatbox in some cases
+ \c!headstyle=\v!bold,
+ \c!headcolor=,
+ \c!leftmargin=\zeropoint,
+ \c!rightmargin=\zeropoint,
+ \c!outermargin=\zeropoint,
+ \c!innermargin=\zeropoint,
+ \c!setups=,
+ \c!style=\v!normal,
+ \c!color=,
+ \c!textstyle=,
+ \c!textcolor=,
+ \c!align=,
+ \c!number=\v!yes,
+ % \c!expansion=\v!no
+ % \c!prefix=\v!no,
+ % \c!prefixconnector=.,
+ % \c!way=\v!by\v!chapter,
+ % \c!prefixsegments=2:2,
+ % \c!way=\@@nrway,
+ % \c!blockway=\@@nrblockway,
+ % \c!sectionnumber=\@@nrsectionnumber,
+ % \c!separator=\@@koseparator,
+ % \c!starter=\@@kostarter,
+ % \c!stopper=\@@kostopper,
+ \c!suffixseparator=, % currently rather hard coded
+ \c!suffix=\floatcaptionsuffix,
+ \c!distance=1em,
+ \c!conversion=\v!numbers,
+ \c!command=]
+
+% we can comment some of these
+
+\setupfloats
+ [\c!location=\v!middle,
+ \c!width=8\lineheight,
+ \c!height=6\lineheight,
+ \c!offset=\v!overlay,
+ \c!frame=\v!off,
+ \c!strut=\v!no,
+ \c!radius=.5\bodyfontsize,
+ \c!corner=\v!rectangular,
+ %\c!background=,
+ %\c!backgroundcolor=,
+ \c!backgroundoffset=\!!zeropoint,
+ %\c!topframe=,
+ %\c!bottomframe=,
+ %\c!leftframe=,
+ %\c!rightframe=,
+ \c!frameoffset=\!!zeropoint,
+ %\c!before=,
+ %\c!after=,
+ \c!spacebefore=\v!big,
+ \c!spaceafter=\v!big,
+ \c!sidespacebefore=\rootfloatparameter\c!spacebefore,
+ \c!sidespaceafter=\rootfloatparameter\c!spaceafter,
+ \c!sidealign=\v!normal,
+ \c!textmethod=\ifgridsnapping2\else0\fi, % 0=raw 1=safe (.99pg) 2=tight (-1pt) % THIS WILL CHANGE
+ \c!sidemethod=\ifgridsnapping2\else1\fi, % 0=raw 1=safe (.99pg) 2=tight (-1pt) % THIS WILL CHANGE
+ \c!indentnext=\v!no,
+ \c!margin=1em,
+ \c!method=1,
+ \c!cache=\v!yes, % when no, then intermediate flush
+ \c!leftmargin=\zeropoint, % displacement in 'normal floats'
+ \c!rightmargin=\zeropoint, % idem
+ \c!innermargin=\zeropoint, % idem
+ \c!outermargin=\zeropoint, % idem
+ \c!leftmargindistance=\zeropoint,
+ \c!rightmargindistance=\floatparameter\c!leftmargindistance,
+ \c!ntop=2,
+ \c!nbottom=0,
+ \c!nlines=4,
+ %\c!local=,
+ %\c!bottombefore=, % e.g. \vfill
+ %\c!bottomafter=,
+ %\c!default=, % default location
+ \c!numbering=\v!yes]
+
+%D Individial settings:
+
+\presetstructurecountersetup\setupcaption\sharedstructurecounterparameter
+
+\appendtoks
+ \let\currentfloat\currentfloatcaption
+ \ifx\currentfloat\empty \else
+ \dostructurecountersetup\currentfloatcaption\floatcaptionparameter
+ \docheckstructurecountersetup\currentfloatcaption
+ \fi
+\to \everysetupfloatcaption
+
+%D Definitions:
+
+\let\saveddefinefloat\definefloat
+
+\unexpanded\def\definefloat
+ {\dotripleempty\dodefinefloat}
+
+\def\dodefinefloat[#1][#2][#3]% #1=naam #2=meervoud #3=parent
+ {\ifthirdargument
+ \redodefinefloat[#1][#2][#3]%
+ \else\ifsecondargument
+ \dododefinefloat[#1][#2]%
+ \else
+ \dododefinefloat[#1][#1]%
+ \fi\fi}
+
+\def\dododefinefloat[#1][#2]%
+ {\definefloatcaption[#1]%
+ \definestructurecounter[#1]%
+ \definelist[#1]%
+ \presetlabeltext[#1=\Word{#1}~]%
+ \presetheadtext[#2=\Word{#2}]%
+ \saveddefinefloat[#1]%
+ \dodefinefloatcommands[#1][#2]}
+
+\def\redodefinefloat[#1][#2][#3]%
+ {\definefloatcaption[#1][#3]%
+ \definestructurecounter[#1][#3]%
+ \definelist[#1][#3]%
+ \presetlabeltext[#1=\Word{#3}~]%
+ \presetheadtext[#2=\Word{#2}]%
+ \saveddefinefloat[#1][#3]%
+ \dodefinefloatcommands[#1][#2]}
+
+\def\dodefinefloatcommands[#1][#2]%
+ {\setuvalue {\e!place\e!listof#2}{\dodoubleempty\doplacelist[#1]}%
+ \setuvalue {\e!complete\e!listof#2}{\dotripleempty\dodocompletelist[#1][#2]}%
+ \setuevalue {\e!place#1}{\float_place{#1}}%
+ \setuevalue {\e!start\e!place#1}{\float_start_place{#1}}%
+ \setuevalue {\e!stop\e!place#1}{\float_stop_place}%
+ \setuevalue {\e!start#1\e!text}{\float_start_text{#1}}%
+ \setuevalue {\e!stop#1\e!text}{\float_stop_text}%
+ % these will become obsolete:
+ \setuevalue {\e!reserve#1}{\float_reserve{#1}}%
+ \setuevalue{\e!start\e!reserve#1\e!text}{\float_start_reserve_text{#1}}%
+ \setuevalue {\e!stop\e!reserve#1\e!text}{\float_stop_reserve_text}}
+
+%D Fallback float body:
+
+\unexpanded\def\float_place_empty_box % \inheritedfloatframed
+ {\framed
+ [\c!frame=\v!on,
+ \c!width=\rootfloatparameter\c!width,
+ \c!height=\rootfloatparameter\c!height,
+ \c!location=\v!normal,
+ \c!offset=\rootfloatparameter\c!offset]%
+ {\getmessage\m!floatblocks{12}\empty}}
+
+%D Data. We can generalize this to lists.
+
+\newif\ifnofloatcaption
+\newif\ifnofloatnumber
+\newif\ifemptyfloatcaption
+
+\installstructurelistprocessor{float}{\usestructurelistprocessor{number+title}}
+
+\unexpanded\def\thecurrentfloatnumbersuffix
+ {\doifsomething{\floatcaptionparameter\c!suffix}
+ {\floatcaptionparameter\c!suffixseparator
+ \floatcaptionparameter\c!suffix}}
+
+\unexpanded\def\thecurrentfloatnumber
+ {\ifnofloatcaption \else \ifnofloatnumber \else
+ \ifx\currentfloatnumber\relax\else
+ \namedtaggedlabeltexts
+ \t!floatlabel \currentfloat
+ \t!floatnumber\currentfloat
+ {\ctxlua{structures.lists.savedprefixednumber("\currentfloat",\currentfloatnumber)}%
+ \thecurrentfloatnumbersuffix}%
+ \fi
+ \fi \fi}
+
+\unexpanded\def\thecurrentfloatcaption
+ {\ifnofloatcaption \else
+ \ifx\currentfloatnumber\relax\else
+ \dostarttagged\t!floattext\empty
+ \ctxlua{structures.lists.savedtitle("\currentfloat",\currentfloatnumber)}%
+ \dostoptagged
+ \fi
+ \fi}
+
+%D Captions.
+
+\let\floatcaptionsuffix\empty % an optional suffix
+\let\floatcaptionnumber\empty % a logical counter
+
+% the split is needed when for instance the float goes into
+% a multi page field and the list of figs becomes larger than
+% one page: cycle between 'only flush when object ref ok'
+% and 'one/many page fig list'; see "uguide finometer"
+%
+% potential sync bug with sectionblocks, see uguide.tex
+
+% begin of todo
+
+\unexpanded\def\placefloatcaption{\dodoubleempty\doplacefloatcaption}
+\unexpanded\def\setfloatcaption {\dodoubleempty\dodosetfloatcaption}
+
+\def\doplacefloatcaption[#tag][#reference]#caption{[not supported]}
+\def\dodosetfloatcaption[#tag][#reference]#caption{[not supported]} % \dosetfloatcaption already in use
+
+\unexpanded\def\placefloatcaptiontext [#tag]{[not suported yet]}
+\unexpanded\def\placefloatcaptionnumber [#tag]{[not suported yet]}
+\unexpanded\def\placefloatcaptionreference[#tag]{[not suported yet]}
+
+\let\placefloatlabel \placefloatcaption
+\let\placefloatlabeltext \placefloatcaptiontext
+\let\placefloatlabelreference\placefloatcaptionreference
+
+% end of todo
+
+\newbox \float_caption_box
+\newdimen\float_caption_height
+\newdimen\float_caption_depth
+
+\newbox \float_content_box
+
+\def\float_make_complete_caption
+ {\doifsomething{\floatcaptionparameter\c!spacebefore}{\blank[\floatcaptionparameter\c!spacebefore]}%
+ \synchronizedisplaydirection % temp hack, till we have a proper model
+ \noindent
+ \gdef\lastcaptiontag{\strut\thecurrentfloatnumber}% was xdef ... needs checking
+ \begingroup
+ \dosetfloatcaptionattributes\c!style\c!color
+ \ifnofloatnumber
+ \else
+ \hbox{\dosetfloatcaptionattributes\c!headstyle\c!headcolor\strut\thecurrentfloatnumber}%
+ \ifnofloatcaption \else \ifemptyfloatcaption \else
+ \doifelsenothing{\floatcaptionparameter\c!spaceinbetween}
+ {\scratchskip\floatcaptionparameter\c!distance\relax
+ \dotfskip\scratchskip\emergencystretch.5\scratchskip}
+ {\blank[\floatcaptionparameter\c!spaceinbetween]}%
+ \fi \fi
+ \fi
+ \ifnofloatcaption
+ \global\float_caption_height\zeropoint
+ \global\float_caption_depth \zeropoint
+ \else
+ \dosetfloatcaptionattributes\c!textstyle\c!textcolor
+ \global\float_caption_height\strutheight
+ \global\float_caption_depth \strutdepth
+ \begstrut\thecurrentfloatcaption\endstrut\endgraf
+ \fi
+ \endgroup
+ \doifsomething{\floatcaptionparameter\c!spaceafter}{\blank[\floatcaptionparameter\c!spaceafter]}}
+
+% \newif\iftracecaptions
+%
+% \def\settracedcaptionbox
+% {\iftracecaptions\setbox\float_caption_box\ruledhbox{\box\float_caption_box}\fi}
+
+% \definefloat [figure-1] [figure]
+% \definefloat [figure-2] [figure]
+% \setupfloat [figure-1] [location=left,leftmargin=10mm]
+% \setupfloat [figure-2] [location=left,leftmargin=-5mm]
+% \setupcaption [figure-1] [align=flushleft]
+% \setupcaption [figure-2] [align=flushleft,leftmargin=15mm]
+%
+% \startsetups somefigure
+% \ifdim\wd\nextbox>\textwidth
+% \placefloat[figure-2][][]{}{\box\nextbox}
+% \else
+% \placefloat[figure-1][][]{}{\box\nextbox}
+% \fi
+% \stopsetups
+%
+% \unexpanded\def\setupswithbox[#1]{\dowithnextbox{\setups[#1]}\vbox}
+%
+% test \setupswithbox[somefigure]{\framed[width=3cm] {}} test
+% test \setupswithbox[somefigure]{\framed[width=\dimexpr\textwidth+3cm\relax]{}} test
+
+% temporary removed ... was not applied systematically
+%
+% \def\dosetcaptionthings
+% {\doprocesslocalsetups{\floatcaptionparameter\c!setups}\relax}
+
+\def\check_float_caption_content
+ {\ifnofloatcaption \else
+ \setbox\float_caption_box\hbox
+ {\settrialtypesetting
+ \notesenabledfalse
+ \float_make_complete_caption}%
+ % new, \placefigure{\xmlfirst{#1}{somecaption}}{} passes earlier empty check
+ % so here we misuse the scratch box; actually this means that the previous
+ % test can go away (some day, when i redo this module)
+ \ifdim\wd\float_caption_box=\zeropoint
+ \global\emptyfloatcaptiontrue
+ \ifnofloatnumber
+ \global\nofloatcaptiontrue
+ \fi
+ \else
+ \setbox\float_caption_box\hbox{\hskip\leftskip\box\float_caption_box}%
+ \fi
+ \fi}
+
+% the tricky part of getting float related two pass data is
+% that we should fetch is early but can only save it with
+% the composed float box; this determines the order: get it
+% before saving it
+
+\definetwopasslist{\s!float\s!data} \newcounter\noffloatdata
+
+\let\twopassfloatdata\realpageno % used for odd/even determination, can be combined with nodelocation
+
+\def\dosavefloatdata % \expanded ... will change in mkiv
+ {\doglobal\increment\noffloatdata
+ \lazysavetaggedtwopassdata{\s!float\s!data}{\noffloatdata}{\noffloatpages}{\noexpand\realfolio}}% later {}{}{}{} and \getfirst...
+
+\def\dogetfloatdata % precedes save !
+ {\doglobal\increment\noffloatpages
+ \findtwopassdata{\s!float\s!data}{\noffloatpages}%
+ \iftwopassdatafound
+ \globallet\twopassfloatdata\twopassdata
+ \else
+ \globallet\twopassfloatdata\realpageno % \realfolio
+ \fi}
+
+%D test case:
+%D
+%D \starttyping
+%D \setupfloat[figure][criterium=\marginwidth,fallback=bottom]
+%D \dorecurse{3}{
+%D \chapter{test}
+%D \placefigure[bottom]{1}{\framed{bottom}}
+%D test
+%D \placetable[bottom]{1}{\framed{table}}
+%D test
+%D \placetable{2}{\framed{table}}
+%D test
+%D \placefigure[left]{2}{\framed{left but way too wide}}
+%D \input tufte
+%D \placefigure[left]{3}{\framed{left but ok}}
+%D \input tufte }
+%D \stoptyping
+
+% A complication is that we may have to handle a pagebreak
+% first, which in turn may issue a (postponed) float.
+% Therefore we may not trust on variable assignments before
+% we're really dealing with the float. Some day I'll root out
+% the global settings.
+
+\def\float_set_current_tag#tag%
+ {\edef\currentfloat{#tag}%
+ \ifx\currentfloat\empty
+ \let\currentfloat\v!figure % a bit of a hack
+ \fi
+ \let\currentfloatcaption\currentfloat}
+
+% place
+
+\unexpanded\def\float_place#tag%
+ {\flushnotes
+ \flushsidefloats % here !
+ \float_begin_group
+ \float_set_current_tag{#tag}%
+ \dodoubleempty\float_place_indeed}
+
+\def\float_place_indeed[#location][#reference]#caption%
+ {\edef\floatlocation{#location}%
+ \ifx\floatlocation\empty
+ \edef\floatlocation{\floatparameter\c!default}% beware of a clash between alignment locations
+ \fi
+ \setupcurrentfloatcaption[\c!reference={#reference},\c!title={#caption},\c!marking=,\c!list=,\c!bookmark=]%
+ \doifinsetelse\v!split\floatlocation\place_next_float_box_split\place_next_float_box_normal}
+
+% start-stop
+
+\unexpanded\def\float_start_place#tag%
+ {\flushnotes
+ \flushsidefloats % here !
+ \float_begin_group
+ \float_set_current_tag{#tag}%
+ \dosingleempty\float_start_place_indeed}
+
+\def\float_start_place_indeed[#settings]% tricky ... saved not ok yet
+ {\edef\savedfloatlocation{\floatcaptionparameter\c!location}%
+ \setupcurrentfloatcaption[\c!location=,\c!reference=,\c!title=,\c!marking=,\c!list=,\c!bookmark=,#settings]%
+ \edef\floatlocation{\floatcaptionparameter\c!location}%
+ \setupcurrentfloatcaption[\c!location=\savedfloatlocation]%
+ \ifx\floatlocation\empty
+ \edef\floatlocation{\floatparameter\c!default}%
+ \fi
+ \doifinsetelse\v!split\floatlocation\place_next_float_box_split\place_next_float_box_normal
+ \bgroup
+ \ignorespaces}
+
+\unexpanded\def\float_stop_place
+ {\removeunwantedspaces
+ \egroup}
+
+% reserve
+
+\unexpanded\def\float_reserve#tag%
+ {\flushnotes
+ \flushsidefloats % here !
+ \float_begin_group
+ \float_set_current_tag{#tag}%
+ \dotripleempty\float_reserve_indeed}
+
+\def\float_reserve_indeed[#settings][#location][#reference]#caption% maybe check for #settings
+ {\float_place_indeed[#location][#reference]{#caption}{\float_reserve_box{#settings}}}
+
+\def\float_reserve_box#settings%
+ {\begingroup
+ \setupcurrentfloat[\c!frame=\v!on,#settings]%
+ \inheritedfloatframed{}%
+ \endgroup}
+
+% text
+
+\unexpanded\def\float_start_text#tag%
+ {\flushnotes % Here indeed?
+ \flushsidefloats % Here indeed?
+ \float_begin_text_group
+ \float_set_current_tag{#tag}%
+ \dodoubleempty\float_start_text_indeed}
+
+\def\float_start_text_indeed[#location][#reference]%
+ {\float_place_indeed[\v!text,#location,\v!left][#reference]}
+
+\unexpanded\def\float_stop_text
+ {\float_stop_text_indeed}
+
+% reserved text
+
+\unexpanded\def\float_start_reserve_text#tag%
+ {\flushnotes
+ \flushsidefloats
+ \float_begin_text_group
+ \float_set_current_tag{#tag}%
+ \dotripleempty\float_start_reserve_text_indeed}
+
+\def\float_start_reserve_text_indeed[#settings][#location][#reference]#caption%
+ {\float_place_indeed[\v!text,#location,\v!left][#reference]{#caption}{\float_reserve_box{#settings}}}
+
+\unexpanded\def\float_stop_reserve_text
+ {\float_stop_text_indeed}
+
+% special hack
+
+\def\float_begin_group {\begingroup}
+\def\float_end_group {\carryoverpar\endgroup}
+
+\def\float_begin_text_group {\begingroup\let\float_end_group\relax}
+\def\float_end_text_group {\endgroup}
+
+% implemenation
+
+\def\flushfloatslist
+ {\v!left,\v!right,\v!inner,\v!outer,%
+ \v!backspace,\v!cutspace,%
+ \v!inleft,\v!inright,\v!inmargin,%
+ \v!leftmargin,\v!rightmargin,\v!leftedge,\v!rightedge,%
+ \v!innermargin,\v!outermargin,\v!inneredge,\v!outeredge,%
+ \v!text,\v!opposite}% \v!page
+
+\unexpanded\def\place_next_float_box_split
+ {\splitfloat{\place_next_float_box_normal}}
+
+\unexpanded\def\place_next_float_box_normal
+ {\ifsomefloatwaiting
+ % this was \checkwaitingfloats spread all over
+ \doifinsetelse\v!always\floatlocation
+ {\showmessage\m!floatblocks5\empty}
+ {\doifcommonelse\floatlocation\flushfloatslist\doflushfloats\donothing}%
+ % but which should be done before using box \floatbox
+ \fi
+ \ifmarginblocks
+ \doifinset\v!margin\floatlocation\endgraf
+ \fi
+ \global\insidefloattrue
+ \dostarttagged\t!float\currentfloat
+ \ifmarginblocks
+ \doifinset\v!margin\floatlocation{\hsize\@@mbwidth}%
+ \fi
+ \the\everyinsidefloat
+ \float_analyze_variables_one
+ \dostarttagged\t!floatcontent\empty
+ \dowithnextboxcontent
+ {\float_set_local_hsize
+ \floatparameter\c!inner
+ \postponenotes} % new
+ {\dostoptagged
+ \float_finish_placement}
+ \vbox}
+
+\def\float_finish_placement
+ {\doifsomething{\floatparameter\c!criterium}
+ {\ifdim\wd\nextbox>\floatparameter\c!criterium\relax
+ \edef\forcedfloatmethod{\floatparameter\c!fallback}%
+ \ifx\forcedfloatmethod\empty\let\forcedfloatmethod\v!here\fi
+ \fi}%
+ \float_check_extra_actions
+ \float_analyze_variables_two
+ \float_place_packaged_boxes
+ % we need to carry over the par because of side floats
+ \global\sidefloatdownshift \zeropoint
+ \global\sidefloatextrashift\zeropoint
+ \ifparfloat
+ \doifinset\v!reset\floatlocation\forgetsidefloats
+ \doinhibitblank
+ \fi
+ \float_end_group}
+
+\setnewconstant\sidefloatalign \zerocount
+\setnewconstant\textfloatmethod\zerocount % 0=raw 1=safe (.99) 2=tight (-1pt)
+\setnewconstant\sidefloatmethod\plusone % 0=raw 1=safe (.99) 2=tight (-1pt)
+\setnewconstant\floatrotation \zerocount % 0 90 180 270
+
+\def\float_analyze_variables_two
+ {\doifcommonelse
+ {\floatlocation}
+ {\v!left,\v!right,\v!inner,\v!outer,%
+ \v!inleft,\v!inright,\v!inmargin,%
+ \v!backspace,\v!cutspace,%
+ \v!innermargin,\v!outermargin,\v!inneredge,\v!outeredge,%
+ \v!leftmargin,\v!leftedge,\v!rightmargin,\v!rightedge}
+ {\global\parfloattrue}
+ {\global\parfloatfalse}%
+ \ifinsidecolumns
+ \global\parfloatfalse
+ \fi
+ \global\sidefloatshift\zeropoint
+ \global\sidefloatmaximum\zeropoint
+ \global\sidefloatmethod\floatparameter\c!sidemethod
+ \global\textfloatmethod\floatparameter\c!textmethod
+ \global\sidefloatalign\zerocount
+ \global\floatrotation\zerocount
+ \float_calculate_skips
+ \ifparfloat
+ \processaction
+ [\floatparameter\c!sidealign]
+ [\v!height=>\global\sidefloatalign\plusone,%
+ \v!line=>\global\sidefloatalign\plustwo,% (***)
+ \v!depth=>\global\sidefloatalign\plusthree,%
+ \v!grid=>\global\sidefloatalign\plusfour,%
+ \v!halfline=>\global\sidefloatalign\plusfive]%
+ \ifcase\sidefloatalign\relax % todo: optie v!lokaal => \else
+ \doifinset\v!height \floatlocation{\global\sidefloatalign\plusone}%
+ \doifinset\v!line \floatlocation{\global\sidefloatalign\plustwo}%
+ \doifinset\v!depth \floatlocation{\global\sidefloatalign\plusthree}%
+ \doifinset\v!grid \floatlocation{\global\sidefloatalign\plusfour}%
+ \doifinset\v!halfline\floatlocation{\global\sidefloatalign\plusfive}% meant for 'none'
+ \fi
+ \doifinset\v!high\floatlocation{\global\sidefloattopskip \zeropoint}%
+ \doifinset\v!low \floatlocation{\global\sidefloatbottomskip\zeropoint}%
+ \doifinset\v!fit \floatlocation
+ {\global\sidefloattopskip \zeropoint
+ \global\sidefloatbottomskip\zeropoint
+ \global\floatsideskip \zeropoint}%
+ \else
+ \processallactionsinset
+ [\floatlocation]
+ [ 90=>\global\floatrotation\commalistelement\relax,%
+ 180=>\global\floatrotation\commalistelement\relax,%
+ 270=>\global\floatrotation\commalistelement\relax]%
+ \fi
+ \doifinsetelse\v!nonumber\floatlocation
+ {\global\nofloatnumbertrue}
+ {\doifelse{\floatcaptionparameter\c!number}\v!yes
+ {\global\nofloatnumberfalse}
+ {\global\nofloatnumbertrue}}%
+ \doifinsetelse\v!none\floatlocation
+ {\global\nofloatcaptiontrue}
+ {\global\nofloatcaptionfalse}%
+ \doif{\floatcaptionparameter\c!number}\v!none % new
+ {\global\nofloatcaptiontrue}%
+ \ifemptyfloatcaption \ifnofloatnumber
+ \global\nofloatcaptiontrue
+ \fi \fi}
+
+% documenteren in details
+
+\def\float_analyze_variables_one
+ {\doifelse{\floatparameter\c!local}\v!yes % fout keyword
+ \globalcenterfloatboxtrue
+ \globalcenterfloatboxfalse
+ \ifglobalcenterfloatbox
+ \localcenterfloatboxtrue
+ \else
+ \doifinsetelse\v!local\floatlocation
+ \localcenterfloatboxtrue
+ \localcenterfloatboxfalse
+ \fi
+ \doifnotcommon{\v!always,\v!here,\v!force}\floatlocation % ! ! ! ! ! !
+ {\globalcenterfloatboxfalse
+ \localcenterfloatboxfalse}}
+
+\let\naturalfloatheight\!!zeropoint
+\let\naturalfloatwidth \!!zeropoint
+\let\naturalfloatdepth \!!zeropoint
+
+\def\float_set_natural_dimensions#box%
+ {\xdef\naturalfloatheight{\the\ht#box}%
+ \xdef\naturalfloatwidth {\the\wd#box}%
+ \xdef\naturalfloatdepth {\the\dp#box}}
+
+\def\doifelsemainfloatbody
+ {\ifinsidesplitfloat
+ \ifconditional\splitfloatfirstdone
+ \doubleexpandafter\secondoftwoarguments
+ \else
+ \doubleexpandafter\firstoftwoarguments
+ \fi
+ \else
+ \expandafter\firstoftwoarguments
+ \fi}
+
+% todo: optional user pars
+
+\let\currentfloatattribute\empty % to be checked
+
+\def\floatcaptionattribute
+ {\iflocation
+ \ifnofloatnumber
+ \else
+ \ifnofloatcaption
+ \else
+ \ifinsidesplitfloat
+ \ifconditional\splitfloatfirstdone
+ \else
+ attr \destinationattribute \currentfloatattribute
+ \fi
+ \else
+ attr \destinationattribute \currentfloatattribute
+ \fi
+ \fi
+ \fi
+ \fi}
+
+\newconditional\usesamefloatnumber
+
+\def\float_place_packaged_boxes
+ {\bgroup
+ \ifconditional\usesamefloatnumber
+ \globallet\currentfloatnumber \previousfloatnumber
+ \globallet\currentfloatattribute \empty
+ \globallet\currentfloatsynchronize\relax
+ \else
+ \dostructurecountercomponent
+ {float}%
+ \setupcurrentfloatcaption
+ \floatcaptionparameter
+ \detokenizedfloatcaptionparameter
+ \relax
+ \relax
+ \relax
+ [\c!name=\currentfloat,%
+ \s!counter=\@@thestructurecounter\currentfloat,%
+ \s!hascaption=\ifnofloatcaption \v!no\else\v!yes\fi,%
+ \s!hasnumber=\ifnofloatnumber \v!no\else\v!yes\fi,%
+ \s!hastitle=\ifemptyfloatcaption\v!no\else\v!yes\fi]%
+ []%
+ \globallet\previousfloatnumber \laststructurecounternumber
+ \globallet\currentfloatnumber \laststructurecounternumber
+ \globallet\currentfloatattribute \laststructurecounterattribute
+ \globallet\currentfloatsynchronize\laststructurecountersynchronize
+ \fi
+ %
+ \global\setfalse\usesamefloatnumber % one shot
+ % check float box
+ \float_set_natural_dimensions\nextbox
+ \global\setbox\floatbox\vbox{\floatparameter\c!command{\box\nextbox}}%
+ \float_set_natural_dimensions\floatbox
+ \ifdim\htdp\floatbox=\zeropoint
+ \showmessage\m!floatblocks{11}\empty
+ \global\setbox\floatbox\vbox{\float_place_empty_box}%
+ \fi
+ % deal with lack of caption
+ \global\setbox\floatbox\vbox \floatcaptionattribute
+ {\doifelsemainfloatbody\currentfloatsynchronize\donothing
+ \unvbox\floatbox
+ \ifnofloatcaption
+ \vss
+ \fi}% gets rid of the depth (unless tabulate)
+ \egroup
+ % place the float
+ \float_set_box
+ \float_get_box
+ \global\insidefloatfalse}
+
+\def\float_set_local_hsize
+ {\iflocalcenterfloatbox
+ \seteffectivehsize
+ \hsize\localhsize
+ \fi}
+
+\ifdefined\everyinsidefloat \else \newevery \everyinsidefloat \relax \fi
+
+\appendtoks
+ \everyinsidefloat\emptytoks % in case it's called earlier
+ \dogetfloatdata
+\to \everyinsidefloat
+
+\def\doifrightpagefloatelse
+ {\ifdoublesided
+ \ifsinglesided
+ \doubleexpandafter\firstoftwoarguments
+ \else
+ \doubleexpandafter\doifoddfloatpageelse
+ \fi
+ \else
+ \expandafter\firstoftwoarguments
+ \fi}
+
+\def\doifoddfloatpageelse
+ {\ifodd\purenumber\twopassfloatdata\space
+ \expandafter\firstoftwoarguments
+ \else
+ \expandafter\secondoftwoarguments
+ \fi}
+
+\appendtoks
+ \let\rightorleftpageaction\doifrightpagefloatelse
+\to \everyinsidefloat
+
+% \let\movesidefloat\gobbleoneargument
+
+% new : \place...[leftmargin,-2*line]; we need to catch fxtb:2*3
+% watch out: line alone aligns on the line ! ! !
+
+\unexpanded\def\movesidefloat[#settings]% (-)n*line|x=,y=
+ {\global\sidefloatdownshift \zeropoint
+ \global\sidefloatextrashift\zeropoint
+ \doifassignmentelse{#settings}%
+ {\bgroup
+ \getparameters[\??fl\??fl][\c!x=\zeropoint,\c!y=\zeropoint,#settings]%
+ \ifgridsnapping
+ \getnoflines\@@fly
+ \global\sidefloatdownshift\noflines\lineheight
+ \else
+ \global\sidefloatdownshift\@@fl@@fly
+ \fi
+ \global\sidefloatextrashift\@@fl@@flx
+ \egroup}
+ {\movedownsidefloat[#settings]}}
+
+\def\float_move_down#setting%
+ {\processaction
+ [#setting]%
+ [ \v!line=>\float_move_down_line+,%
+ +\v!line=>\float_move_down_line+,%
+ -\v!line=>\float_move_down_line-,%
+ \v!hang=>\float_move_down_hang\plusone,%
+ +\v!hang=>\float_move_down_hang\plusone,%
+ -\v!hang=>\float_move_down_hang\minusone]}
+
+\def\float_move_down_line#sign%
+ {\if!!donea\else\global\sidefloatdownshift\zeropoint\!!doneatrue\fi
+ \global\advance\sidefloatdownshift#sign\lineheight}
+
+\def\float_move_down_hang#lines%
+ {\if!!doneb\else\global\sidefloatsidelines\zerocount\!!donebtrue\fi
+ \global\advance\sidefloatsidelines#lines\relax}
+
+\unexpanded\def\movedownsidefloat[#settings]% already in core
+ {\doifnotinstring{:}{#settings}
+ {\begingroup
+ \!!doneafalse
+ \!!donebfalse
+ \normalexpanded{\dorepeatwithcommand[#settings]}\float_move_down
+ \endgroup}}
+
+\unexpanded\def\hangsidefloat[#number]%
+ {\global\sidefloatsidelines#number\relax}
+
+\def\set_extra_float_action#rightpagelocation#leftpagelocation%
+ {\rightorleftpageaction
+ {\let\extrafloatlocation#rightpagelocation}%
+ {\let\extrafloatlocation#leftpagelocation}}
+
+\def\float_check_extra_actions
+ {\doifnotinset\v!text\floatlocation % fuzzy, text overloads left, since then it's a directive
+ {\let\extrafloatlocation\empty
+ % \sidefloatdownshift will be reset afterwards, and can
+ % already be set at this point
+ \processallactionsinset
+ [\floatlocation] % ininner/inouter : for old times sake
+ [ \v!inner=>\set_extra_float_action\v!left \v!right,
+ \v!outer=>\set_extra_float_action\v!right \v!left,
+ \v!innermargin=>\set_extra_float_action\v!leftmargin \v!rightmargin,
+ \v!outermargin=>\set_extra_float_action\v!rightmargin\v!leftmargin,
+ \v!inneredge=>\set_extra_float_action\v!leftedge \v!rightedge,
+ \v!outeredge=>\set_extra_float_action\v!rightedge \v!leftedge,
+ \v!backspace=>\set_extra_float_action\v!backspace \v!cutspace,
+ \v!cutspace=>\set_extra_float_action\v!cutspace \v!backspace,
+ % \v!margin=>\set_extra_float_action\v!cutspace \v!backspace,
+ \v!left=>\set_extra_float_action\v!left \v!left,
+ \v!right=>\set_extra_float_action\v!right \v!right,
+ \v!line=>, % only -n*line is handled (see ***)
+ \s!unknown=>{\movedownsidefloat[\commalistelement]}]%
+ \ifx\extrafloatlocation\empty \else
+ \edef\floatlocation{\extrafloatlocation,\floatlocation}%
+ \fi}}
+
+% pas op, maxbreedte niet instellen als plaats=links/rechts
+
+\def\float_set_local_dimensions
+ {\global\sidefloatshift \zeropoint % duplicate
+ \global\sidefloatmaximum\zeropoint\relax % duplicate
+ \ifdim\sidefloatdownshift=\zeropoint\else
+ \global\setbox\floatbox\vbox
+ {\vskip\sidefloatdownshift\nointerlineskip\box\floatbox}%
+ \fi
+ \doifsomething{\floatparameter\c!minwidth}
+ {\scratchdimen\floatparameter\c!minwidth\relax
+ \ifdim\wd\floatbox<\scratchdimen
+ \global\setbox\floatbox\hbox to \scratchdimen
+ {\doifnot{\floatparameter\c!location}\v!left \hss
+ \box\floatbox
+ \doifnot{\floatparameter\c!location}\v!right\hss}%
+ \fi}%
+ \doifinset\v!hanging\floatlocation
+ {\doifcommonelse{\v!inleft,\v!leftmargin}\floatlocation
+ {\letfloatparameter\c!maxwidth\leftmarginwidth}%
+ {\doifcommon{\v!inright,\v!rightmargin}\floatlocation
+ {\letfloatparameter\c!maxwidth\rightmarginwidth}}}%
+ \doifsomething{\floatparameter\c!maxwidth}
+ {\scratchdimen\floatparameter\c!maxwidth\relax
+ \ifdim\wd\floatbox>\scratchdimen
+ \doifcommonelse{\v!inright,\v!rightmargin,\v!rightedge,\v!inleft,\v!leftmargin,\v!leftedge}\floatlocation
+ {\global\sidefloatmaximum\scratchdimen}
+ {\global\setbox\floatbox\hbox to \scratchdimen
+ {\doifcommonelse{\v!right,\v!left}\floatlocation
+ {\doifnotinset\v!right\floatlocation\hss
+ \box\floatbox
+ \doifnotinset\v!left\floatlocation\hss}%
+ {\doifnot{\floatparameter\c!location}\v!left\hss
+ \box\floatbox
+ \doifnot{\floatparameter\c!location}\v!right\hss}}}%
+ \fi}}
+
+\unexpanded\def\placefloat
+ {\dotripleempty\docomplexplacefloat}
+
+\unexpanded\def\placefloats
+ {\doflushfloats}
+
+\installinsertion\topins
+\installinsertion\botins
+
+\newdimen\botinserted
+\newdimen\topinserted
+
+\newif\iftopofinsert
+\newif\iftestfloatbox
+
+\newdimen\floatsideskip \floatsideskip 12pt
+\newdimen\floattopskip \floattopskip \floattopskip
+\newdimen\floatbottomskip \floatbottomskip \floattopskip
+
+\newdimen\sidefloattopskip \sidefloattopskip \floattopskip
+\newdimen\sidefloatbottomskip \sidefloatbottomskip\floatbottomskip
+
+\newskip\sidefloatdownshift
+\newskip\sidefloatleftshift
+\newskip\sidefloatrightshift
+
+\def\sidefloattopoffset {\openstrutdepth} % {\strutdp}
+
+\newcount\noftopfloats \noftopfloats=2
+\newcount\nofbotfloats \nofbotfloats=0
+
+\def\float_calculate_skip#target#skip%
+ {\edef\askedfloatskip{#skip}%
+ \ifx\askedfloatskip\empty
+ \global#target\zeropoint
+ \else\ifx\askedfloatskip\v!none
+ \global#target\zeropoint
+ \else
+ \setbox\scratchbox\vbox{\whitespace\blank[\askedfloatskip]}% todo: move whitespace inside blank
+ \global#target\ht\scratchbox
+ \fi\fi}
+
+\def\float_calculate_skips
+ {\begingroup
+ \float_calculate_skip\floattopskip {\rootfloatparameter\c!spacebefore}%
+ \float_calculate_skip\floatbottomskip {\rootfloatparameter\c!spaceafter}%
+ \float_calculate_skip\sidefloattopskip {\rootfloatparameter\c!sidespacebefore}%
+ \float_calculate_skip\sidefloatbottomskip{\rootfloatparameter\c!sidespaceafter}%
+ \gdef \sidefloattopoffset {\openstrutdepth}% was \def
+ \global\floatsideskip \rootfloatparameter\c!margin
+ \global\sidefloatleftshift \floatparameter\c!leftmargindistance
+ \global\sidefloatrightshift\floatparameter\c!rightmargindistance
+ \global\noftopfloats \rootfloatparameter\c!ntop\relax
+ \global\nofbotfloats \rootfloatparameter\c!nbottom\relax
+ \endgroup}
+
+% beter de laatste skip buiten de \insert uitvoeren,
+% bovendien bij volle flush onder baseline.
+
+% \def\betweenfloatblanko% assumes that spaceafter is present
+% {\bgroup
+% \setbox0\vbox{\strut\blank[\rootfloatparameter\c!spacebefore]\strut}%
+% \setbox2\vbox{\strut\blank[\rootfloatparameter\c!spaceafter]\strut}%
+% \ifdim\ht0>\ht2
+% \blank[-\rootfloatparameter\c!spaceafter,\rootfloatparameter\c!spacebefore]%
+% \fi
+% \egroup}
+
+\unexpanded\def\betweenfloatblanko% assumes that spaceafter is present
+ {\blank[\rootfloatparameter\c!spacebefore]} % or v!back,....
+
+\def\doplacefloatbox % used elsewhere
+ {%\forgetall % NO
+ \whitespace
+ \blank[\rootfloatparameter\c!spacebefore]
+ \flushfloatbox
+ \blank[\rootfloatparameter\c!spaceafter]}
+
+%
+
+\ifdefined\someherefloat\else \let\someherefloat\doplacefloatbox \fi
+\ifdefined\someslotfloat\else \let\someslotfloat\doplacefloatbox \fi
+\ifdefined\somefixdfloat\else \let\somefixdfloat\doplacefloatbox \fi
+\ifdefined\sometopsfloat\else \let\sometopsfloat\doplacefloatbox \fi
+\ifdefined\somebotsfloat\else \let\somebotsfloat\doplacefloatbox \fi
+\ifdefined\somesidefloat\else \let\somesidefloat\doplacefloatbox \fi
+
+% test case:
+%
+% \placefigure[page,none]{}{\blackrule[width=\textwidth,height=0.9\textheight,color=green]}
+% \placefigure[page,none]{}{\blackrule[width=\textwidth,height=1.0\textheight,color=green]}
+% \placefigure[page,none]{}{\blackrule[width=\textwidth,height=1.1\textheight,color=green]}
+
+% the [#1] will go away
+
+\def\sometextfloat[#1]%
+ {%\checkwaitingfloats{#1}%
+ % todo: check if #1 is indeed \floatlocation or maybe more
+ \global\floattextwidth\hsize
+ \global\floatwidth\wd\floatbox
+ \global\floatheight\ht\floatbox % forget about the depth
+ \global\advance\floattextwidth -\floatwidth
+ \global\advance\floattextwidth -\rootfloatparameter\c!margin\relax % was \tfskipsize
+ \edef\floatlocation{#1}% to be sure
+ \doifinsetelse\v!tall{#1}
+ {\floattextheight\pagegoal
+ \advance\floattextheight -\pagetotal
+ \advance\floattextheight -\bigskipamount % lelijk
+ \ifdim\floattextheight>\textheight
+ \floattextheight\textheight
+ \fi
+ \boxmaxdepth\zeropoint \relax % toegevoegd
+ \ifdim\floattextheight<\floatheight
+ \floattextheight\floatheight
+ \fi
+ \setbox\floattext\vbox to \floattextheight}
+ {\setbox\floattext\vbox}%
+ \bgroup
+ \forgetall
+ \setupblank
+ \setupwhitespace % new, also needed for footnotes
+ \blank[\v!disable]
+ \hsize\floattextwidth
+ \ignorespaces}
+
+\def\float_stop_text_indeed
+ {\egroup
+ \doifnotinset\v!tall\floatlocation
+ {\ifdim\ht\floattext<\floatheight
+ \floattextheight\floatheight
+ \else
+ \floattextheight\ht\floattext
+ \fi}%
+ \setbox\floatbox\vbox to \floattextheight
+ {\hsize\floatwidth
+ \doifinsetelse\v!both\floatlocation
+ {\doifinsetelse\v!low\floatlocation
+ {\vfill\box\floatbox}
+ {\doifinsetelse\v!middle\floatlocation
+ {\vfill\box\floatbox\vfill}
+ {\box\floatbox\vfill}}}
+ {\box\floatbox\vfill}}%
+ \setbox\floattext\vbox to \floattextheight
+ {\hsize\floattextwidth
+ \doifinsetelse\v!low\floatlocation
+ {\vfill
+ \box\floattext
+ \doifinset\c!offset\floatlocation{\whitespace\blank}}
+ {\doifinsetelse\v!middle\floatlocation
+ {\vfill
+ \box\floattext
+ \vfill}
+ {\doifinset\v!offset\floatlocation{\whitespace\blank}%
+ \box\floattext
+ \vfill}}}%
+ \doifinsetelse\v!right\floatlocation
+ {\setbox\floatbox\hbox to \hsize
+ {\box\floattext
+ \hfill
+ \box\floatbox}}
+ {\setbox\floatbox\hbox to \hsize
+ {\box\floatbox
+ \hfill
+ \box\floattext}}%
+ \baselinecorrection
+ \whitespace
+ \blank[\rootfloatparameter\c!spacebefore]%
+ \doifnotinset\v!tall\floatlocation
+ {\dp\floatbox\openstrutdepth}% dp\strutbox}% % toegevoegd
+ \box\floatbox
+ \dostoptagged
+ \blank[\rootfloatparameter\c!spaceafter]%
+ \float_end_text_group
+ \doinsertfloatinfo}
+
+\def\somefacefloat[#1]% links, rechts, midden, hoog, midden, laag
+ {%\checkwaitingfloats{#1}%
+ \startopposite\box\floatbox\stopopposite
+ \doinsertfloatinfo}
+
+\def\someelsefloat[#1]%
+ {\doifinsetelse\v!here{#1}
+ {\doifinsetelse\v!always{#1}
+ {\page[\v!preference]%
+ \docheckiffloatfits
+ \ifroomforfloat
+ \placesomeherefloat[#1]%
+ \else
+ \showmessage\m!floatblocks9\empty
+ \doreversesavefloat
+ \fi}
+ {\ifsomefloatwaiting
+ \dosavefloat
+ \else
+ \page[\v!preference]%
+ \docheckiffloatfits
+ \ifroomforfloat
+ \placesomeherefloat[#1]%
+ \else
+ \dosavefloat
+ \fi
+ \fi}}
+ {\doifinsetelse\v!always{#1}
+ {\docheckiffloatfits
+ \ifroomforfloat
+ \sometopbottomfloat[#1]
+ \else
+ \showmessage\m!floatblocks9\empty
+ \doreversesavefloat
+ \fi}
+ {\docheckiffloatfits
+ \ifroomforfloat
+ \sometopbottomfloat[#1]
+ \else
+ \dosavefloat
+ \fi}}}
+
+\def\floatautofactor{.5}
+
+\def\sometopbottomfloat[#1]%
+ {\doifelse\floatmethod\v!auto
+ {\ifdim\pagetotal<\floatautofactor\pagegoal % when empty page, maxdimen
+ \placesometopsfloat[#1]%
+ \else
+ \placesomebotsfloat[#1]%
+ \fi}
+ {\doifelse\floatmethod\v!top
+ {\placesometopsfloat[#1]}
+ {\doifelse\floatmethod\v!bottom
+ {\placesomebotsfloat[#1]}
+ {\placesomeherefloat[#1]}}}}
+
+\def\borderedfloatbox
+ {\begingroup
+ \setupcurrentfloat[\c!location=\v!normal,\c!width=\v!fit,\c!height=\v!fit]%
+ \inheritedfloatframed{\box\floatbox}%
+ \endgroup}
+
+% minwidth=fit,width=max : no overshoot, as wide as graphic
+
+\ifdefined\moveboxontogrid\else \let\movecaptionontogrid\gobblethreearguments \fi
+
+\def\float_align_content_indeed
+ {\alignstrutmode\zerocount
+ \doifnotcommon{\floatcaptionparameter\c!location}{\v!outermargin,\v!innermargin,\v!leftmargin,\v!rightmargin}
+ {\shiftalignedline
+ {\floatparameter\c!leftmargin }{\floatparameter\c!rightmargin}%
+ {\floatparameter\c!innermargin}{\floatparameter\c!outermargin}}%
+ \alignedline{\floatparameter\c!location}\v!middle}
+
+\def\float_align_caption_indeed
+ {\alignstrutmode\zerocount
+ \shiftalignedline
+ {\floatcaptionparameter\c!leftmargin }{\floatcaptionparameter\c!rightmargin}%
+ {\floatcaptionparameter\c!innermargin}{\floatcaptionparameter\c!outermargin}%
+ \alignedline{\floatparameter\c!location}\v!middle}
+
+\def\float_set_page_variant
+ {\bgroup
+ \float_set_local_hsize
+ \ifcase\floatrotation\else
+ \swapdimens\hsize\vsize
+ \fi
+ \forgetall
+ \postponenotes
+ \dontcomplain
+ \setbox\float_content_box\vbox{\borderedfloatbox}%
+ \let\float_align_content \float_align_content_indeed
+ \let\float_align_caption\float_align_caption_indeed
+ \check_float_caption_content
+ \ifcase\floatparameter\c!method
+ \or % automatic
+ \ifnofloatcaption
+ \prepare_no_float_caption
+ \doglobal\addlocalbackgroundtobox\floatbox
+ \else
+ % todo: installable maken, variant/method=auto vs macro
+ \prepare_page_float_caption
+ \addlocalbackgroundtobox\float_content_box
+ \setbox\float_caption_box\hbox
+ {\floatcaptionparameter\c!command{\box\float_caption_box}}%
+ \moveboxontogrid\float_caption_box{\floatcaptionparameter\c!grid}\float_caption_height
+ \addlocalbackgroundtobox\float_caption_box
+ \build_float_box
+ \fi
+ \or % semi automatic
+ \or % manual
+ \fi
+ \ifcase\floatrotation
+ % weird, gone: \postcenterfloatbox\width
+ \else
+ \global\setbox\floatbox\vbox
+ {\rotate[\c!rotation=\number\floatrotation]{\box\floatbox}}%
+ \fi
+ \egroup}
+
+\def\captionminwidth {15\bodyfontsize}
+\def\captionovershoot {2em}
+
+\def\prepare_no_float_caption
+ {\global\setbox\floatbox\vbox % pas op als wd groter dan hsize
+ {\ifinsidecolumns\ifdim\wd\float_content_box>\hsize
+ \let\float_align_content\relax
+ \fi\fi
+ \float_align_content{\copy\float_content_box}}}
+
+\def\prepare_page_float_caption
+ {\dostarttagged\t!floatcaption\empty
+ \doifinsetelse{\floatcaptionparameter\c!location}{\v!top,\v!bottom}
+ {\doifinsetelse{\floatcaptionparameter\c!width}{\v!fit,\v!max}
+ {\doifelse{\floatcaptionparameter\c!minwidth}\v!fit
+ {\doifelse{\floatcaptionparameter\c!width}\v!max
+ {\dopreparestackcaptionmax}
+ {\ifdim\wd\float_caption_box>\wd\float_content_box % wider caption
+ \doifelse{\floatcaptionparameter\c!width}\v!fit
+ {\dopreparestackcaptionaut}
+ {\dopreparestackcaptionwid}%
+ \else
+ \dopreparestackcaptionmin
+ \fi}}
+ {\dopreparestackcaptionfix}}%
+ {\dopreparesidewidthcaption}}% new, special effects (see icare)
+ {\doifinsetelse{\floatcaptionparameter\c!width}{\v!fit,\v!max}
+ {\dopreparesideautocaption}
+ {\dopreparesidewidthcaption}}%
+ \dostoptagged}
+
+\def\dosettempcaptionbox
+ {\setbox\float_caption_box\vbox\bgroup
+ %expanded{\setupalign[\v!new,\v!reset,\floatcaptionparameter\c!align,\v!old]}% wrong! see icare
+ \normalexpanded{\noexpand\setupalign[\v!reset,\floatcaptionparameter\c!align]}% i need to check what reset does
+ \let\next}
+
+\def\dopreparesideautocaption
+ {\scratchdimen\dimexpr\hsize-\wd\float_content_box-\floatparameter\c!margin\relax % was \tfskipsize\relax
+ \ifdim\wd\float_caption_box>\scratchdimen
+ \ifdim\wd\float_caption_box<1.3\scratchdimen
+ \scratchdimen0.8\scratchdimen
+ \fi
+ \fi
+ \dosettempcaptionbox
+ {\hsize\scratchdimen
+ \float_make_complete_caption}}
+
+\def\dopreparesidewidthcaption
+ {\dosettempcaptionbox
+ {\hsize\floatcaptionparameter\c!width
+ \float_make_complete_caption}}
+
+\def\dopreparestackcaptionfix
+ {\dosettempcaptionbox
+ {\hsize\floatcaptionparameter\c!minwidth % special effects
+ \float_make_complete_caption}}
+
+\def\dopreparestackcaptionmax
+ {\dosettempcaptionbox
+ {\hsize\wd\float_content_box
+ \float_make_complete_caption}}
+
+\def\dopreparestackcaptionwid
+ {\dosettempcaptionbox
+ {\hsize\floatcaptionparameter\c!width
+ \float_make_complete_caption}}
+
+\def\dopreparestackcaptionmin
+ {\dosettempcaptionbox
+ {\hsize\wd\float_content_box
+ \doifnothing{\floatcaptionparameter\c!align}\raggedcenter % on purpose overloads align !
+ \float_make_complete_caption}}
+
+\def\dopreparestackcaptionaut
+ {\doifsomething{\floatcaptionparameter\c!align}
+ {\doifnotinset\v!middle{\floatcaptionparameter\c!align}%
+ {\let\captionovershoot\!!zeropoint}}%
+ \edef\captionhsize{\the\wd\float_content_box}%
+ \ifdim\captionhsize>\hsize
+ % float is wider than \hsize
+ \dosettempcaptionbox
+ {\settrialtypesetting
+ \hsize\captionhsize
+ \notesenabledfalse
+ \float_make_complete_caption}%
+ \ifdim\ht\scratchbox>\lineheight % more lines
+ \dosettempcaptionbox
+ {\hsize\captionhsize
+ \advance\hsize -\captionovershoot\relax
+ \ifdim\hsize<\captionminwidth\relax
+ \hsize\captionhsize
+ \fi
+ \float_make_complete_caption}%
+ \else
+ \dosettempcaptionbox
+ {\hsize\captionhsize
+ \float_make_complete_caption}%
+ \fi
+ \else
+ % float is smaller of equal to \hsize
+ \ifdim\captionhsize<\captionminwidth\relax
+ \scratchdimen\captionminwidth % float smaller than min width
+ \edef\captionhsize{\the\scratchdimen}%
+ \fi
+ \setbox\scratchbox\vbox % test with overshoot
+ {\settrialtypesetting
+ \scratchdimen\captionhsize
+ \advance\scratchdimen \captionovershoot
+ \advance\scratchdimen 3em % an average word length
+ \ifdim\scratchdimen<\hsize \hsize\scratchdimen \fi
+ \notesenabledfalse
+ \float_make_complete_caption}%
+ \ifdim\ht\scratchbox>\lineheight
+ % at least an average word longer than a line
+ \dosettempcaptionbox
+ {\scratchdimen\captionhsize
+ \advance\scratchdimen \captionovershoot
+ \ifdim\scratchdimen<\hsize \hsize\scratchdimen \fi
+ \float_make_complete_caption}%
+ \else
+ % just over a line, don't use an overshoot % % % todo: outer/inner and such
+ \doifcommonelse{\floatcaptionparameter\c!align}{\v!left,\v!right,\v!flushleft,\v!flushright}
+ {\dosettempcaptionbox
+ {\hsize\captionhsize
+ % strange : \raggedcenter
+ \float_make_complete_caption}}
+ {% nicer
+ \dosettempcaptionbox
+ {\hsize\captionhsize
+ \doifnothing{\floatcaptionparameter\c!align}\raggedcenter% overloads
+ \float_make_complete_caption}}%
+ \fi
+ \fi}
+
+\newdimen\tempfloatheight
+\newdimen\tempfloatwidth
+
+\def\dofloatboxbetweenstack
+ {\endgraf\nointerlineskip\floatcaptionparameter\c!inbetween\endgraf}
+
+\def\dofloatboxdefaultbuilder % done
+ {\float_align_content{\box\float_content_box}}
+
+\def\dofloatboxnextrightbuilder#1%
+ {\ifparfloat \hbox \else \expandafter \float_align_content \fi
+ {\tempfloatheight\ht\float_content_box
+ \box\float_content_box
+ \normalexpanded{\noexpand\doifnotinset{\v!hang}{\floatcaptionparameter\c!location}}{\dotfskip{\floatcaptionparameter\c!distance}}%
+ \vbox to\tempfloatheight{#1}}}
+
+\def\dofloatboxnextleftbuilder#1%
+ {\ifparfloat \hbox \else \expandafter \float_align_content \fi
+ {\tempfloatheight\ht\float_content_box
+ \vbox to\tempfloatheight{#1}%
+ \normalexpanded{\noexpand\doifnotinset{\v!hang}{\floatcaptionparameter\c!location}}{\dotfskip{\floatcaptionparameter\c!distance}}%
+ \box\float_content_box}}
+
+\def\dofloatboxnextouterbuilder
+ {\doifrightpagefloatelse\dofloatboxnextrightbuilder\dofloatboxnextleftbuilder}
+
+\def\dofloatboxnextinnerbuilder
+ {\doifrightpagefloatelse\dofloatboxnextleftbuilder\dofloatboxnextrightbuilder}
+
+\def\dofloatboxnextrighthangbuilder#1%
+ {\ifparfloat \hbox \else \expandafter \float_align_content \fi
+ {\tempfloatheight\ht\float_content_box
+ \box\float_content_box
+ \vbox to\tempfloatheight{#1}}}
+
+\def\dofloatboxnextlefthangbuilder#1%
+ {\ifparfloat \hbox \else \expandafter \float_align_content \fi
+ {\tempfloatheight\ht\float_content_box
+ \vbox to\tempfloatheight{#1}%
+ \box\float_content_box}}
+
+\def\dodofloatboxnextrightmarginbuilder#1#2%
+ {\ifparfloat
+ \hbox\bgroup
+ \tempfloatheight\ht\float_content_box
+ \box\float_content_box
+ \hsmash{\hskip#1\vbox to\tempfloatheight{#2}}%
+ \egroup
+ \else
+ \begingroup
+ \tempfloatheight\ht\float_content_box
+ \everyrightofalignedline{\hsmash{\hskip#1\vbox to\tempfloatheight{#2}}}%
+ \float_align_content{\box\float_content_box}%
+ \endgroup
+ \fi}
+
+\def\dodofloatboxnextleftmarginbuilder#1#2%
+ {\ifparfloat
+ \hbox\bgroup
+ \tempfloatheight\ht\float_content_box
+ \hsmash{\hskip-\dimexpr#1+\wd\float_caption_box\relax\vbox to\tempfloatheight{#2}}%
+ \box\float_content_box
+ \egroup
+ \else
+ \begingroup
+ \tempfloatheight\ht\float_content_box
+ \everyleftofalignedline{\hsmash{\hskip-\dimexpr#1+\wd\float_caption_box\relax\vbox to\tempfloatheight{#2}}}%
+ \float_align_content{\box\float_content_box}%
+ \endgroup
+ \fi}
+
+\def\dofloatboxnextrightmarginbuilder{\dodofloatboxnextrightmarginbuilder\rightmargindistance}
+\def\dofloatboxnextleftmarginbuilder {\dodofloatboxnextleftmarginbuilder \leftmargindistance }
+
+\def\dofloatboxnextoutermarginbuilder
+ {\doifrightpagefloatelse
+ {\dodofloatboxnextrightmarginbuilder\rightmargindistance}
+ {\dodofloatboxnextleftmarginbuilder \rightmargindistance}}
+
+\def\dofloatboxnextinnermarginbuilder
+ {\doifrightpagefloatelse
+ {\dodofloatboxnextleftmarginbuilder \leftmargindistance}
+ {\dodofloatboxnextrightmarginbuilder\leftmargindistance}}
+
+\def\dofloatboxnextbuilder % beware, we first check on left/rightmargin because there can be left/right also
+ {\let\next\dofloatboxnextleftbuilder
+ \normalexpanded{\noexpand\processallactionsinset[\floatcaptionparameter\c!location]}
+ [ \v!outermargin=>\let\next\dofloatboxnextoutermarginbuilder,
+ \v!innermargin=>\let\next\dofloatboxnextinnermarginbuilder,
+ \v!leftmargin=>\let\next\dofloatboxnextleftmarginbuilder,
+ \v!rightmargin=>\let\next\dofloatboxnextrightmarginbuilder,
+ \v!lefthanging=>\let\next\dofloatboxnextlefthangbuilder,
+ \v!righthanging=>\let\next\dofloatboxnextrighthangbuilder,
+ \v!outer=>\let\next\dofloatboxnextouterbuilder,
+ \v!inner=>\let\next\dofloatboxnextinnerbuilder,
+ \v!left=>\let\next\dofloatboxnextleftbuilder,
+ \v!right=>\let\next\dofloatboxnextrightbuilder]%
+ \next}
+
+\def\dofloatboxsidebuilder
+ {\ifparfloat
+ \let\next\dofloatboxhighbuilder
+ \else
+ \let\next\dofloatboxmiddlebuilder
+ \expanded{\processallactionsinset[\floatcaptionparameter\c!location]}
+ [ \v!low=>\let\next\dofloatboxlowbuilder,
+ \v!middle=>\let\next\dofloatboxmiddlebuilder,
+ \v!high=>\let\next\dofloatboxhighbuilder]%
+ \fi
+ \next}
+
+\def\doflushfloatleftcaptionhang
+ {\hsmash{\llap{\box\float_caption_box\dotfskip{\floatcaptionparameter\c!distance}}}}
+\def\doflushfloatrightcaptionhang
+ {\hsmash{\rlap{\dotfskip{\floatcaptionparameter\c!distance}\box\float_caption_box}}}
+
+\def\doflushfloatcaptionhang % expanded can go
+ {\expanded{\doifinsetelse{\v!righthanging}{\floatcaptionparameter\c!location}}
+ {\doflushfloatrightcaptionhang}
+ {\expanded{\doifinsetelse{\v!lefthanging}{\floatcaptionparameter\c!location}}
+ {\doflushfloatleftcaptionhang}
+ {\expanded{\doifinsetelse{\v!hang}{\floatcaptionparameter\c!location}}
+ {\expanded{\doifinsetelse{\v!outer}{\floatcaptionparameter\c!location}}
+ {\doifrightpagefloatelse{\doflushfloatrightcaptionhang}{\doflushfloatleftcaptionhang}}
+ {\expanded{\doifinsetelse{\v!right}{\floatcaptiondirectives}}
+ {\doflushfloatrightcaptionhang}
+ {\doflushfloatleftcaptionhang}}}
+ {\box\float_caption_box}}}}
+
+\def\dofloatboxhighbuilder
+ {\dofloatboxnextbuilder{\dofloatboxbetweenstack\doflushfloatcaptionhang\vfill}}
+
+\def\dofloatboxlowbuilder
+ {\dofloatboxnextbuilder{\vfill\doflushfloatcaptionhang\dofloatboxbetweenstack}}
+
+\def\dofloatboxmiddlebuilder
+ {\dofloatboxnextbuilder{\vfill\box\float_caption_box\vfill}}
+
+% \definefloat
+% [lefty][lefties][figure]
+% \setupfloat
+% [lefty]
+% [default=left,
+% rightmargindistance=-2cm,
+% leftmargindistance=-2cm]
+% \setupcaption
+% [lefty]
+% [location={bottom,overlay}]
+%
+% \starttext
+% \placelefty{}{} \input tufte \input tufte
+% \placelefty{}{} \input tufte \input tufte
+% \stoptext
+
+\def\bothangfloat#1{\ruledvbox to \ht\float_content_box{#1\vss}}
+\def\tophangfloat#1{\ruledvbox to \ht\float_content_box{\vss#1}}
+
+\def\dofloatboxnormaltopstackbuilder
+ {\expanded{\doifinset{\v!overlay}{\floatcaptionparameter\c!location}}\tophangfloat
+ {\tempfloatwidth\wd\float_content_box
+ \ifparfloat
+ \hbox{\locatesidefloat{\box\float_caption_box}}%
+ \dofloatboxbetweenstack
+ \hbox{\hbox {\box\float_content_box }}%
+ \else
+ \hbox{\locatetextfloat{\box\float_caption_box}}
+ \dofloatboxbetweenstack
+ \hbox{\float_align_content {\box\float_content_box }}%
+ \fi}}
+
+\def\dofloatboxnormalbotstackbuilder
+ {\expanded{\doifinset{\v!overlay}{\floatcaptionparameter\c!location}}\bothangfloat
+ {\tempfloatwidth\wd\float_content_box
+ \ifparfloat
+ \hbox{\hbox {\box\float_content_box }}%
+ \dofloatboxbetweenstack
+ \hbox{\locatesidefloat{\box\float_caption_box}}%
+ \else
+ \hbox{\float_align_content {\box\float_content_box }}%
+ \dofloatboxbetweenstack
+ \hbox{\locatetextfloat{\box\float_caption_box}}%
+ \fi}}
+
+\def\dofloatboxgridtopstackbuilder
+ {\dp\float_caption_box\strutdepth
+ \setbox\scratchbox\vbox
+ {\tempfloatwidth\wd\float_content_box
+ \ifparfloat
+ \locatesidefloat{\box\float_caption_box}%
+ \vss\dofloatboxbetweenstack
+ \hbox {\box\float_content_box }%
+ \else
+ \locatetextfloat{\box\float_caption_box}%
+ \vss\dofloatboxbetweenstack
+ \float_align_content {\box\float_content_box }%
+ \fi}%
+ \getnoflines{\dimexpr\htdp\scratchbox-10\scaledpoint\relax}% get rid of inaccuracy
+ \vbox to \noflines\lineheight{\unvbox\scratchbox}}
+
+\def\dofloatboxgridbotstackbuilder
+ {\dp\float_caption_box\strutdepth
+ \setbox\scratchbox\vbox
+ {\tempfloatwidth\wd\float_content_box
+ \ifparfloat
+ \hbox {\box\float_content_box }%
+ \vss\dofloatboxbetweenstack
+ \locatesidefloat{\box\float_caption_box}%
+ \else
+ \float_align_content {\box\float_content_box }%
+ \vss\dofloatboxbetweenstack
+ \locatetextfloat{\box\float_caption_box}%
+ \fi}%
+ \getnoflines{\dimexpr\htdp\scratchbox-10\scaledpoint\relax}% get rid of inaccuracy
+ \vbox to \noflines\lineheight{\unvbox\scratchbox}}
+
+\def\dofloatboxstretchtopstackbuilder
+ {\dp\float_caption_box\strutdepth
+ \setbox\scratchbox\vbox
+ {\float_align_caption{\copy\float_caption_box}%
+ \float_align_content {\copy\float_content_box }}%
+ \getnoflines{\dimexpr\htdp\scratchbox-10\scaledpoint\relax}% get rid of inaccuracy
+ \vbox to \noflines\lineheight
+ {\tempfloatwidth\wd\float_content_box
+ \ifparfloat
+ \locatesidefloat{\box\float_caption_box}%
+ \vss\dofloatboxbetweenstack\vss
+ \hbox {\box\float_content_box }%
+ \else
+ \locatetextfloat{\box\float_caption_box}%
+ \vss\dofloatboxbetweenstack\vss
+ \float_align_content {\box\float_content_box }%
+ \fi}}
+
+\def\dofloatboxstretchbotstackbuilder
+ {\dp\float_caption_box\strutdepth
+ \setbox\scratchbox\vbox
+ {\float_align_content {\copy\float_content_box }%
+ \float_align_caption{\copy\float_caption_box}}%
+ \getnoflines{\dimexpr\htdp\scratchbox-10\scaledpoint\relax}% get rid of inaccuracy
+ \vbox to \noflines\lineheight
+ {\tempfloatwidth\wd\float_content_box
+ \ifparfloat
+ \hbox {\box\float_content_box }%
+ \vss\dofloatboxbetweenstack\vss
+ \locatesidefloat{\box\float_caption_box}
+ \else
+ \float_align_content {\box\float_content_box }%
+ \vss\dofloatboxbetweenstack\vss
+ \locatetextfloat{\box\float_caption_box}%
+ \fi}}
+
+\def\dofloatboxtopbuilder
+ {\let\next\dofloatboxnormaltopstackbuilder
+ \expanded{\processfirstactioninset[\floatcaptionparameter\c!location]}
+ [ \v!grid=>\let\next\dofloatboxgridstackbuilder,
+ \v!stretch=>\let\next\dofloatboxstretchstackbuilder]%
+ \next}
+
+\def\dofloatboxbottombuilder
+ {\let\next\dofloatboxnormalbotstackbuilder
+ \expanded{\processfirstactioninset[\floatcaptionparameter\c!location]}
+ [ \v!grid=>\let\next\dofloatboxgridstackbuilder,
+ \v!stretch=>\let\next\dofloatboxstretchstackbuilder]%
+ \next}
+
+\def\relocatecaptionright#1{\float_align_caption{\hbox to \tempfloatwidth{\hss#1}}}
+\def\relocatecaptionleft #1{\float_align_caption{\hbox to \tempfloatwidth{#1\hss}}}
+
+\long\def\installfloatboxbuilder#1#2{\setvalue{\??kj:#1}{#2}}
+
+\def\build_float_box
+ {\global\setbox\floatbox\vbox
+ {\float_set_local_hsize
+ \forgetall
+ \let\floatcaptionarrangement\s!default
+ \def\docommand##1%
+ {\doifdefined{\??kj:##1}{\def\floatcaptionarrangement{##1}\quitcommalist}}%
+ \processcommacommand[\floatcaptionparameter\c!location]\docommand
+ \executeifdefined{\??kj:\floatcaptionarrangement}{\getvalue{\??kj:\s!default}}}}
+
+\def\locatetextfloat
+ {\let\next\float_align_caption
+ \expanded{\processallactionsinset[\floatcaptionparameter\c!location]}
+ [ \v!left=>\let\next\relocatecaptionleft,
+ \v!right=>\let\next\relocatecaptionright,
+ \v!inner=>\doifrightpagefloatelse{\let\next\relocatecaptionleft }{\let\next\relocatecaptionright},
+ \v!outer=>\doifrightpagefloatelse{\let\next\relocatecaptionright}{\let\next\relocatecaptionleft }]%
+ \next}
+
+\installfloatboxbuilder \v!none \dofloatboxdefaultbuilder
+\installfloatboxbuilder \s!default \dofloatboxdefaultbuilder
+\installfloatboxbuilder \v!high \dofloatboxhighbuilder
+\installfloatboxbuilder \v!low \dofloatboxlowbuilder
+\installfloatboxbuilder \v!middle \dofloatboxmiddlebuilder
+
+\installfloatboxbuilder \v!left \dofloatboxsidebuilder
+\installfloatboxbuilder \v!right \dofloatboxsidebuilder
+
+\installfloatboxbuilder \v!top \dofloatboxtopbuilder
+\installfloatboxbuilder \v!bottom \dofloatboxbottombuilder
+
+% \setuplayout[grid=yes] \showgrid \setupcaptions[style=smallbodyfont,location=grid,inbetween=]
+%
+% \starttext
+% test \placefigure{} {\externalfigure[cow.pdf][frame=on,grid=yes]} test \page
+% test \placefigure{\input zapf\relax}{\externalfigure[cow.pdf][frame=on,grid=yes]} test \page
+% test \placefigure{} {\externalfigure[cow.pdf][frame=on,grid=depth]} test \page
+% test \placefigure{\input zapf\relax}{\externalfigure[cow.pdf][frame=on,grid=depth]} test \page
+% \stoptext
+
+\newif\ifpostponecolumnfloats \postponecolumnfloatsfalse % don't change
+
+\setnewconstant\postcenterfloatmethod\plusone
+
+\def\postcenterfloatbox#1%
+ {\scratchdimen
+ \ifcase\postcenterfloatmethod
+ #1% \wd\floatbox
+ \or\ifinsidecolumns
+ \ifpostponecolumnfloats\makeupwidth\else#1\fi
+ \else\ifdim#1>\hsize
+ \hsize
+ \else
+ \wd\floatbox
+ \fi\fi\fi
+ \global\setbox\floatbox\hbox to \scratchdimen
+ % {\hfill\box\floatbox\hfill}} % geen \hss, gaat mis in kolommen !
+ % {\hss \box\floatbox\hss }} % wel \hss, anders mis in colset
+ {\ifglobalcenterfloatbox
+ \donetrue
+ \else\iflocalcenterfloatbox
+ \donetrue
+ \else
+ \donefalse
+ \fi\fi
+ \ifdim\scratchdimen>\effectivehsize
+ \donefalse
+ \fi
+ \hss\ifdone\hskip\effectiveleftskip\fi
+ \box\floatbox
+ \ifdone\hskip\effectiverightskip\fi\hss}}
+
+\def\float_set_paragraph_variant
+ {\bgroup
+ \forgetall
+ \postponenotes
+ \dontcomplain
+ %\showcomposition
+ \setbox\float_content_box\vbox{\borderedfloatbox}%
+ \addlocalbackgroundtobox\float_content_box % no \doglobal
+ \ifnofloatcaption
+ \global\setbox\floatbox\vbox{\box\float_content_box}%
+ \else
+ \check_float_caption_content
+ \prepare_side_float_caption
+ \setbox\float_caption_box\hbox{\floatcaptionparameter\c!command{\box\float_caption_box}}%
+ \moveboxontogrid\float_caption_box{\floatcaptionparameter\c!grid}\float_caption_height
+ \addlocalbackgroundtobox\float_caption_box % no \doglobal
+ \build_side_float_box
+ \fi
+ \egroup}
+
+\def\prepare_side_float_caption
+ {\doifelse{\floatcaptionparameter\c!width}\v!max
+ {\dosettempcaptionbox
+ {\hsize\wd\float_content_box
+ \float_make_complete_caption}}%
+ {\doifelse{\floatcaptionparameter\c!width}\v!fit
+ {\ifdim\wd\float_caption_box>\wd\float_content_box\relax
+ \setbox\float_caption_box\vbox
+ {\forgetall % needed?
+ \hsize\wd\float_content_box
+ \float_make_complete_caption}%
+ \else
+ \setbox\float_caption_box\hbox to \wd\float_content_box
+ {\hss\box\float_caption_box\hss}%
+ \fi}
+ {\dosettempcaptionbox
+ {\hsize\floatcaptionparameter\c!width % \wd\float_content_box
+ \float_make_complete_caption}}}}
+
+\def\build_side_float_box
+ {\let\float_align_content\relax
+ \let\float_align_caption\relax
+ \def\locatesidefloat##1%
+ {\begingroup
+ \alignstrutmode\zerocount
+ \hsize\tempfloatwidth \forgetall
+ \alignedline{\floatparameter\c!location}\v!middle{##1}%
+ \endgroup}%
+ \build_float_box}
+
+\newif\ifparfloat
+
+\def\float_set_box % todo : \global\setbox, currently messy
+ {\ifvisible
+ \par
+ \edef\floatcaptiondirectives{\floatparameter\c!location,\floatcaptionparameter\c!location}%
+ \ifparfloat
+ \float_set_paragraph_variant
+ \else
+ \float_set_page_variant
+ \fi
+ \float_set_local_dimensions
+ \global\advance\totalnoffloats\plusone
+ \setbox\floatbox\hbox{\dosavefloatdata\box\floatbox}% still needed? we will do renumbering differently
+ \global\floatheight\htdp\floatbox
+ \global\floatwidth\wd\floatbox
+ \doifnotinset\v!margin\floatlocation % gaat namelijk nog fout
+ {\setbox\floatbox\vbox
+ {\parindent\zeropoint
+ \doifconcepttracing{\inleftmargin{\framed{\infofont\the\totalnoffloats}}}%
+ \box\floatbox}}%
+ \wd\floatbox\floatwidth
+ \ifdim\dimexpr\floatheight+\lineheight\relax<\textheight \else
+ \global\floatheight\dimexpr\textheight-\lineheight\relax
+ \ht\floatbox\floatheight
+ \dp\floatbox\zeropoint
+ \showmessage\m!floatblocks{10}{\the\totalnoffloats}%
+ \fi
+ \fi}
+
+\newcounter\noxfloatlocations
+
+\def\dooutput{\sidefloatoutput} % redefinition of \dooutput
+
+\definefloat
+ [\v!figure]
+ [\v!figures]
+
+\definefloat
+ [\v!table]
+ [\v!tables]
+
+\setupfloat
+ [\v!table]
+ [\c!frame=\v!off]
+
+\definefloat
+ [\v!intermezzo]
+ [\v!intermezzi]
+
+\definefloat
+ [\v!graphic]
+ [\v!graphics]
+
+% float strategy, replaces some of the above macros
+
+\let\floatmethod \empty
+\let\floatlabel \empty
+\let\floatcolumn \empty
+\let\floatrow \empty
+\let\forcedfloatmethod\empty
+
+\def\setfloatmethodvariables#1% \floatmethod \floatlabel \floatrow \floatcolumn
+ {\ctxcommand{analysefloatmethod("#1")}}
+
+\def\float_get_box
+ {\ifvisible
+ \let\floatlabel \empty
+ \let\floatcolumn\empty
+ \let\floatrow \empty
+ \setfloatmethodvariables\floatlocation
+ % todo: nog algemeen otr
+ \ifdefined\OTRSETsetpreferedcolumnslot
+ \OTRSETsetpreferedcolumnslot\floatcolumn\floatrow
+ \fi
+ \ifcsname\string\floatmethod\floatmethod\endcsname \else
+ \let\floatmethod\v!here
+ \fi
+ \ifx\forcedfloatmethod\empty \else
+ \let\floatmethod\forcedfloatmethod
+ \fi
+ \getvalue{\string\floatmethod\floatmethod}[\floatmethod,\floatlocation]%
+ \fi}
+
+\def\installfloathandler#1#2% #1=keyword #2=handler
+ {\setvalue{\string\floatmethod#1}{#2}}
+
+\def\somesomewherefloat[#1]%
+ {\dofloatssavesomewherefloat\s!somewhere{#1}}
+
+\installfloathandler \v!here \someherefloat
+\installfloathandler \v!force \somefixdfloat
+\installfloathandler \v!left \someleftsidefloat
+\installfloathandler \v!right \somerightsidefloat
+\installfloathandler \v!text \sometextfloat
+\installfloathandler \v!top \sometopfloat
+\installfloathandler \v!bottom \somebottomfloat
+\installfloathandler \v!auto \someautofloat
+\installfloathandler \v!margin \somemarginfloat
+\installfloathandler \v!opposite \somefacefloat
+\installfloathandler \v!page \somepagefloat
+\installfloathandler \v!leftpage \someleftpagefloat
+\installfloathandler \v!rightpage \somerightpagefloat
+\installfloathandler \v!inmargin \someinmarginfloat
+\installfloathandler \v!inleft \someinleftmarginfloat
+\installfloathandler \v!inright \someinrightmarginfloat
+\installfloathandler \v!leftmargin \someinleftmarginfloat
+\installfloathandler \v!rightmargin \someinrightmarginfloat
+\installfloathandler \v!leftedge \someinleftedgefloat
+\installfloathandler \v!rightedge \someinrightedgefloat
+
+\installfloathandler \v!somewhere \somesomewherefloat
+
+\installfloathandler \v!backspace \somebackspacefloat
+\installfloathandler \v!cutspace \somecutspacefloat
+
+\installfloathandler {tblr} \someslotfloat
+\installfloathandler {lrtb} \someslotfloat
+\installfloathandler {tbrl} \someslotfloat
+\installfloathandler {rltb} \someslotfloat
+\installfloathandler {btlr} \someslotfloat
+\installfloathandler {lrbt} \someslotfloat
+\installfloathandler {btrl} \someslotfloat
+\installfloathandler {rlbt} \someslotfloat
+\installfloathandler {fxtb} \someslotfloat
+\installfloathandler {fxbt} \someslotfloat
+
+% no \registerotrcommand\placesome* here!, this has to be cleaned up:
+
+\def\somesidefloat{\OTRcommand\somesidefloat}
+
+\def\someleftsidefloat [#1]{\somesidefloat[#1]\presetindentation}
+\def\somerightsidefloat [#1]{\somesidefloat[#1]}
+\def\sometopfloat [#1]{\someelsefloat[#1]\nonoindentation}
+\def\somebottomfloat [#1]{\someelsefloat[#1]}
+\def\someautofloat [#1]{\someelsefloat[#1]}
+\def\somemarginfloat [#1]{\somenextfloat[#1]\nonoindentation}
+\def\someinleftmarginfloat [#1]{\somesidefloat[#1]}
+\def\someinrightmarginfloat[#1]{\somesidefloat[#1]}
+\def\someinleftedgefloat [#1]{\somesidefloat[#1]}
+\def\someinrightedgefloat [#1]{\somesidefloat[#1]}
+\def\someinmarginfloat [#1]{\somesidefloat[#1]}
+\def\someherefloat [#1]{\someelsefloat[\v!here,#1]}
+\def\somebackspacefloat [#1]{\somesidefloat[#1]}
+\def\somecutspacefloat [#1]{\somesidefloat[#1]}
+
+\unexpanded\def\placesomeslotfloat {\OTRcommand\someslotfloat}
+\unexpanded\def\placesomeherefloat {\OTRcommand\someherefloat}
+\unexpanded\def\placesomefixdfloat {\OTRcommand\somefixdfloat}
+\unexpanded\def\placesomepagefloat {\OTRcommand\somepagefloat}
+\unexpanded\def\placesomeleftpagefloat {\OTRcommand\someleftpagefloat}
+\unexpanded\def\placesomerightpagefloat{\OTRcommand\somerightpagefloat}
+\unexpanded\def\placesometopsfloat {\OTRcommand\sometopsfloat}
+\unexpanded\def\placesomebotsfloat {\OTRcommand\somebotsfloat}
+\unexpanded\def\placesomesidefloat {\OTRcommand\somesidefloat}
+\unexpanded\def\placesomefacefloat {\OTRcommand\somefacefloat}
+%unexpanded\def\placesomesomewherefloat{\OTRcommand\somesomewherefloat}
+
+\def\somefixdfloat {\placesomefixdfloat}
+\def\somepagefloat {\placesomepagefloat}
+\def\someleftpagefloat {\placesomeleftpagefloat}
+\def\somerightpagefloat{\placesomerightpagefloat}
+\def\somefacefloat {\placesomefacefloat}
+\def\someslotfloat {\placesomeslotfloat}
+
+%D Local floats:
+
+\def\setuplocalfloats
+ {\getparameters[\??lf]}
+
+\setuplocalfloats
+ [%\c!before=\blank,
+ %\c!after=\blank,
+ \c!inbetween=\blank]
+
+\installfloathandler \v!local \somelocalfloat
+
+\initializeboxstack{localfloats}
+
+\newcounter\noflocalfloats
+
+\def\resetlocalfloats
+ {\doglobal\newcounter\noflocalfloats
+ \initializeboxstack{localfloats}}
+
+\def\somelocalfloat[#1]%
+ {\doglobal\increment\noflocalfloats
+ \savebox{localfloats}{\noflocalfloats}{\box\floatbox}}
+
+\def\getlocalfloats
+ {\dorecurse\noflocalfloats
+ {\ifnum\recurselevel=\plusone % 1\relax
+ \getvalue{\??lf\c!before}%
+ \else
+ \getvalue{\??lf\c!inbetween}%
+ \fi
+ \dontleavehmode\hbox{\foundbox{localfloats}\recurselevel}%
+ \ifnum\recurselevel=\noflocalfloats\relax
+ \getvalue{\??lf\c!after}%
+ \fi}}
+
+\def\flushlocalfloats
+ {\getlocalfloats
+ \resetlocalfloats}
+
+\def\getlocalfloat#1{\expanded{\foundbox{localfloats}{\number#1}}}
+
+\def\forcelocalfloats{\let\forcedfloatmethod\v!local}
+
+\protect \endinput