1

I'm not sure how to combine line numbering with a background in a typing environment.

Here's what I'm trying to achieve: Desired Output

Here's a minimal example of what I'm trying:

\starttext
\startbackground[frame=on,background=off]
  \startlinenumbering
    \starttyping
Phasellus neque orci, porta a, aliquet quis, semper a, massa.
Etiam laoreet quam sed arcu.
In id erat non orci commodo lobortis.
    \stoptyping
  \stoplinenumbering
\stopbackground
\stoptext

When I compile this, I get typing in a background, but no line numbers:

enter image description here

However, if I remove the background from the block line numbers appear as expected.

I can get essentially what I want with the framedtext environment but then I can't break across pages:

\starttext
\startframedtext[frame=on,background=off,width={\hsize},frameoffset=2em]
  \startlinenumbering
    \starttyping
Phasellus neque orci, porta a, aliquet quis, semper a, massa.
Etiam laoreet quam sed arcu.
In id erat non orci commodo lobortis.
    \stoptyping
  \stoplinenumbering
\stopframedtext
\stoptext

enter image description here

I can also get line numbers to show up if I wrap the text in a textbackground, but then I'm not able to get the background to extend around the line numbers:

\starttext
\definetextbackground
  [MyBackground]
  [framecolor=black,
   location=always,
   background=off]
\starttextbackground[MyBackground]
  \startlinenumbering
    \starttyping
Phasellus neque orci, porta a, aliquet quis, semper a, massa.
Etiam laoreet quam sed arcu.
In id erat non orci commodo lobortis.
    \stoptyping
  \stoplinenumbering
\stoptextbackground
\stoptext

enter image description here

Is there any way to achieve the result in the first image such that the typing can break across pages?

7
  • Do you really need \starttyping .. \stoptyping? If you want a typewriter font, \tt should suffice. Typing environments are for verbatim text.
    – user226564
    Commented Jan 30, 2021 at 20:08
  • Unfortunately yes, I need syntax highlighting and the other typing environment features. Commented Jan 30, 2021 at 20:15
  • 1
    I think you could use the vim module by Aditya Mahajan instead. See an example here: tex.stackexchange.com/questions/537289/…
    – user226564
    Commented Jan 30, 2021 at 20:20
  • I was originally using the vim module and had the same problem. I posed the question about the typing environment because I thought it would have a wider reach. Commented Jan 30, 2021 at 20:22
  • \setuplinenumbering[location=text]?
    – user226564
    Commented Jan 30, 2021 at 20:30

2 Answers 2

4

Just for the record, the following works:

\starttext
\setuplinenumbering[location=text]
\definetextbackground
  [MyBackground]
  [framecolor=black,
   location=always,
   background=off]
\startMyBackground
\startlinenumbering
%For testing only
\dorecurse{2}{\typefile{\jobname.tex}}
\stoplinenumbering
\stopMyBackground
\stoptext

enter image description here

0

I've done some additional digging through manuals and examples and I found a solution using MetaPost. This provides a lot of flexibility at the cost of being more difficult to understand.

\startuseMPgraphic{MyMPBackground}
  begingroup; save lftbdry, rtbdry, parframe;
  for i=1 upto nofmultipars :
      path lftbdry, rtbdry, parframe;
      rtbdry := rightboundary multipars[i];
      lftbdry := (leftboundary multipars[i])
        shifted (-36pt, 0);
      parframe := point 0 of lftbdry
                --point 1 of lftbdry
                --point 0 of rtbdry
                --point 1 of rtbdry
                --cycle;
      draw parframe;
  endfor;
  endgroup;
\stopuseMPgraphic
\starttext
\definetextbackground
  [MyBackground]
  [location=paragraph,
    mp=MyMPBackground,
    frame=off]
\startlinenumbering
  \starttextbackground[MyBackground]
    \typefile[option=context]{\jobname.mkiv}
  \stoptextbackground
\stoplinenumbering
\stoptext

Sample Code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .