ฉันจะทำเครื่องหมายและติดป้ายกำกับบางภูมิภาคในระยะขอบด้วย ConTeXt ได้อย่างไร

Aug 17 2020

ฉันเขียนเอกสารที่กล่าวถึงความแตกต่างทางวากยสัมพันธ์ระหว่างสองภาษา (สมมติว่า TeX และ Markdown) ในหัวข้อต่างๆข้อความจะพูดถึงภาษาหนึ่งและเกี่ยวกับภาษาอื่น

สิ่งที่ฉันต้องการทำคือการวางเครื่องหมายในระยะขอบเพื่อแสดงว่าภูมิภาคใดที่พูดคุยเกี่ยวกับ TeX และที่กล่าวถึง Markdown ตัวอย่างเช่น:

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

And the text starting here \
                           | Markdown
discusses Markdown         /

เนื่องจากฉันมีคู่ภูมิภาคแบบนี้ค่อนข้างมากฉันจึงต้องการสร้างมันด้วยสภาพแวดล้อมดังนี้:

\starttexdiscussion
Here are some paragraphs discussing features

of TeX.
\stoptexdiscussion

\startmarkdowndiscussion
And the text starting here

discusses Markdown
\stopmarkdowndiscussion

เป็นไปได้ไหมที่จะกำหนดสภาพแวดล้อมที่ทำเพื่อฉัน ฉันจะปรับตำแหน่งและความยาวของเนื้อหาระยะขอบให้ตรงกับเนื้อหาหลักได้อย่างไร ฉันจะจัดการตัวแบ่งหน้าได้อย่างไร

คำตอบ

1 flyx Aug 19 2020 at 12:27

นี่คือวิธีแก้ปัญหาตามความคิดเห็นของ Henri Menke ที่ทำตามที่อธิบายไว้อย่างชัดเจนรวมถึงการแยกวงเล็บปีกกาเมื่อพบตัวแบ่งหน้า

\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