MAJOR=4
MINOR=41
DEVNAME=tty41
  7   ˆl–Ü4ý(Ð;�½p-©‹Fÿ�þ\q‘,Üd+mQ¹üÿÌ„�p_Ë¿É ?÷     %D \module
%D   [       file=page-bck, % copied from main-001
%D        version=1997.03.31,
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Backgrounds,
%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.

% Currently the text cells are fakes and no (foreground) frames which makes sense
% as order might matter e.g. is text sticks in other cells. The page, text etc
% areas do support foreground order change.

\writestatus{loading}{ConTeXt Page Macros / Backgrounds}

\unprotect

% maybe use \currentframedhash here

%D For special purposes, users can question the \type {*background} mode. This mode
%D is only available when typesetting the pagebody.
%D
%D \starttyping
%D \startmode[*background] ...
%D \stoptyping

\newconditional\c_page_backgrounds_new
\newconditional\c_page_backgrounds_new_right
\newconditional\c_page_backgrounds_new_left
\newconditional\c_page_backgrounds_some

\appendtoks
    \ifconditional\c_page_backgrounds_some
        \ifconditional\c_page_backgrounds_new
            \setsystemmode\v!background
        \fi
    \fi
\to \everybeforepagebody

\unexpanded\def\initializepagebackgrounds
  {\setfalse\c_page_backgrounds_new
   \setfalse\c_page_backgrounds_new_right
   \setfalse\c_page_backgrounds_new_left
   \setfalse\c_page_backgrounds_some}

%D We keep calculations and checks to a minimum and also try to minimize
%D the amount of tracing due to expansion.

\let\currentotrbackground\empty

%D This is the only spot where we have a low level dependency on the way
%D parent chains are defined but we want the speed.

\unexpanded\def\page_backgrounds_check_background
  {\ifcsname\??framed\currentotrbackground:\c!background\endcsname
    %\edef\page_background_temp{\csname\??framed\currentotrbackground:\c!background\endcsname}%
     \edef\page_background_temp{\lastnamedcs}%
     \ifx\page_background_temp\empty
       \expandafter\expandafter\expandafter\page_backgrounds_check_frame
     \else
       \page_backgrounds_set_yes
     \fi
   \else
     \expandafter\page_backgrounds_check_frame
   \fi}

\def\page_backgrounds_check_frame
  {\ifcsname\??framed\currentotrbackground:\c!frame\endcsname
    %\edef\page_background_temp{\csname\??framed\currentotrbackground:\c!frame\endcsname}%
     \edef\page_background_temp{\lastnamedcs}%
     \ifx\page_background_temp\v!on
       \page_backgrounds_set_yes
     \else
       \expandafter\expandafter\expandafter\page_backgrounds_check_leftframe
     \fi
   \else
     \expandafter\page_backgrounds_check_leftframe
   \fi}

\def\page_backgrounds_check_leftframe
  {\ifcsname\??framed\currentotrbackground:\c!leftframe\endcsname
    %\edef\page_background_temp{\csname\??framed\currentotrbackground:\c!leftframe\endcsname}%
     \edef\page_background_temp{\lastnamedcs}%
     \ifx\page_background_temp\v!on
       \page_backgrounds_set_yes
     \else
       \expandafter\expandafter\expandafter\page_backgrounds_check_rightframe
     \fi
   \else
     \expandafter\page_backgrounds_check_rightframe
   \fi}

\def\page_backgrounds_check_rightframe
  {\ifcsname\??framed\currentotrbackground:\c!rightframe\endcsname
    %\edef\page_background_temp{\csname\??framed\currentotrbackground:\c!rightframe\endcsname}%
     \edef\page_background_temp{\lastnamedcs}%
     \ifx\page_background_temp\v!on
       \page_backgrounds_set_yes
     \else
       \expandafter\expandafter\expandafter\page_backgrounds_check_topframe
     \fi
   \else
     \expandafter\page_backgrounds_check_topframe
   \fi}

\def\page_backgrounds_check_topframe
  {\ifcsname\??framed\currentotrbackground:\c!topframe\endcsname
    %\edef\page_background_temp{\csname\??framed\currentotrbackground:\c!topframe\endcsname}%
     \edef\page_background_temp{\lastnamedcs}%
     \ifx\page_background_temp\v!on
       \page_backgrou