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.

5
  • Just a question: Do "Lesson 1" and "The visual studio experience" both belong to the same section level? Or is "Lesson 1" a part and "The visual studio experience" a chapter?
    – mickep
    Apr 20, 2022 at 11:25
  • They both belong to the same section level.
    – user213111
    Apr 20, 2022 at 11:31
  • Why don't you try with the eso-pic package?
    – Bernard
    Apr 20, 2022 at 11:54
  • @Bernard This question is about ConTeXt. Apr 20, 2022 at 12:59
  • @HenriMenke: I should have read all details in the question…
    – Bernard
    Apr 20, 2022 at 13:59

1 Answer 1

4

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.

7
  • 1
    Impressive! Thank you! Can I ask you where did you find that out and where I can learn more about it?
    – user213111
    Apr 20, 2022 at 16:03
  • 1
    I updated with a link to the testsuite (Hans pointed me in that direction)
    – mickep
    Apr 20, 2022 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!
    – user213111
    Apr 20, 2022 at 16:35
  • 1
    Ah, then one needs placehead=yes. I'll update.
    – mickep
    Apr 20, 2022 at 16:39
  • Oh, of course! Stupid me! It works perfectly!
    – user213111
    Apr 20, 2022 at 16:45

You must log in to answer this question.