5

Following instructions here, I have a new section mysection. On this new section I want to apply a background created with MetaPost; for the sake of the question let's say this background is simply

\startuseMPgraphic{mysection}
  StartPage ;
  fill Page withcolor green ;
  StopPage ;
\stopuseMPgraphic

So, in order to apply the the background to the section I remembered that answer and start playing around with it. I commented out \globaldisablemode[mysectionpage] in the pagebackground setup and obtained the wanted green background on all the pages after startmysection is used.

Let me show you in an example.

\defineresetset[myreset][][0]

\definehead[mysection][section=section-8, sectionresetset=myreset]
\setuplist[mysection][numbersegments=mysection]




\startuseMPgraphic{mysection}
StartPage ;
  fill Page withcolor green ;
StopPage ;
\stopuseMPgraphic

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

\startsetups pagebackground
\doifelsemode {mysectionpage} {
  \setlayer[mysection][preset=lefttop]{\useMPgraphic{mysection}}
  %\globaldisablemode[mysectionpage]           <--------------------------
  }{}
\placelayer[mysection]
\stopsetups

\startsetups mysection:before
\globalenablemode[mysectionpage]
\stopsetups

\setuphead[mysection][before={\page[yes]\setup{mysection:before}}]
\setuphead[section][before={\page[yes]}]




\starttext
\startsection[title=Section]
  \dorecurse{3}{\input knuth}
\stopsection

\startmysection[title=My Section]
  \dorecurse{15}{\input ward}
\stopmysection

\startsection[title=Section]
  \dorecurse{3}{\input knuth}
\stopsection
\stoptext

enter image description here

As you can see, the background is applied on every pages after of the document after \startmysection. That is the good part of the experiment. However, what I want to achieve is to have the background applied only on all the mysection pages, not other section leveling. So the last page with a regular section should have a white background.

I tried to put \globaldisablemode[mysectionpage] in the else part of \doifmodeelse

\doifelsemode {mysectionpage} {
  \setlayer[mysection][preset=lefttop]{\useMPgraphic{mysection}}
  }{\globaldisablemode[mysectionpage]}

and it did not work. Then I tried to create a setup for after:

\startsetups mysection:after
  \globaldisablemode[mysectionpage]
\stopsetups

it did not work either.

Then I thought I could move sections one level bellow to create mysection:

  \definehead[mysection][section=section-3,sectionreset=mysectionreset]
  \definehead[section][section=section-4,sectionreset=sectionreset]
  \definehead[subsection][section=section-5,sectionreset=subsectionreset]
  ...

and apply the same things. Did not work either.

2 Answers 2

2

Like this?

\startuseMPgraphic{chapterbackground}
  if \somenamedheadnumber{mysec}{current} > 0 :
    fill Page withcolor green;
  fi;
\stopuseMPgraphic

\defineoverlay[chapterbackground][\useMPgraphic{chapterbackground}]
\setupbackgrounds[page][background=chapterbackground]

\definehead[mysec][section]

\starttext
  \dorecurse{5}{
    \startchapter \input ward \stopchapter \page
    \startmysec \input knuth \stopmysec \page
    \startmysec \input knuth \stopmysec \page
    \startchapter \input ward \stopchapter 
  }
\stoptext
1
  • 1
    I marked your answer as accepted but note that \definehead[mysec][section] change the background of every page containing a section. To make it works as intended in my question, we have to move sections around \definehead[mysec][section=section-3] \definehead[section][section=section-4] ... or to define mysec directly as section-8: \definehead[mysec][section=section-8].
    – user213111
    Commented Sep 22, 2022 at 11:48
1

It is not clear what should happen when there are subsections inside a mysection. I am assuming that the coloring should continue, as technically you are still inside mysection.

My idea is same as Dave Jarvis, but instead of using currentheadnumber, I simply check the status of a flag. I am not assuming that mysection starts or ends a page (although that is true in the example below), so I simply disable the flag after the page body has been constructed.

\startuseMPgraphic{chapterbackground}
  StartPage;
  if \InsideMySection == 1 :
    fill Page withcolor green;
  fi;
  % label("\InsideMySection", center Page);
  StopPage;
\stopuseMPgraphic

\defineoverlay[chapterbackground][\useMPgraphic{chapterbackground}]
\setupbackgrounds[page][background=chapterbackground]

\edef\InsideMySection{0}

\definehead[mysection][section]
           [
             page=yes,
             beforesection={\edef\InsideMySection{1}},
             aftersection={\appendtoks\gdef\InsideMySection{0}\to\everyafterpagebody},
          ]


\define\information{\InsideMySection}

\starttext
  \dorecurse{5}{
    \startchapter \information \input ward \stopchapter 
    \startmysection 
      \information \input knuth 
      \startsubsection \information \input ward \stopsubsection 
    \stopmysection 
    \startsection \information \input ward \stopsection 
    \startmysection \information \input knuth \stopmysection 
    \startsection \information \input ward \stopsection 
    \startchapter \information \input ward \stopchapter 
  }
\stoptext
1
  • Interesting. This idea of yours makes me wonder if it is possible to keep track of the current page number we are in mysection (page 1 of mysection, page 2 of mysection) and stop it at a predefined number (even if we do not have reach the end of it.)
    – user213111
    Commented Sep 24, 2022 at 14:04

You must log in to answer this question.