ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Jeroen <contextntg@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: [NTG-context] Verbatim Textbox with Reference NUmbering
Date: Sat, 9 Sep 2023 15:58:44 +0200	[thread overview]
Message-ID: <CAPtmdbOogA1_Rn=_uvE4JuJM97wMS66g77FeaFuXEj5VCu0DUA@mail.gmail.com> (raw)


[-- 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
___________________________________________________________________________________

                 reply	other threads:[~2023-09-09 14:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPtmdbOogA1_Rn=_uvE4JuJM97wMS66g77FeaFuXEj5VCu0DUA@mail.gmail.com' \
    --to=contextntg@gmail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).