3

In order to finish my whole background series, I am trying to figure out how to set the background for only the first two pages of heads (part, chapter, whatever). Here is an example I found from a french book

enter image description here

As you can see, the first two pages could probably be a super head level with the "two pages background" (or just a SVG graphic, but let's say it is not) and then, the part and chapter pages are back to default background. This is what I am currently trying to get.

To do that I have investigate through some links : first of all, a previous answer of mickep allowing me to change the background of the first page of the structure. Without any real modification, this is what we get from it:

\definemeasure[PartPaperWidth][\paperwidth]
\definemeasure[PartPaperHeight][\paperheight]

\startuseMPgraphic{PartBackgroundGraphic}
  path background;
  background := origin -- (2*\measure{PartPaperWidth},0cm) --
                          (2*\measure{PartPaperWidth},\measure{PartPaperHeight}) --
                          (0cm,\measure{PartPaperHeight}) --
                cycle ;
  fill background withcolor 0.3[white,red] ;
\stopuseMPgraphic

\definelayer[PartBackgroundLayer][width=\paperwidth, height=\paperheight]
\defineoverlay[PartBackgroundOverlay][\directsetup{PartBackgroundSetup}]
\setupbackgrounds[page][background=PartBackgroundOverlay]

\startsetups PartBackgroundSetup
\doifelsemode {partpage} {
  \setlayer[PartBackgroundLayer][preset=lefttop]{\useMPgraphic{PartBackgroundGraphic}}
  \globaldisablemode[partpage]
  }{}
\placelayer[PartBackgroundLayer]
\stopsetups

\startsetups part:before
\globalenablemode[partpage]
\stopsetups

\setuphead[part][
  number=no,
  placehead=yes,
  header=high,
  before=\setup{part:before},
]

\starttext
\startpart[title={An awesome title}]
  \dorecurse{20}{\samplefile{ward}}

\startpart[title={An awesome title}]
  \dorecurse{20}{\samplefile{ward}}
\stoppart
\stoptext

enter image description here

As one can observes, we only do get the left part of the graphic on the left page and the right part of the graphic does not appear on the right page.

In order to do that, I tried the following from Wolfgang Schuster and Dave Jarvis in this link which allows me to span the background on two pages.

To implement that in my case I changed a little bit of the PartBackgroundSetup, like so

\startsetups PartBackgroundSetup
\doifelsemode {partpage} {
  \setlayer[PartBackgroundLayer][y=.0\paperheight]
    {\clip[nx=2,x=\doifelseoddpage{1}{2}]
      {\useMPgraphic{PartBackgroundGraphic}}}
    \globaldisablemode[partpage]
  }{}
\placelayer[PartBackgroundLayer]
\stopsetups

Then, there is two possible output depending if I do use or if I do not use \globaldisablemode[partpage]. If I do use it I get

enter image description here

and if I do not use it I get

enter image description here

At some point Aditya gives me an idea: what if I use a page counter to exit partmode after the second page? Yeah, it sounds great, let's do that!

\definecounter[PartPageCounter][way=bypage]

\startsetups PartBackgroundSetup
\doifelsemode {partpage} {
  \setlayer[PartBackgroundLayer][y=.0\paperheight]
    {\clip[nx=2,x=\doifelseoddpage{1}{2}]
      {\useMPgraphic{PartBackgroundGraphic}}}
    \ifnum\rawcountervalue[PartPageCounter]>2\globaldisablemode[partmode]\fi
  }{}
\placelayer[PartBackgroundLayer]
\stopsetups

\startsetups part:before
\globalenablemode[partpage]
\setcounter[PartPageCounter][1]
\stopsetups

and... it did not work.

How can I make that background appears only on the first two pages of a new head (part, chapter, etc.)?

2
  • Maybe you can use \startpostponing? Commented Sep 28, 2022 at 18:15
  • You are not incrementing the counter! But even if you did, way=bypage means that the counter gets reset at every page!
    – Aditya
    Commented Sep 29, 2022 at 5:14

1 Answer 1

2

Here is one idea: At the start of every page, save the value of \realpageno at the beginning of each section, and then disable the partpage mode whenever \realpageno=\LastPart+2.

\definemeasure[PartPaperWidth][\paperwidth]
\definemeasure[PartPaperHeight][\paperheight]

\startuseMPgraphic{PartBackgroundGraphic}
  path background;
  background := origin -- (2*\measure{PartPaperWidth},0cm) --
                          (2*\measure{PartPaperWidth},\measure{PartPaperHeight}) --
                          (0cm,\measure{PartPaperHeight}) --
                cycle ;
  fill background withcolor 0.3[white,red] ;
\stopuseMPgraphic

\definelayer[PartBackgroundLayer][width=\paperwidth, height=\paperheight]
\defineoverlay[PartBackgroundOverlay][\directsetup{PartBackgroundSetup}]
\setupbackgrounds[page][background=PartBackgroundOverlay]

\permanent\countdef\LastPart\zerocount

\startsetups PartBackgroundSetup
\doif{\the\realpageno}{\the\numexpr\LastPart+2\relax}
  {\globaldisablemode[partpage]}
\doifelsemode {partpage} {
  \setlayer[PartBackgroundLayer][y=.0\paperheight]
    {\clip[nx=2,x=\doifelseoddpage{1}{2}]
      {\useMPgraphic{PartBackgroundGraphic}}}
  }{}
\placelayer[PartBackgroundLayer]
\stopsetups

\startsetups part:before
\globalenablemode[partpage]
\LastPart=\realpageno\relax
\stopsetups

\setuphead[part][
  number=no,
  placehead=yes,
  header=high,
  before=\setup{part:before},
]

\starttext
\startpart[title={An awesome title}]
  \dorecurse{40}{\samplefile{ward}}

\startpart[title={An awesome title}]
  \dorecurse{40}{\samplefile{ward}}
\stoppart
\stoptext

You must log in to answer this question.