1

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?

flyx
  • 2,051
  • Does this have to break across pages? – Henri Menke Aug 18 '20 at 07: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 08:29
  • 1
    Conceptually, this should be in the direction of what you want: https://tex.stackexchange.com/questions/436250/colored-bar-next-to-text-over-multiple-pages/436255#436255 – Henri Menke Aug 18 '20 at 08: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 09: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. – Henri Menke Aug 18 '20 at 09:48
  • Ah, nofmultipars apparently means number of multipars, that makes sense. I assume multipars and this number is set by using the graphic as text background. It seems to be a list of content split by page break. – flyx Aug 18 '20 at 10:09
  • Ah, that was the question. Yes, nofmultipars is the number of multipars where each multipar is some region where ConTeXt decides to spit the input (page breaks, column breaks, around floats). – Henri Menke Aug 18 '20 at 10:50
  • Getting a curly brace into the textbackground is relatively easy but I have no idea how to get changeable text in there, because textbackground are handled in a second pass. http://dpaste.com/836NS4UQG (expires in 10 days) – Henri Menke Aug 18 '20 at 10:51
  • @HenriMenke Thanks a lot, I simply wrapped that in a macro to have different text (see the answer). – flyx Aug 19 '20 at 12:29

1 Answers1

1

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.

\def\definebraceddiscussion#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 0pt\right\}$") ;
            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

flyx
  • 2,051
  • 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 05:13