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:

Here are some paragraphs discussing features

of TeX.

And the text starting here

discusses Markdown

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?

  • Does this have to break across pages? Aug 18 '20 at 7:39
  • Well it would be great if it would automatically split in two when it encounters a page break, but primarily I want to know how to generally align margin content with main content.
    – flyx
    Aug 18 '20 at 8:29
  • 1
    Conceptually, this should be in the direction of what you want: tex.stackexchange.com/questions/436250/… Aug 18 '20 at 8:45
  • This looks quite nice. Can you explain a bit how it works, specifically nofmultipars? I did a quick search in the MetaFun manual, but didn't find anything.
    – flyx
    Aug 18 '20 at 9:16
  • Good question. I just read the source code of anch-bck.mkvi and mp-abck.mpiv. Usually I learn about the existence of these things by reading the mailing list. Aug 18 '20 at 9:48

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.

        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 0pt\right\}$") ;
            draw p shifted (.5[lr,ur] + (EmWidth,0));
            label.rt("#4", .5[lr,ur] shifted (.75cm, 0)) ;
        endfor ;
    [mp=#2frame, location=paragraph]




  \input knuth

  \input tufte



  \input ward

  \input zapf


  • 1
    There is a fancy brace (I think copied from the metafont code for computer modern font) available if you load \useMPlibrary[fen]. It can be used as: fill BasicBraceSymbol(180) ysized (ypart ur - ypart lr) shifted ( 0.5[lr,ur] ) ;. It looks better at small sizes (5-8 lines) but looks really weird once you go above a certain number of lines (10 to 15 or so).
    – Aditya
    Aug 20 '20 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.