%D \module %D [ file=page-flt, %D version=2010.04.08, %D title=\CONTEXT\ Page Macros, %D subtitle=Float Management, %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 Page Macros / Float Management} %D This module has code that previously was in other modules. There is %D also float related code in \type {strc-flt.mkiv}. \registerctxluafile{page-flt}{1.001} \unprotect %D To be checked and removed %def\dosavefloatinfo {\showmessage\m!floatblocks2{\the\totalnoffloats}} \def\doinsertfloatinfo {\showmessage\m!floatblocks4{\the\totalnoffloats}} \def\dofloatflushedinfo{\showmessage\m!floatblocks3{\the\numexpr\totalnoffloats-\savednoffloats\relax}} %D Extra float registers. \newif\ifsomefloatwaiting \somefloatwaitingfalse \newif\ifroomforfloat \roomforfloattrue \newif\ifnofloatpermitted \nofloatpermittedfalse \newif\ifcenterfloatbox \centerfloatboxtrue \newif\iflocalcenterfloatbox \localcenterfloatboxfalse \newif\ifglobalcenterfloatbox \globalcenterfloatboxfalse \newif\ifflushingfloats \flushingfloatsfalse \newif\ifpackflushedfloats \packflushedfloatstrue % for the moment \newif\ifpackcolumnfloats \packcolumnfloatstrue \newcount\totalnoffloats \newcount\savednoffloats \newcount\noffloatinserts \newcount\nofcollectedfloats % communication channel \newbox \floatlist \newbox \savedfloatlist \newbox \floattext \newdimen\floatwidth \newdimen\floatheight \newdimen\floatdepth \newdimen\floattextwidth \newdimen\floattextheight \newbox \floatbox \newbox \savedfloatbox %D From now on we manage the float stack at the \LUA\ end instead of packing %D them in a box and splitting off stacked floats. It's not so much less code %D but it's cleaner this way. It also opens op some posibilities as we can now %D more conveniently cary additional information around. \newtoks \everyfloatscheck \appendtoks \ifcase\savednoffloats \global\somefloatwaitingfalse \else \global\somefloatwaitingtrue \fi \to \everyfloatscheck \def\dofloatsflush#1#2% {\ctxcommand{flushfloat("#1",\number#2)}% \the\everyfloatscheck} \def\dofloatsflushbylabel#1#2% {\ctxcommand{flushfloat("#1","#2",true)}% \the\everyfloatscheck} \def\dofloatssave#1% {\ctxcommand{savefloat("#1")}% \the\everyfloatscheck} \def\dofloatsresave#1% {\ctxcommand{resavefloat("#1")}% \the\everyfloatscheck} \def\dopushsavedfloats {\ctxcommand{pushfloat()}% \the\everyfloatscheck} \def\dopopsavedfloats {\ctxcommand{popfloat()}% \the\everyfloatscheck} \def\dofloatsgetinfo#1% {\ctxcommand{consultfloat("#1")}} \def\doifelsesavedfloat#1% {\ctxcommand{doifelsesavedfloat("#1")}} \def\dofloatscollect#1#2#3% {\ctxcommand{collectfloat("#1",\number\dimexpr#2,\number\dimexpr#3)}} \def\nofstackedfloatincategory#1% {\ctxcommand{nofstackedfloats("#1")}} \let\dopushcolumnfloats\dopushsavedfloats \let\dopopcolumnfloats \dopopsavedfloats \def\dofloatssavepagefloat#1#2% {\ctxcommand{savefloat("#1", { specification = "#2" })}} \def\dofloatssavesomewherefloat#1#2% #1=method {\ctxcommand{savefloat("#1", { specification = "#2", label = "\floatlabel" })}} %D This is an experimental new feature (for Alan Braslau), a prelude to more: %D %D \starttyping %D test \placefigure{}{} %D test \placefigure[somewhere:alpha][whatever]{}{} %D test \placefigure[somewhere:beta] [whatever]{}{} %D test \placefigure[somewhere:gamma][whatever]{}{} %D test \placefigure[somewhere:delta][whatever]{}{} %D test \placefigure{}{} %D %D in \in{figure}[whatever] bla bla %D %D \placenamedfloat[figure][*l*] %D \placenamedfloat[figure][gamma] %D \placenamedfloat[figure][beta] %D \stoptyping \def\placenamedfloat {\dodoubleargument\doplacenamedfloat} \def\doplacenamedfloat[#1][#2]% {\doloop {\dofloatsflushbylabel\s!somewhere{#2}% \ifvoid\floatbox \exitloop \else \def\currentfloat{#1}% \blank[\rootfloatparameter\c!spacebefore]% \box\floatbox \blank[\rootfloatparameter\c!spaceafter] \fi}} % \setupcaption [figure] [align=flushleft] % \setupcaption [figure-1] [align=flushleft,leftmargin=10mm] % \setupcaption [figure-2] [align=flushleft,leftmargin=10mm,rightmargin=-10mm,width=\textwidth] % % \startsetups somefigure % \ifdim\floatsetupwidth>\textwidth % \placesetupfloat[figure-2] % \else % \placesetupfloat[figure-1] % \fi % \stopsetups % % \placefloatwithsetups[somefigure]{}{\externalfigure[dummy][width=5cm,height=2cm]} \def\placefloatwithsetups {\dotripleempty\doplacefloatwithsetups} \long\def\doplacefloatwithsetups[#1][#2][#3]#4% {\def\floatsetupcaption {#4}% \def\floatsetupcontent {\copy\nextbox}% \def\floatsetupwidth {\wd\nextbox}% \def\floatsetupheight {\ht\nextbox}% \def\placesetupfloat[##1]{\placefloat[##1][#2][#3]{#4}{\floatsetupcontent}}% #4 and not \floatsetupcaption (unexpanded) \dowithnextbox{\setups[#1]}\vbox} %D The following code is in transition as we don't want to break the %D current single column, multi column, and columnset mechanism. %D %D First we reimplement some helpers. \def\dogetfloat {\ifsomefloatwaiting \dofloatsflush\s!text{1}% \ifcenterfloatbox \ifdim\wd\globalscratchbox<\hsize \global\setbox\floatbox\hbox to \hsize{\hss\box\floatbox\hss}% \else % retain special alignments \ifinsidecolumns \ifdim\wd\floatbox>\makeupwidth \wd\floatbox\makeupwidth \fi \fi \fi \fi \else \global\savednoffloats\zerocount \global\setbox\floatbox\emptybox \fi} \def\dosavefloat {\dofloatssave\s!text \nonoindentation} % brrr nonoindentation here \def\doresavefloat {\dofloatsresave\s!text} \def\doreversesavefloat {\dofloatsresave\s!text} \def\doflushsavedfloats % simplified \OTRONEdodoflushfloats .. nothing special in otr ... in place {\doloop {\ifsomefloatwaiting \page_otr_command_check_if_float_fits \ifroomforfloat \dogetfloat \doplacefloatbox \else \exitloop \fi \else \exitloop \fi}} %D Page floats use different stacks. \newtoks \everybeforeflushedpagefloat \def\doflushsomepagefloat#1% future releases can do more clever things {\dofloatsflush{#1}{1}% \edef\floatspecification{\ctxcommand{getfloatvariable("specification")}}% Is this okay? \the\everybeforeflushedpagefloat \vbox to \textheight {\doifnotinset\v!high\floatspecification\vfill \box\floatbox \doifnotinset\v!low\floatspecification\vfill}% \page_otr_fill_and_eject_page} \def\doflushpagefloats {\edef\checkedpagefloat{\ctxcommand{checkedpagefloat()}}% (true) for packed \ifx\checkedpagefloat\empty % nothing \else\ifx\checkedpagefloat\v!empty \emptyhbox \page_otr_fill_and_eject_page % why not dummy_page \else \doflushsomepagefloat\checkedpagefloat \fi\fi} \def\uncenteredfloatbox % hm, where is this one used (was in save/restore, see old implementation) {\ifcenterfloatbox \ifhbox\floatbox\relax % remove centering \ifdim\wd\floatbox=\hsize \ifhbox\floatbox \setbox\scratchbox\hbox {\unhbox\floatbox \unskip\unskip \global\setbox\globalscratchbox\lastbox}% \box\globalscratchbox \else \box\floatbox \fi \else \box\floatbox \fi \else \box\floatbox \fi \else \box\floatbox \fi} % temp hack, needed to prevent floatbox being forgotten during % output, this will change to using another box for flushing % % \dorecurse{700}{text } \placefigure[top][]{First} {\framed{bla 1}} % \placefigure[top][]{Second}{\framed{bla 2}} % \dorecurse {40}{text } \placefigure[top][]{Third} {\framed{bla 3}} \newbox\savedfloatbox \appendtoks \global\setbox\savedfloatbox\box\floatbox \to \everybeforeoutput \appendtoks \global\setbox\floatbox\box\savedfloatbox \to \everyafteroutput \protect \endinput