Odd, even , first page not working

From Wiki
Revision as of 03:31, 16 December 2010 by Jstein (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

One is able to use different page layouts for the first, even and odd pages, but when it comes to varying text widths, ConTeXt doesn't adapt the paragraph width at a page boundary:

 % setup layout for first page
 \definelayout[1][
  leftmargin=25mm,
  rightmargin=30mm,
  cutspace=50mm,
  backspace=40mm,
  height=fit,
  width=fit,
 ]

 \definelayout[even][
  leftmargin=30mm,
  rightmargin=25mm,
  cutspace=50mm,
  backspace=40mm,
  height=fit,
  width=fit,
  ]

 \definelayout[odd][
  leftmargin=25mm,
  rightmargin=30mm,
  cutspace=50mm,
  backspace=40mm,
  height=fit,
  width=fit,
  ]

\setuplayout

This code sets up different sizes for each page. However, the text does not flow from one page to the next. For example, if the even pages is very wide, and the odd page is narrow, then a paragraph starting on the even page and continuing on the odd page will run over.

Hans presented [a workaround] on the mailing list, with the caveat that it's "for novels only", meaning, no display math or floats. Consider yourself warned if you expect this to work beyond what's specified:

\startsetups [grid] [*default]
  \nopenalties
\stopsetups

\setuppagenumbering
  [alternative=doublesided]

\setuplayout
  [grid=yes]

\definelayout
  [odd]
  [width=10cm,
   lines=40]

\definelayout
  [even]
  [width=8cm,
   lines=40]

\setuplayout
  [odd]

\setuptolerance
  [verytolerant]

\showframe

\def\SetLineWidths
  {\scratchtoks \emptytoks
   \ifdim\pagegoal=\maxdimen
     \scratchdimen\textheight
     \ifodd\realpageno
       \noflines\namedlayoutparameter{odd}{lines}%
     \else
       \noflines\namedlayoutparameter{even}{lines}%
     \fi
   \else
     \scratchdimen\dimexpr\pagegoal-\pagetotal\relax
     \advance\scratchdimen-\topskipgap
     \getnoflines\scratchdimen
   \fi
   \ifdim\scratchdimen<\lineheight
     \page
   \else
     \scratchcounter\noflines\relax
     \ifodd\realpageno
       \doSetLineWidths{odd}{even}%
     \else
       \doSetLineWidths{even}{odd}%
     \fi
     \parshape \scratchcounter \the\scratchtoks \relax \ignorespaces
   \fi}

\def\doSetLineWidths#1#2%
  {\dorecurse\noflines
     {\appendetoks 0cm \namedlayoutparameter{#1}{width} \to\scratchtoks}%
   \dorecurse{2}
     {\advance\scratchcounter\namedlayoutparameter{#2}{lines}\relax
      \dorecurse{\namedlayoutparameter{#2}{lines}}
        {\appendetoks 0cm \namedlayoutparameter{#2}{width} \to\scratchtoks}%
      \advance\scratchcounter\namedlayoutparameter{#1}{lines}\relax
      \dorecurse{\namedlayoutparameter{#1}{lines}}
        {\appendetoks 0cm \namedlayoutparameter{#1}{width} \to\scratchtoks}}}

\dontcomplain

\EveryPar{\SetLineWidths}

\starttext

\dorecurse{25}{\dorecurse{4}{\input tufte }\par}

\stoptext