4

I am trying to reproduce something like this for parts and chapters with MetaFun:

Screenshot from 'Get Programming with F#' by Isaac Abraham

Placing the content on the page is simple so I am trying to get the colored background. However I do not know how to have it on the whole page...

My first attempt was to setup an alternative with an MPpage:

\setuppapersize[A6][A6]
\startsetups[partHeadRendering]
  \startMPpage
    StartPage ;
numeric w ; w := bbwidth(Page) ;
numeric h ; h := bbheight(Page) ;

fill (unitsquare xyscaled (w,h)) withcolor \MPcolor{darkred} ;
StopPage ;

\stopMPpage \stopsetups

\defineheadalternative[partrenderer][alternative=vertical, renderingsetup=partHeadRendering]

\setuphead[part][alternative=partrenderer, placehead=yes]

\showframe \starttext \startpart \stoppart \stoptext

But...

Then I tried to use MPgraphic with an overlay as shown in the cover page wiki

\setuppapersize[A6][A6]

\startuseMPgraphic{PartCover} \startMPpage StartPage ; fill Page withcolor \MPcolor{darkred} ; StopPage ; \stopMPpage \stopuseMPgraphic

\defineoverlay[PartCover][\useMPgraphic{PartCover}]

\startsetups[partHeadRendering] \setupbackgrounds[page][background=PartCover] \stopsetups

\defineheadalternative[partrenderer][alternative=vertical, renderingsetup=partHeadRendering]

\setuphead[part][alternative=partrenderer, placehead=yes]

\showframe \starttext \startpart \stoppart \stoptext

but it did not go well either...

I also did take a look at this this but I got the same result as the first one.

1 Answers1

3

I have learned today that you can work with a partpage mode and a layer that is only filled with content for part pages. Something like the following.

Define the MetaFun background:

\startuseMPgraphic{part}
StartPage ;
  fill Page withcolor 0.25[white,darkcyan] ;
  picture p, q ;
  p := textext("\ss\bf\setstrut\strut\getmarking[partnumber]") scaled 14 ;
  q := textext("\ss\bf\setstrut\strut Lesson") scaled 2 ;

p := (p shifted - center p) ; q := (q shifted - center q) ;

draw image ( draw p withcolor white ; draw q ; ) shifted urcorner Field[Text][Text] shifted - urcorner p ; StopPage ; \stopuseMPgraphic

Define a layer, an overlay (that uses a \directsetup that is introduced in the next step), and set the background to use them.

\definelayer[part][width=\paperwidth, height=\paperheight]
\defineoverlay[pagebackground][\directsetup{pagebackground}]
\setupbackgrounds[page][background=pagebackground]

Add the just mentioned setup. It checks if you are in the partpage, and if you are, it updates the content of the layer with \setlayer, and then it disables the partpage mode (if not, you will get the layer on the upcoming pages as well). Then place the layer.

\startsetups pagebackground
\doifelsemode {partpage} {
  \setlayer[part][preset=lefttop]{\useMPgraphic{part}}
  \globaldisablemode[partpage]
  }{}
\placelayer[part]
\stopsetups

We add another setup that enables the partpage mode and pushes the content of the part page.

\startsetups part:before
\globalenablemode[partpage]
\blank[force,20*line]
\stopsetups

Finally we set up the part. The important thing for us here is the before key that enables the partpage mode so that the pagebackground kicks in. I added also a style.

\setuphead[part][
  number=no,
  placehead=yes,
  header=high,
  before=\setup{part:before},
  style={\definedfont[SansBold at 18pt]\WORD},
]

Then we are ready for content. I switched font to dejavu, but you of course have another favorite to use.

\setupbodyfont[dejavu]

\starttext \startpart[title={The visual studio experience}] \dorecurse{20}{\samplefile{ward}} \stoppart \stoptext

Adding all this together gives the following first two pages.

the first two pages showing the result

Edit

Two comments. The code

\startuseMPgraphic{PartCover}
  \startMPpage
    StartPage ;
    fill Page withcolor \MPcolor{darkred} ;
    StopPage ;
  \stopMPpage
\stopuseMPgraphic

that you suggest is invalid. If \startMPpage and \stopMPpage are removed it will look better.

Additionally, there is a testsuite that contains a lot of nice examples. In this specific case the toggles-001.tex in the backgrounds folder.

mickep
  • 8,685
  • 1
    Impressive! Thank you! Can I ask you where did you find that out and where I can learn more about it? –  Apr 20 '22 at 16:03
  • 1
    I updated with a link to the testsuite (Hans pointed me in that direction) – mickep Apr 20 '22 at 16:07
  • Just to have a complete answer to the question: you stated that you use chapters instead of parts here. Let's say I want to reuse this for parts, does it means that I just have to replace every occurrence of chapter with part? But when I do this, it does not seems to work. I guess I miss something obvious. Anyway, thank you very much for this! –  Apr 20 '22 at 16:35
  • 1
    Ah, then one needs placehead=yes. I'll update. – mickep Apr 20 '22 at 16:39
  • Oh, of course! Stupid me! It works perfectly! –  Apr 20 '22 at 16:45
  • I'm reusing your answer to a section I have created. When I comment out \globaldisablemode[mysectionpage] in your pagebackground setup the background applied to the whole mysection. This is great. However, the background never ends and continues when exiting the mysection. I thought that putting \globaldisablemode[mysectionpage] in the else part of the \doifelsemode would do the trick but it seems it does not work like that. Do you know what should I do? –  Sep 21 '22 at 19:16
  • Not sure I get what you are trying to do. Can you please ask a new question (you can link to this question) and explain more. Perhaps by showing your code and what you get, it will be easier to understand. – mickep Sep 21 '22 at 19:29