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
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
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
and if I do not use it I get
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.)?



\startpostponing? – Max Chernoff Sep 28 '22 at 18:15way=bypagemeans that the counter gets reset at every page! – Aditya Sep 29 '22 at 05:14