9

Most of the pages in my document look like this, a layout common in books:

 ___________________________
|             |             |
| Title       | ........... |
|             | ........... |
|  .......... | ........... |
| ........... | ........... |
| ........... | ........... |
| ........... | ........... |
| ........... | ........... |
| ........... | ........... |
|      1      |      2      |
|_____________|_____________|

I have some special pages in which I hope the contents will span across the left and right page.

  • The paper is essentially treated like one wide A3 page, except page numbers remain unchanged.
  • The margins are identical to above, but there are no margins in the fold of the book.
  • Even chapter and section titles should span.

Most pages in the book do not span in this way.

 ___________________________
|             |             |
| The Title Goes Across Too |
|             |             |
|  ........................ |
| ......................... |
| ......................... |
| ......................... |
| ......................... |
| ......................... |
|      1      |      2      |
|_____________|_____________|

How can I span the content of some pages across two pages in this manner?

Dave Jarvis
  • 11,809
Village
  • 13,603
  • 23
  • 116
  • 219
  • 1
    Isn't this just the same as adding a A3 page in between? – Aditya Jan 16 '13 at 05:33
  • That is better if the solution creates a PDF with independent A4 pages, as the people who print my documents will be confused by an A3 page in the middle of the document. – Village Jan 16 '13 at 09:49
  • Are you ok with a word (or even a letter) split across the page boundary? Also keep in mind that most prknters cannot print until the edge of the paper. – Aditya Jan 16 '13 at 13:08
  • Yes, that is no problem if the words or letters are split at the page boundary. – Village Jan 17 '13 at 02:02

1 Answers1

6

If your two page spread has no floats, then you can simply store the content in a box, and split the box into two.

% The default layout
\setuplayout[cutspace=1in, backspace=1in, width=middle]

% The layout for left and right page. ConTeXt treats cutspace=0pt as a signal
% to set cutspace=backspace. So, I use cutspace=1sp (the smallest non-zero 
% space in TeX.
\definelayout[leftpage] [cutspace=1sp, backspace=1in, width=middle]
\definelayout[rightpage][cutspace=1in, backspace=1sp, width=middle]

% A box to store the content
\newbox\twopagebox

% A frame to typeset the content. 
\defineframed
    [twopageframe]
    [
      width=\the\dimexpr2\paperwidth-2\backspace,
      height=\textheight,
      align=normal,
      frame=off,
    ]

% An environment to gather the data, typeset it in a box, and then split 
% the box.
%
% A buffer is not needed here, as we can directly typeset the material in 
% a box.
\unexpanded\def\starttwopagemakeup
    {\grabbufferdata[twopagebuffer][starttwopagemakeup][stoptwopagemakeup]}

\unexpanded\def\stoptwopagemakeup
    {\setbox\twopagebox\hbox{\twopageframe{\getbuffer[twopagebuffer]}}%
     \page[right]%
     \setuplayout[leftpage]%
     \clip[nx=2, ny=1, x=1]{\copy\twopagebox}%
     \page
     \setuplayout[rightpage]%
     \clip[nx=2, ny=1, x=2]{\copy\twopagebox}%
     \page
     \setuplayout[reset]}

\setupbackgrounds[page][frame=on, framecolor=red]
% To visualize the page border

\starttext
  \dorecurse{6}{\input knuth \endgraf}
\starttwopagemakeup
  \chapter {Two page data}
  \dorecurse{6}{\input knuth \endgraf}
\stoptwopagemakeup
  \dorecurse{6}{\input knuth \endgraf}

\stoptext

which gives

enter image description here

Note I have deliberately included space between the pages when combining the pages together to show the image here.

This solution only works for a single page. If you want support for multiple pages, then you need to store the content as a \vbox and keep \vspliting it until no material is left. For example,

% The default layout
\setuplayout[cutspace=1in, backspace=1in, width=middle]

% The layout for left and right page. ConTeXt treats cutspace=0pt as a signal
% to set cutspace=backspace. So, I use cutspace=1sp (the smallest non-zero 
% space in TeX.
\definelayout[leftpage] [cutspace=1sp, backspace=1in, width=middle]
\definelayout[rightpage][cutspace=1in, backspace=1sp, width=middle]

% A box to store the content
\newbox\twopagebox
\newbox\contentbox

\unprotect
% An environment to gather the data, typeset it in a box, and then split 
% the box.

\unexpanded\def\starttwopagemakeup
    {\setbox\contentbox\vbox\bgroup
        \hsize\the\dimexpr2\paperwidth-2\backspace\relax}

\unexpanded\def\stoptwopagemakeup
    {\egroup
     \typeset_all_pages}

\def\typeset_all_pages
    {\ifvoid\contentbox
       % Done
     \else\ifdim\ht\contentbox>\textheight
        \setbox\twopagebox\vsplit\contentbox to \textheight
           \typeset_one_page\twopagebox
           \typeset_all_pages
         \else
            \typeset_one_page\contentbox
         \fi
      \fi}

\def\typeset_one_page#1% box
   {\page[right]%
     \setuplayout[leftpage]%
     \clip[nx=2, ny=1, x=1]{\copy#1}%
     \page
     \setuplayout[rightpage]%
     \clip[nx=2, ny=1, x=2]{\copy#1}%
     \page
     \setuplayout[reset]}

\protect

\setupbackgrounds[page][frame=on, framecolor=red]
% To visualize the page border

\setuphead[chapter][page=] % Otherwise we get an extra page

\starttext
\starttwopagemakeup
  \chapter{One}
  \dorecurse{12}{\input knuth \relax}
\stoptwopagemakeup

\chapter{Normal Text}
\dorecurse{12}{\input ward \endgraf}


\stoptext

This uses low-level TeX (as splitting pages is effectively equal to writing an output routine). See TeX by Topic for details.

Aditya
  • 62,301