Difference between revisions of "Odd, even , first page not working"

From Wiki
Jump to navigation Jump to search
m
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
Theoretically, one should be able to use different page layouts for the first, even and odd pages:
+
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:
 
<texcode>
 
<texcode>
 
  % setup layout for first page
 
  % setup layout for first page
Line 32: Line 32:
 
</texcode>
 
</texcode>
  
This code sets up different sizes for each page. However, the text does not flow from one page to the next. For examle, 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.
+
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.
  
<pre>
+
Hans presented [[http://archive.contextgarden.net/message/20050321.003053.1d7975e1.html 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:
 +
<texcode>
 +
\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
|  odd page    |
+
  </texcode>
|                |
+
[[Category:deletemeperhaps]]
|a paragraph from| the preceding page
 
|that is too wide|  for the page.
 
|                |
 
|other paragraphs|
 
|fit fine. they |
 
|fit.
 
|                |
 
------------------
 
</pre>
 

Latest revision as of 03:31, 16 December 2010

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