#StackBounty: #titles #context #metapost #context-lmxt ConTeXt LMTX: Offset on page titles with MetaPost

Bounty: 100

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:

unexpandeddefChapterTitle#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

unexpandeddefChapterTitle#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:

Output of MWE

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...stopMPpages and not within regular pages?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.