summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/page-spr.mkiv
blob: dc1e013d50d7d6dcbaa6ef33fa694cee5bef65e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
%D \module
%D   [       file=page-spr,
%D        version=2002.11.11,
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Spreading,
%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 / Spreading}

% This module is experimental and not yet official!

\unprotect

\newbox        \b_page_spread_content
\newconditional\c_page_spread_busy
\newconditional\c_page_spread_once     % when true only one flush (writes etc)

% beware, ugly overload, to be redone

\def\normalsettextpagecontent#1#2#3% #2 and #3 will disappear
  {\setbox#1\hbox
     {\setlayoutcomponentattribute{\v!page:\v!text}%
      \vbox \layoutcomponentboxattribute to \textheight
        {\offinterlineskip
         \freezetextwidth
         \hsize\textwidth   % local variant of \sethsize
         \boxmaxdepth\maxdepth
         \noindent             % content can be < \hsize
         \page_otr_command_package_contents#2#3}}%
   \dp#1\zeropoint
   \ifconditional\c_page_spread_busy
      \normalsettextpagecontent_spread{#1}%
   \else
      \normalsettextpagecontent_normal{#1}%
   \fi}

\def\normalsettextpagecontent_normal#1%
  {\setbox#1\hbox to \makeupwidth
     {\hss\box#1\hss}} % never change the \hss's

\def\normalsettextpagecontent_spread#1%
  {\setbox#1\hbox to \makeupwidth
     {\ifvoid\b_page_spread_content
        \ifconditional\c_page_spread_once
          \box#1%
        \else
          \global\setbox\b_page_spread_content\box#1%
          \copy\b_page_spread_content
        \fi
        \hss % left page
      \else
        \hss % right page
        \ifarrangingpages
          % writes don't matter anyway
        \else\ifconditional\c_page_spread_once
          \global\setbox\b_page_spread_content\emptyhbox
          \wd\b_page_spread_content\makeupwidth
          \ht\b_page_spread_content\textheight
        \else
          % writes can interfere (todo: write stripper, but how about hyperlinks)
        \fi \fi
        \box\b_page_spread_content
      \fi}}

\unexpanded\def\page_spread_flush
  {\ifconditional\c_page_spread_busy \ifvoid\b_page_spread_content\else
     % this page will be discarded later
     \emptyhbox \page
   \fi \fi }

\unexpanded\def\startspread
  {\ifdoublesided
     \ifconditional\c_page_spread_busy
       \doubleexpandafter\page_spread_start_nop
     \else
       \doubleexpandafter\page_spread_start_yes
     \fi
   \else
     \expandafter\page_spread_start_nop
   \fi}

\let\stopspread\relax

\unexpanded\def\page_spread_start_yes
  {\bgroup
   \page[\v!left]%
  %\setsystemmode{spread}%
   \settrue\c_page_spread_busy
   \expanded{\setuplayout[\c!textwidth=\the\dimexpr2\textwidth+2\backspace\relax]}%
   \let\stopspread\page_spread_stop_yes}

\unexpanded\def\page_spread_stop_yes
  {\kern\zeropoint
   \page
   \setuplayout[\c!textwidth=\textwidth]
   \page[\v!left]
   \egroup}

\unexpanded\def\page_spread_start_nop
  {\bgroup
   \let\stopspread\page_spread_stop_nop}

\unexpanded\def\page_spread_stop_nop
  {\egroup}

\protect \endinput

% texexec --arr --pdf test
%
% \setuplayout[width=middle]
% \setuppapersize[A4][A3,landscape]
% \setuppagenumbering[alternative=doublesided]
% \setuparranging[2UP]
%
% \starttext
%
% \dorecurse{3}{\input tufte }
%
% \startspread
%   \dorecurse{10}{\input tufte }
% \stopspread
%
% \dorecurse{3}{\input tufte }
%
% \stoptext