* [NTG-context] Verbatim Textbox with Reference NUmbering
@ 2023-09-09 13:58 Jeroen
0 siblings, 0 replies; only message in thread
From: Jeroen @ 2023-09-09 13:58 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 2404 bytes --]
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
[-- Attachment #1.2: Type: text/html, Size: 2778 bytes --]
[-- Attachment #2: Type: text/plain, Size: 495 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-09-09 14:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-09 13:58 [NTG-context] Verbatim Textbox with Reference NUmbering Jeroen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox