# ConTeXt and Metafun: Framed enumeration with counter as part of overlay

How do you make an enumeration where the enumeration counter appears within a frame decorated with Metafun?

The idea is to have something similar to an example on pg. 144 of the Metafun manual:

Except that "Zapf (1)" would be a counter rather a manual label.

Here is the code that reproduces the example with the manual frame:

\startuseMPgraphic{FunnyFrame}
picture p ; numeric w, h, o ;
p := textext.rt(\MPstring{FunnyFrame}) ;
w := OverlayWidth ; h := OverlayHeight ; o := BodyFontSize ;
p := p shifted (2o,h-ypart center p) ; draw p ;
drawoptions (withpen pencircle scaled 1pt withcolor .625red) ;
draw (2o,h)--(0,h)--(0,0)--(w,0)--(w,h)--(xpart urcorner p,h) ;
draw boundingbox p ;
setbounds currentpicture to unitsquare xyscaled(w,h) ;
\stopuseMPgraphic

\defineoverlay[FunnyFrame][\useMPgraphic{FunnyFrame}]
\defineframedtext[FunnyText][frame=off,background=FunnyFrame]
\def\StartFrame{\startFunnyText}
\def\StopFrame {\stopFunnyText }
\def\FrameTitle#1%
\setMPtext{FunnyFrame}{}

\starttext

\FrameTitle{Zapf (1)}
\StartFrame
Coming back to the use of typefaces in electronic
publishing: many of the new typographers receive their
knowledge and information about the rules of typography from
books, from computer magazines or the instruction manuals
which they get with the purchase of a PC or software.
\StopFrame

\stoptext


I was able to make enough progress to add an answer to this problem, but I'm still unsure if it's the right way to go.

Use \wrappedcurrentconstruction instead of MPstring/MPtext. With \wrappedcurrentconstruction, the references also work correctly.

\startuseMPgraphic{FunnyFrame}
picture p ; numeric w, h, o ;
p := textext.rt("\wrappedcurrentconstruction");

w := OverlayWidth ; h := OverlayHeight ; o := BodyFontSize ;
p := p shifted (2o,h-ypart center p);
draw p ;

path b;
b := boundingbox p enlarged (o/10);

drawoptions (withpen pencircle scaled 1pt withcolor .625red) ;
draw (2o,h)--(0,h)--(0,0)--(w,0)--(w,h)--(xpart urcorner b,h) ;
draw b;

setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic

\defineoverlay[FunnyFrame][\useMPgraphic{FunnyFrame}]

\defineframedtext
[FunnyFramedText]
[
frame=off,
background=FunnyFrame,
offset=\bodyfontsize,
width=\textwidth,
]

\defineenumeration[Counter]
[
alternative=empty,
before=\startFunnyFramedText,
after=\stopFunnyFramedText,
]

\starttext
\startCounter
Coming back to the use of typefaces in electronic
publishing: many of the new typographers receive their
knowledge and information about the rules of typography from
books, from computer magazines or the instruction manuals
which they get with the purchase of a PC or software.
\stopCounter

\startCounter
Coming back to the use of typefaces in electronic
publishing: many of the new typographers receive their
knowledge and information about the rules of typography from
books, from computer magazines or the instruction manuals
which they get with the purchase of a PC or software.
\stopCounter
\stoptext


Effectively, the answer relies on referencing the counter within the frame using \getnumber and omitting the default enumeration label.

% Code from manual
\startuseMPgraphic{FunnyFrame}
picture p ; numeric w, h, o ;
p := textext.rt(\MPstring{FunnyFrame}) ;
w := OverlayWidth ; h := OverlayHeight ; o := BodyFontSize ;
p := p shifted (2o,h-ypart center p) ; draw p ;
drawoptions (withpen pencircle scaled 1pt withcolor .625red) ;
draw (2o,h)--(0,h)--(0,0)--(w,0)--(w,h)--(xpart urcorner p,h) ;
draw boundingbox p ;
setbounds currentpicture to unitsquare xyscaled(w,h) ;
\stopuseMPgraphic

\defineoverlay[FunnyFrame][\useMPgraphic{FunnyFrame}]
\defineframedtext[FunnyText][frame=off,background=FunnyFrame]
\def\FrameTitle#1%
\setMPtext{FunnyFrame}{}

\defineenumeration
[Counter]
[text=,
alternative=empty,
before={\FrameTitle{Counter \getnumber[Counter]}
\startFunnyText},
after={\stopFunnyText}]

\starttext

\startCounter
Coming back to the use of typefaces in electronic
publishing: many of the new typographers receive their
knowledge and information about the rules of typography from
books, from computer magazines or the instruction manuals
which they get with the purchase of a PC or software.
\stopCounter

\startCounter
Coming back to the use of typefaces in electronic
publishing: many of the new typographers receive their
knowledge and information about the rules of typography from
books, from computer magazines or the instruction manuals
which they get with the purchase of a PC or software.
\stopCounter

\stoptext


Edit: Replaced alternative=inleft with alternative=empty as per comment.

The result:

• You can use alternative=empty instead of alternative=inleft. The alternative=empty only sets the style and color of the title text. – Aditya Jul 2 '18 at 13:43