Decorative frame for enumeration

Jethro Djan <[email protected]> Sat, 13 Jun 2026 18:45:59 +0000
Newsgroups gmane.comp.tex.context
Message-ID <CAHgnkf9yPC7b=q8Zf+68b1TVbrCJA2Pr_oWjdoxeWXukzKRV=w@mail.gmail.com>
I am going for a design I saw in a high school math text book for
typesetting examples.

But my implementation leaves a little vertical space at the top above the
enumeration title. Also, I have to manually shift the frame. If I zoom in,
I still see that the frame for the header title and the frame it is
contained in are not aligned.

Is there a better way to do this?

MWE:

\startuseMPgraphic{WEFrame}
    numeric w, h ;
    w := OverlayWidth ; h := OverlayHeight ;
    fill (0,0)--(0,h)--(w,h)--(w,0)--cycle withcolor (.93, .96, 1.0) ;
    setbounds currentpicture to unitsquare xyscaled(w,h) ;
\stopuseMPgraphic

\defineoverlay[WEFrame][\useMPgraphic{WEFrame}]

\defineenumeration[WorkedEx]
\setupenumeration[WorkedEx][%
    alternative=top,
    text={Worked Example},
    inbetween={\blank[small]},
    before={\startframedtext[
        frame=off,
        background=WEFrame,
        offset=0pt,
        loffset=8pt,
        boffset=4pt,
        width=max,
    ]},
    after={\stopframedtext},
    headcommand=\WETitleCommand,
]

\startuseMPgraphic{WETitleFrame}
    numeric w, h ;
    w := OverlayWidth ; h := OverlayHeight ;
    fill (0,0)--(0,h)--(w,h)--(w,0)--cycle withcolor (.2, .4, .75) ;
    setbounds currentpicture to unitsquare xyscaled(w,h) ;
\stopuseMPgraphic

\defineoverlay[WETitleFrame][\useMPgraphic{WETitleFrame}]

\define[1]\WETitleCommand{%
    \hskip-8pt
    \framed[frame=off,%
        width=\dimexpr\textwidth-25pt\relax,%
        frame=off,%
        offset=4pt,%
        strut=no,
        background=WETitleFrame,%
        foregroundcolor=white,
        align=flushleft,%
    ]{#1}
}

\starttext

\startWorkedEx
Take the sequence
    \startformula
        2, 8, 14, 20, 26, \ldots
    \stopformula
\stopWorkedEx

\stoptext

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : [email protected] / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________