I want to do some silly Metapost stuff with chapter titles, so set a command to begin with:
\setuphead[chapter][command=\ChapterTitle]
And on that custom command I threw the following to pass both number and title to a MetaPost drawing that should return a separate page:
\unexpanded\def\ChapterTitle#1#2{%
\setMPtext{number}{#1}
\setMPtext{title}{#2}
\startMPpage
\includeMPgraphic{chaptertitle}
\stopMPpage
Said drawing has a background and handles those variables.
\startuseMPgraphic{chaptertitle}{number,title}
StartPage;
fill unitsquare xyscaled( PaperWidth, PaperHeight ) withcolor red;
% Funky typographic stuff with number and title and more graphic thingies
StopPage;
\stopuseMPgraphic
All put together as a MWE:
\showframe
\setuppapersize[A8][A5,landscape]
\setuppaper[nx=4,ny=2]
\setuplayout[page][location=middle,marking=on]
\setuparranging[XY]
\setupbodyfont[8pt]
\startuseMPgraphic{chaptertitle}{number,title}
StartPage;
fill unitsquare xyscaled( PaperWidth, PaperHeight ) withpen pencircle scaled 1bp withcolor red;
StopPage;
\stopuseMPgraphic
\unexpanded\def\ChapterTitle#1#2{%
\setMPtext{number}{#1}
\setMPtext{title}{#2}
\startMPpage
\includeMPgraphic{chaptertitle}
\stopMPpage
}
\setuphead[chapter][command=\ChapterTitle]
\starttext
\startchapter[title={A chapter}]
\input ward
\stopchapter
\startchapter[title={Another chapter}]
\input tufte
\stopchapter
\startchapter[title={Another chapter}]
\input knuth
\stopchapter
\stoptext
I thought the \startMPpage...\stopMPpage
commands must return a separate page, with no layout and adjusted to its drawing's size, but when coupled with the command
key on \setuphead
put the drawing inside a regular page, somewhat aligned to the textarea:
As a workaround, I tried wrapping the code in the custom command with a makeup page, but can't set it to work. If I define a custom makeup, say
\definemakeup[chaptertitle]
and set a layout for it so it would be used automatically with that makeup,
\definelayout[chaptertitle][backspace=\zeropoint,header=\zeropoint,topspace=\zeropoint,margin=\zeropoint]
it will be the same thing, as it seems the layout and the makeup are not coupling, but then I won't know how to make that happen). And if I use the standard makeup just the top offset disappears but can't figure how to get rid of the left one.
And all of that makeup stuff is somewhat hacky. Played around with other arguments on \setuphead
just in case, and (for my surprise) the margin
one did affected the left offset, though it seems the left offset is equal to the backspace width plus something I can't guess. Still a workaround.
Not sure if I'm doing some rookie mistake or missing something silly, but how can I make those MetaPost page titles actually draw themselves as regular \startMPpage...\stopMPpage
s and not within regular pages?