%D \module %D [ file=anch-pgr, % moved from anch-pgr (1999.08.01) %D version=2011.12.19, % 1999.08.01, %D title=\CONTEXT\ Anchoring Macros, %D subtitle=Table Extensions, %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 Anchoring Macros / Table Extensions} \unprotect \newcount\c_anch_tabs \unexpanded\def\tabl_tabulate_hook_b {\iftrialtypesetting\else \ifpositioning \ifcase\c_tabl_tabulate_noflines % \ifnum\c_tabl_tabulate_noflines=\c_tabl_tabulate_totalnoflines \tabl_tabulate_hook_b_first \else \tabl_tabulate_hook_b_next \fi \fi \fi} \unexpanded\def\tabl_tabulate_hook_e {\iftrialtypesetting\else \ifpositioning \ifcase\c_tabl_tabulate_noflines % \ifnum\c_tabl_tabulate_noflines=\c_tabl_tabulate_totalnoflines \tabl_tabulate_hook_e_first \else \tabl_tabulate_hook_e_next \fi \fi \fi} \unexpanded\def\tabl_tabulate_hook_b_first {\ctxcommand{bcolumn("tabulate:\the\c_anch_tabs:\the\c_tabl_tabulate_column",true)}} \unexpanded\def\tabl_tabulate_hook_b_next {\ctxcommand{bcolumn("tabulate:\the\c_anch_tabs:\the\c_tabl_tabulate_column")}} \unexpanded\def\tabl_tabulate_hook_e_first {\ctxcommand{ecolumn(true)}} \unexpanded\def\tabl_tabulate_hook_e_next {\ctxcommand{ecolumn()}} % \appendtoks \registerparoptions \to \everypar \appendtoks \global\advance\c_anch_tabs\plusone \to \everytabulate %D Beware, the following code is somewhat weird and experimental %D and might be dropped or become a loadable module. %D \macros %D {GFC, GTC, GSC} %D %D The next macros extend tables and tabulation with %D backgrounds and position related features. Areas are %D specified with symbolic names, and symbolic references to %D the graphics involved. Each table has its own namespace. \newconditional\tablehaspositions \newcount\noftabpositions \newtoks \posXCtoks \def\dotablebpos{\bpos} \def\dotableepos{\epos} \installcorenamespace{positiontables} \def\tbPOSprefix {\??positiontables\number\noftabpositions:} \def\tablepos {\normalexpanded{\global\posXCtoks\emptytoks\the\posXCtoks}} \let\tabulatepos\tablepos \def\dodododoGSC[#1:#2]% {\remappositionframed{#2}{\tbPOSprefix#1}% \dotablebpos{\tbPOSprefix#1}% \doglobal\appendtoks\@EA\dotableepos\@EA{\tbPOSprefix#1}\to\posXCtoks} \def\dododoGSC[#1:#2:#3]% {\doglobal\appendtoks\dodododoGSC[#1:#2]\to\posXCtoks\NC} \def\dodoGSC[#1]% {\def\docommand##1{\dododoGSC[##1:##1]}% \processcommalist[#1]\docommand} \def\dodododoGFC[#1:#2:#3]% {\remappositionframed{#2}{\tbPOSprefix#1}% \dotablebpos{\tbPOSprefix#1}} \def\dododoGFC[#1]% {\def\docommand##1{\dodododoGFC[##1:##1]}% \processcommalist[#1]\docommand} \def\dodoGFC[#1]% {\doglobal\appendtoks\dododoGFC[#1]\to\posXCtoks\NC} \def\dododododoGTC[#1:#2]% {\dotableepos{\tbPOSprefix#1}} \def\dodododoGTC[#1]% {\def\docommand##1{\dododododoGTC[##1:##1]}% \processcommalist[#1]\docommand} \def\dododoGTC[#1]% {\doglobal\appendtoks\dodododoGTC[#1]\to\posXCtoks} \def\dodoGTC[#1]% {\doglobal\appendtoks\dododoGTC[#1]\to\posXCtoks\NC} \def\dodododoXC[#1#2]% {\if#1>\dodoGFC [#2:#2]\else \if#1+\dodoGFC [#2:#2]\else \if#1<\dodoGTC [#2:#2]\else \if#1-\dodoGTC [#2:#2]\else \if#1=\dodoGSC [#2:#2]\else \dodoGSC[#1#2:#1#2]\fi\fi\fi\fi\fi} \def\dododoXC#1% {\dodododoXC[#1]} \def\dodoXC[#1]% {{\let\NC\relax\processcommalist[#1]\dododoXC}} \def\@@checktablepositionstate {\iftrialtypesetting \global\settrue\tablehaspositions \firstargumentfalse \fi} \def\doGSC[#1]{\@@checktablepositionstate\iffirstargument\dodoGSC[#1]\else\expandafter\NC\fi} \def\doGFC[#1]{\@@checktablepositionstate\iffirstargument\dodoGFC[#1]\else\expandafter\NC\fi} \def\doGTC[#1]{\@@checktablepositionstate\iffirstargument\dodoGTC[#1]\else\expandafter\NC\fi} \def\doXC [#1]{\@@checktablepositionstate\iffirstargument\dodoXC [#1]\else\expandafter\fi\NC} \def\tbGSC{\dosingleempty\doGSC} \def\tbGFC{\dosingleempty\doGFC} \def\tbGTC{\dosingleempty\doGTC} \def\tbXC {\dosingleempty\doXC } %D The amount of code to support tables and tabulation is %D rather minimalistic. \let\tabulatepos\tablepos \def\tabulatenormalpos {\iftrialtypesetting % nothing \else\ifconditional\tablehaspositions \hss\tabulatepos\hss \else % nothing \fi\fi} \def\tabulateequalpos {\iftrialtypesetting \tabulateEQ \else\ifconditional\tablehaspositions \tabulateEQpos \else \tabulateEQ \fi\fi} \def\tabulateEQpos {\setbox\scratchbox\hbox{\tabulateEQ}% \hbox to \wd\scratchbox{\hss\kern\zeropoint\tabulatepos\hss}% \hskip-\wd\scratchbox \box\scratchbox} \appendtoks \global\advance\noftabpositions\plusone \global\setfalse\tablehaspositions \to \everytabulate % We need to handle paragraphs as well. \let\doflushtabulateepos\relax \def\dotabulatebpos {\bpos} \def\dotabulateepos#1% {\ifvoid\b_tabl_tabulate_current\c_tabl_tabulate_column \epos{#1}% \glet\doflushtabulateepos\relax \else \gdef\doflushtabulateepos{\epos{#1}}% \fi} \def\flushtabulatesplitbox {\box\b_tabl_tabulate \iftrialtypesetting\else\ifconditional\tablehaspositions\doflushtabulateepos\fi\fi} \appendtoks \let\dotablebpos\dotabulatebpos % ? \let\dotableepos\dotabulateepos % ? \glet\doflushtabulateepos\relax \to \everytabulate %D In order to prevent potential clashes with abbreviations, %D postpone the mapping. \appendtoks \let\GSC\tbGSC \let\GFC\tbGFC \let\GTC\tbGTC \let\XC \tbXC \to \everytabulate %D \macros %D {definepositionframed} %D %D The next example show how to provide backgrounds to table %D cells. First we define some framed backgrounds. %D %D \startbuffer %D \definepositionframed[x][background=color,backgroundcolor=red] %D \definepositionframed[y][background=color,backgroundcolor=green] %D \definepositionframed[z][background=color,backgroundcolor=blue] %D \stopbuffer %D %D \typebuffer %D %D % \getbuffer %D %D \startbuffer %D \starttabulate[|c|c|c|] %D \GFC[f:x] this is a small \NC table \NC in which we \NC \FR %D \NC will demonstrate \GFC[g:z] that this \GTC[g] positioning \NC \MR %D \GSC[e:y] mechanism also \GTC[f] works quite well \NC in tables \NC \LR %D \stoptabulate %D \stopbuffer %D %D The table itself defines three areas (a, b and~c) using %D these frames. %D %D \typebuffer %D % \getbuffer %D %D Tables (based on \TABLE) are supported by: \def\normalTABLEsimplebar {\unskip\!ttRightGlue&\tablepos&} % | \def\normalTABLEcomplexbar{\unskip\!ttRightGlue&\omit\tablepos\!ttAlternateVrule} % \| \def\normalTABLEquote {\unskip\!ttRightGlue&\omit\tablepos&} % " \appendtoks \global\advance\noftabpositions\plusone \global\setfalse\tablehaspositions \to \everytable %D Since we don't want nameclashes: \appendtoks \let\GSC\tbGSC \let\GFC\tbGFC \let\GTC\tbGTC \let\XC \tbXC \to \everytable %D In the previous example, we could have provided an overlay to %D the framed definition. A more direct approach is demonstrated %D below: %D %D \startbuffer %D \def\cw#1{\color[white]{#1}} %D %D \startMPpositiongraphic{tableshade} %D initialize_area(\MPpos{\MPvar{from}},\MPpos{\MPvar{to}}) ; %D color c ; c := \MPvar{color} ; %D linear_shade(pxy,0,.4c,.9c) ; %D anchor_area(\MPanchor{\MPvar{from}}) ; %D \stopMPpositiongraphic %D %D \setMPpositiongraphic{b:x}{tableshade}{from=b:x,to=e:x,color=red} %D \setMPpositiongraphic{b:y}{tableshade}{from=b:y,to=e:y,color=green} %D \setMPpositiongraphic{b:z}{tableshade}{from=b:z,to=e:z,color=blue} %D \stopbuffer %D %D \typebuffer \getbuffer %D %D The definition of the table looks about the same as the %D previous one: %D %D \startbuffer %D \starttable[|c|c|c|] %D \GFC[b:z] \cw{this is a small} \NC \cw{table} \NC in which we \NC \FR %D \NC \cw{will demonstrate} \GFC[c:y] \cw{that this} \GTC[c] \cw{positioning} \NC \MR %D \GSC[a:x] \cw{mechanism also} \GTC[b] \cw{works quite well} \NC in tables \NC \LR %D \stoptable %D \stopbuffer %D %D \typebuffer %D %D \getbuffer % \definepositionframed[w][background=color,backgroundcolor=yellow] % \definepositionframed[x][background=color,backgroundcolor=red] % \definepositionframed[y][background=color,backgroundcolor=green] % \definepositionframed[z][background=color,backgroundcolor=blue] % % \starttabulate[|c|c|c|] % \NC this is a small \NC table \NC in which we \NC \FR % \NC will demonstrate \NC that this \NC positioning \NC \MR % \NC mechanism also \NC works quite well \NC in tables \NC \LR % \stoptabulate % % \starttabulate[|c|c|c|] % \GFC[f:x] this is a small \GTC table \NC in which we \NC \FR % \NC will demonstrate \GFC[g:z] that this \GTC[g] positioning \NC \MR % \GSC[e:y] mechanism also \GTC[f] works quite well \NC in tables \NC \LR % \stoptabulate % % \starttabulate[|c|c|c|] % \GFC[f:x,d:w] this is a small \GTC[d] table \NC in which we \NC \FR % \NC will demonstrate \GFC[g:z] that this \GTC[g] positioning \NC \MR % \GSC[e:y] mechanism also \GTC[f] works quite well \NC in tables \NC \LR % \stoptabulate % % \starttabulate[|c|c|c|] % \XC[+f:x] this is a small \XC table \NC in which we \NC \FR % \NC will demonstrate \XC[+g:z] that this \XC[-g] positioning \NC \MR % \XC[=e:y] mechanism also \XC[-f] works quite well \NC in tables \NC \LR % \stoptabulate % % \starttabulate[|c|c|c|] % \XC[+f:x,+d:w] this is a small \XC[-d] table \NC in which we \NC \FR % \NC will demonstrate \XC[+g:z] that this \XC[-g] positioning \NC \MR % \XC[=e:y] mechanism also \XC[-f] works quite well \NC in tables \NC \LR % \stoptabulate % evt [b:x] % % \definepositionframed[x][background=color,fillcolor=red] % \definepositionframed[y][background=color,fillcolor=green] % \definepositionframed[z][background=color,fillcolor=blue] \def\remappositionframed#1#2% from to {\copyposition{b:#1}{b:#2}% \copyposition{e:#1}{e:#2}% \dosetpositionaction{b:#2}{\dopositionaction{b:#1}}} \unexpanded\def\definepositionframed {\dodoubleargument\dodefinepositionframed} \def\dodefinepositionframed[#1][#2]% {\dosetpositionaction{b:#1}{\dopositionframed[#1][#2]}} \unexpanded\def\positionframed {\bgroup \dodoubleempty\dopositionframed} \def\dopositionframed[#1][#2]% {\setbox\scratchbox\hbox {\scratchwidth \dimexpr\MPx{e:#1}-\MPx{b:#1}\relax \scratchdepth \dimexpr\MPy{b:#1}-\MPy{e:#1}+\MPd{e:#1}\relax \scratchheight\dimexpr\scratchdepth+\MPh{b:#1}\relax \lower\scratchdepth\hbox {\framed[\c!width=\scratchwidth,\c!height=\scratchheight,\c!offset=\v!overlay,#2]{}}}% \smashedbox\scratchbox \egroup} \protect \endinput