summaryrefslogtreecommitdiff
path: root/tex/context/base/page-bck.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/page-bck.mkiv')
-rw-r--r--tex/context/base/page-bck.mkiv56
1 files changed, 50 insertions, 6 deletions
diff --git a/tex/context/base/page-bck.mkiv b/tex/context/base/page-bck.mkiv
index 0246e8eb6..01de48e8c 100644
--- a/tex/context/base/page-bck.mkiv
+++ b/tex/context/base/page-bck.mkiv
@@ -55,7 +55,7 @@
%D This is the only spot where we hav ea low level dependency on the way
%D parent chains are defined but we want the speed.
-\def\page_backgrounds_check_background
+\unexpanded\def\page_backgrounds_check_background
{\ifcsname\??framed\currentotrbackground:\c!background\endcsname
\edef\page_background_temp{\csname\??framed\currentotrbackground:\c!background\endcsname}%
\ifx\page_background_temp\empty
@@ -140,13 +140,15 @@
{\edef\currentotrbackground{\??layoutbackgrounds#1}%
\page_backgrounds_check_background}
-\def\doifsomebackgroundelse#1%
+\def\doifelsesomebackground#1%
{\ifcsname\??layoutbackgrounds#1\endcsname
\expandafter\firstoftwoarguments
\else
\expandafter\secondoftwoarguments
\fi}
+\let\doifsomebackgroundelse\doifelsesomebackground
+
\def\doifsomebackground#1%
{\ifcsname\??layoutbackgrounds#1\endcsname
\expandafter\firstofoneargument
@@ -277,7 +279,7 @@
\page_backgrounds_set_boxes
\setbox#1\vbox
{\offinterlineskip
- \doifmarginswapelse{\copy\leftbackground}{\copy\rightbackground}%
+ \doifelsemarginswap{\copy\leftbackground}{\copy\rightbackground}%
\box#1}%
\fi}
@@ -343,7 +345,7 @@
{\dontcomplain
\swapmargins
\ifconditional\swapbackgroundmargins
- \doifmarginswapelse \donothing
+ \doifelsemarginswap \donothing
{\swapmacros\v!rightmargin\v!leftmargin
\swapmacros\v!rightedge \v!leftedge}%
\fi
@@ -501,7 +503,7 @@
\unexpanded\def\page_backgrounds_setup_double[#1][#2][#3]% if needed we can speed this up
{\global\settrue\c_page_backgrounds_some
\def\page_backgrounds_setup_step##1%
- {\doifinsetelse{##1}\v_page_backgrounds_double_set
+ {\doifelseinset{##1}\v_page_backgrounds_double_set
{\page_backgrounds_setup_and_check{##1}{#3}}
{\def\page_backgrounds_setup_step_nested####1{\page_backgrounds_setup_and_check{##1####1}{#3}}%
\processcommacommand[#2]\page_backgrounds_setup_step_nested}}%
@@ -510,7 +512,7 @@
\unexpanded\def\page_backgrounds_setup_single[#1][#2][#3]%
{\global\settrue\c_page_backgrounds_some
- \doifcommonelse{#1}\v_page_backgrounds_single_set
+ \doifelsecommon{#1}\v_page_backgrounds_single_set
{\def\page_backgrounds_setup_step##1{\page_backgrounds_setup_and_check{##1}{#2}}%
\processcommacommand[#1]\page_backgrounds_setup_step
\the\everybackgroundssetup}%
@@ -607,6 +609,48 @@
\setfalse\c_page_backgrounds_some
+%D Sometimes you have a document wide (page) background but need to overload it
+%D locally. In such case (at least in my experience) the only values that get set
+%D are the background and backgroundcolor (if set at all). A full inheritance chain
+%D would complicate things because then we need to use named backgrounds which in
+%D turn will make this mechanism slower. I considered independent local backgrounds
+%D but that also complicates the code (not that much) but isolation means that we
+%D need to set more parameters each time. The following simple approach proabbly
+%D suits most usage.
+%D
+%D \starttyping
+%D \starttext
+%D \setupbackgrounds[page][background=color,backgroundcolor=red]
+%D \input tufte \page
+%D \setupbackgrounds[page][background=,backgroundcolor=]
+%D \input tufte \page
+%D \setupbackgrounds[page][background=color,backgroundcolor=red]
+%D \input tufte \page
+%D \pushbackground[page]
+%D \setupbackgrounds[page][background=color,backgroundcolor=green]
+%D \input tufte \page
+%D \popbackground
+%D \input tufte \page
+%D \stoptext
+%D \stoptyping
+
+\unexpanded\def\pushbackground[#1]%
+ {\pushmacro\popbackground
+ \edef\currentotrbackground{\??layoutbackgrounds#1}%
+ \unexpanded\edef\popbackground
+ {\setupframed
+ [\currentotrbackground]
+ [\c!background=\namedframedparameter{\currentotrbackground}\c!background,
+ \c!backgroundcolor=\namedframedparameter{\currentotrbackground}\c!backgroundcolor]%
+ \page_backgrounds_check_background
+ \popmacro\popbackground}%
+ \setupframed
+ [\currentotrbackground]
+ [\c!background=,\c!backgroundcolor=]%
+ \page_backgrounds_check_background}
+
+\let\popbackground\relax
+
\protect \endinput
% %D The next series is used in local (for instance floating) backgrounds.