TransWikia.com

How can I mark and label certain regions in the margin with ConTeXt?

TeX - LaTeX Asked by flyx on September 26, 2020

I write a document that discusses syntactic differences between two languages (let’s say, TeX and Markdown). Going through various topics, the text talks some time about one language and then about the other language.

What I want to do is to place marks in the margin to show which regions discuss TeX and which discuss Markdown. For example:

Here are some paragraphs   
discussing features        | TeX
                           |
of TeX.                    /

And the text starting here 
                           | Markdown
discusses Markdown         /

Since I have quite some region pairs like this, I would like to generate them with environment, like so:

starttexdiscussion
Here are some paragraphs discussing features

of TeX.
stoptexdiscussion

startmarkdowndiscussion
And the text starting here

discusses Markdown
stopmarkdowndiscussion

Is it possible to define environments that do that for me? How would I adjust position and length of the margin content to match the main content? How could I handle page breaks?

One Answer

Here's a solution based on Henri Menke's comments that does exactly what is described, including splitting the braces when page breaks are encountered.

defdefinebraceddiscussion#1[#2]#3[#4]{
  startuseMPgraphic{#2frame}
    begingroup;
        numeric n ;
        pair lr, ur ;
        picture p ;
        for i=1 upto nofmultipars :
            lr := lrcorner multipars[i] ;
            ur := urcorner multipars[i] ;
            n := arclength(lr -- ur) / 2 ;
            p := textext.rt("$left.vrule height " & decimal n & "bp width 0pt depth 0ptright}$") ;
            draw p shifted (.5[lr,ur] + (EmWidth,0));
            label.rt("#4", .5[lr,ur] shifted (.75cm, 0)) ;
        endfor ;
    endgroup;
  stopuseMPgraphic
  definetextbackground[#2Frame]
    [mp=#2frame, location=paragraph]
  definestartstop[#2discussion]
    [before={starttextbackground[#2Frame]},
     after={stoptextbackground[#2Frame]}]
}

definebraceddiscussion[tex][TeX]
definebraceddiscussion[markdown][Markdown]

starttext

starttexdiscussion

  input knuth

  input tufte

stoptexdiscussion

startmarkdowndiscussion

  input ward

  input zapf

stopmarkdowndiscussion

stoptext

Correct answer by flyx on September 26, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP