This is a longshot, but would be great to have. Below I have at MWE1 the verbatim codefragment textbox I am using. I found in the forum MWE2 which is a textbox with an automatic reference number. Is there a way to get the same for MWE1 with automatic reference numbering like 1.1, 1.2 etc for chapter 1, codefragment 1, 2 etc. with the possibility that in the text I can refer to the codefragment like \in{codefragment\space}[code:ccpsample] similar as to tables and figures? Thanks Jeroen %%%%%%%%%%%%%%%%%% % MWE1 %%%%%%%%%%%%%%%%%% \startuseMPgraphic{mpos:par:myexample} path p; for i = 1 upto nofmultipars : p := multipars[1] topenlarged 4pt bottomenlarged 4pt cornered 2mm ; fill p withcolor 0.95white ; draw p withcolor black withpen pencircle scaled \MPvar{linewidth}; endfor; \stopuseMPgraphic \definetextbackground [listingbackground] [state=start, mp=mpos:par:myexample, location=paragraph, topoffset=0.4em, leftoffset=0em, rulethickness=0.7pt] \definetyping[Listing] [option=commands] \setuptyping [Listing] [bodyfont=10pt, margin=1em, before=% {\blank[3*medium] \setupinterlinespace[line=2.4ex] \starttextbackground[listingbackground]}, after=% {\stoptextbackground \blank[4*medium]}, align={flushleft,verytolerant}] \starttext \startListing this is a code example \stopListing \stoptext %%%%%%%%%%%%%%%%%% % MWE2 %%%%%%%%%%%%%%%%%% \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}{\hbox spread 1em{\hss\strut#1\hss}}} \setMPtext{FunnyFrame}{} % Add the enumeration \defineenumeration [Counter] [text=, alternative=empty, before={\FrameTitle{Counter \getnumber[Counter]} \startFunnyText}, after={\stopFunnyText}] \starttext \startCounter First example \stopCounter \startCounter Second example \stopCounter \stoptext