%D \module %D [ file=node-bck, %D version=2009.06.08, %D title=\CONTEXT\ Node Macros, %D subtitle=Backgrounds, %D author=Hans Hagen, %D date=\currentdate, %D copyright=PRAGMA] %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 Node Support / Backgrounds} %D This is first attempt to replacing backgrounds in a few %D tables mechanisms. \unprotect \registerctxluafile{node-bck}{1.001} %D Box helpers: \def\doaddbackgroundtobox#1[#2]% {\begingroup\faststartcolor[#2]% \normalexpanded{\noexpand\faststopcolor\endgroup#1 attr \backgroundattribute \plusone attr \colormodelattribute \the\attribute\colormodelattribute attr \colorattribute \the\attribute\colorattribute attr \transparencyattribute \the\attribute\transparencyattribute}} \def\backgroundvbox{\doaddbackgroundtobox\vbox} \def\backgroundvtop{\doaddbackgroundtobox\vtop} \def\backgroundhbox{\doaddbackgroundtobox\hbox} \def\colorattr#1% {\ifcsname(cs:\currentpalet#1)\endcsname \thecolorattr{\currentpalet#1}% \else\ifcsname(cs:#1)\endcsname \thecolorattr{#1}% \fi\fi} \def\thecolorattr#1% {attr \colormodelattribute \attribute\colormodelattribute attr \colorattribute \csname(cs:#1)\endcsname attr \transparencyattribute \csname(ts:#1)\endcsname} \def\backgroundcolorattr#1% {\ifcsname(cs:\currentpalet#1)\endcsname \thebackgroundcolorattr{\currentpalet#1}% \else\ifcsname(cs:#1)\endcsname \thebackgroundcolorattr{#1}% \fi\fi} \def\thebackgroundcolorattr#1% {attr \backgroundattribute \plusone attr \colormodelattribute \attribute\colormodelattribute attr \colorattribute \csname(cs:#1)\endcsname attr \transparencyattribute \csname(ts:#1)\endcsname} % \def\backgroundvbox[#1]{\vbox \backgroundcolorattr{#1}} % \def\backgroundvtop[#1]{\vtop \backgroundcolorattr{#1}} % \def\backgroundhbox[#1]{\hbox \backgroundcolorattr{#1}} %D tabulate: \def\tabulatenormalcolumn#1% {\doiffastoptionalcheckelse{\tabulatenormalcolumnyes#1}{\tabulatenormalcolumnnop#1}} \def\tabulatenormalcolumnnop#1% overloads anch-pgr {&\iftabulateequal\tabulateequalpos\else\tabulatenormalpos\fi&\global\chardef\tabulatetype#1&} \def\tabulatenormalcolumnyes#1[#2]% {&\iftabulateequal\tabulateequalpos\else\tabulatenormalpos\fi&\global\chardef\tabulatetype#1&% \iftrialtypesetting\else\settabulatecolor{#2}\fi\ignorespaces} \newcount\maxtabularcolorcolumn \def\settabulatecolor#1% we could store the attributes at the cost of a lua call {\begingroup \global\settrue\tabulatehascolors \ifnum\tabulatecolumn>\maxtabularcolorcolumn \global\maxtabularcolorcolumn\tabulatecolumn \fi \setxvalue{\??tt:c:\the\tabulatecolumn}{#1}% \attribute\backgroundattribute\plusone \faststartcolor[#1]\strut\char0\faststopcolor \endgroup} \def\repeatsettabulatecolor {\begingroup \ifcsname\??tt:c:\the\tabulatecolumn\endcsname \attribute\backgroundattribute\plusone \faststartcolor[\csname\??tt:c:\the\tabulatecolumn\endcsname]\strut\char0\faststopcolor \fi \endgroup} \def\resettabulatecolors {\ifcase\maxtabularcolorcolumn\else \doresettabulatecolors \fi} \def\doresettabulatecolors {\dorecurse\maxtabularcolorcolumn{\letgvalue{\??tt:c:\recurselevel}\undefined}} % slow \appendtoks \resettabulatecolors \to \everyaftertabulaterow \def\splitofftabulatebox % overloads in anch-pgr {\dontcomplain \global\setbox\tabulatebox % % % global ? % % % \vsplit\tablebox\tabulatecolumn to \lineheight \setbox\tabulatebox\normalvbox {\unvbox\tabulatebox}% \setbox\tabulatebox\hbox to \wd\tabulatebox {\iftrialtypesetting\else\ifconditional\tabulatehascolors\repeatsettabulatecolor\fi\fi \hss\dotabulatehook{\box\tabulatebox}\hss}% \ht\tabulatebox\strutht \dp\tabulatebox\strutdp \box\tabulatebox \iftrialtypesetting\else\ifconditional\tablehaspositions\doflushtabulateepos\fi\fi} \appendtoks \global\setfalse\tabulatehascolors \to \everytabulate \protect \endinput % test \starttext \backgroundvbox[green] {\input tufte } \par \backgroundvbox[blue] {\input ward } \par \backgroundvbox[red] {\input knuth } \par \backgroundhbox[yellow]{\rotate[rotation=45]{hello world}} \par \starttabulate[||p||] \NC test \NC test \NC test \NC \NR \NC test \NC[green] \input tufte \NC[yellow] test \NC \NR \NC test \NC test \NC test \NC \NR \NC test \NC test \NC test \NC \NR \NC test \NC test \NC test \NC \NR \NC test \NC test \NC test \NC \NR \NC[blue] test \NC[red] test \NC test \NC \NR \NC test \NC test \NC test \NC \NR \NC test \NC test \NC test \NC \NR \NC test \NC test \NC test \NC \NR \NC test \NC test \NC[gray] test \NC \NR \NC test \NC test \NC test \NC \NR \NC test \NC test \NC test \NC \NR \NC[blue] test \NC test \NC test \NC \NR \NC test \NC test \NC test \NC \NR \NC test \NC test \NC[magenta] test \NC \NR \NC test \NC test \NC test \NC \NR \NC test \NC[cyan] \dorecurse{10}{\input ward }\NC test \NC \NR \NC test \NC test \NC test \NC \NR \NC test \NC[yellow] test \NC test \NC \NR \stoptabulate \stoptext