纯 TeX:对于标记的文本块中的每一行,将字符放在右边距中

纯 TeX:对于标记的文本块中的每一行,将字符放在右边距中

我想将纯 TeX 文档中的某些文本块包装起来,以便在块中每一行的右侧,在右边距打印一个特定的字符。

所有这些字符都应位于边距的同一水平位置,比如说,文本块右边距右侧的 3ex。

使用竖线|作为字符可以让我显示文档中的哪些文本块与文档的先前草稿相比已被修改。

LaTeX 有一个包可以用边线标记更改,但 TeX 中似乎没有。我在这里提出的方法在审美上并不美观,但可以完成工作并且似乎很容易实现。但是,如果无法以这种方式换行任意文本块,那么我可以接受换行整个段落。

我可以想象一个宏\markchunk{Four score and eight years ago}或一对宏如下:

\markstart
Four score and eight years ago
\markend

谢谢你!

答案1

我的解决方案基于原始形式 pdfTeX。和\pdfsavepos的位置保存到文件中,该文件中的数据将在下一次 TeX 运行中重复使用。 数据从开始和结束标记的位置重新计算到\markstart\markstop\jobname.pos位置起始标记加距离从开始到结束标记。这个计算是在\posX宏中完成的,它有点复杂,因为我们需要计算开始和结束标记之间的分页符。计算的结果是\pos:pagenumber表单\posA{position}{distance}\posA{position}{distance}等中的一组宏。这些宏最终在例程中用于\output从位置+10pt 绘制长度为距离+12pt 的条形图。这就是重新定义纯 TeX 输出例程的原因\pagebody

\def\markchunk#1{\markstart #1\markstop}
\def\markstart{\leavevmode\writepos B}
\def\markstop{\writepos E}

\newdimen\botmargin
\ifdim\pdfpageheight=0pt \pdfpageheight=297mm \fi                           
\botmargin=\pdfpageheight \advance\botmargin by-\vsize
\advance\botmargin by-1in \advance\botmargin by-\voffset

\newcount\tmpnum
\def\posX#1#2#3#4{%
   \expandafter\ifx\csname pos:#2\endcsname\relax
      \expandafter\def\csname pos:#2\endcsname{}%
      \tmpnum=\botmargin \advance\tmpnum by\vsize \advance\tmpnum by-\topskip
   \fi
   \ifx#1B%
      \expandafter\edef\csname pos:#2\endcsname{\csname pos:#2\endcsname \posA{#4}}%
      \tmpnum=#4
   \else \expandafter\ifx\csname pos:#2\endcsname\empty
            \expandafter\edef\csname pos:#2\endcsname{\posA{\the\tmpnum}}%
         \fi
      \advance\tmpnum by-#4
      \expandafter\edef\csname pos:#2\endcsname{\csname pos:#2\endcsname{\the\tmpnum}}%     
      \tmpnum=-1
   \fi
}
\def\posY#1{%
   \expandafter\ifx\csname pos:#1\endcsname\relax \else
      \ifnum\tmpnum<0 \else
         \advance\tmpnum by-\botmargin
         \expandafter\edef\csname pos:#1\endcsname{\csname pos:#1\endcsname{\the\tmpnum}}%
   \fi\fi
}
\newread\testin
\def\softinput #1 {\let\next=\relax \openin\testin=#1
  \ifeof\testin \message{Warning: the file #1 does not exist}%
  \else \closein\testin \def\next{\input #1 }\fi
  \next
}
\let\posA=\relax \softinput\jobname.pos

\newwrite\posfile
\immediate\openout\posfile=\jobname.pos
\def\writepos#1{\pdfsavepos
   \write\posfile{\string\posX\space#1{\the\pageno}{\the\pdflastxpos}{\the\pdflastypos}}}

\def\posA#1#2{\vbox to0pt{\kern\botmargin\kern-#1sp\kern-10pt
   \rlap{\vrule height 12pt depth#2sp}\vss}}

\def\pagebody{\hbox{\vbox to\vsize{\boxmaxdepth\maxdepth \pagecontents}%
   \write\posfile{\string\posY{\the\pageno}}%
   \rlap{\kern10pt \csname pos:\the\pageno\endcsname}}}

I'd like to wrap certain chunks of text in my Plain TeX document so that, to
the right of each line in the chunk, a specific character is printed in the 
right margin. \markchunk{Four score and eight years ago.}
All of these characters should be at the same horizontal position in the
margin, say 3ex to the right of the text chunk's right margin.

I'd like to wrap certain chunks of text in my Plain TeX document so that, to
the right of each line in the chunk, a specific character is printed in the 
right margin. And the test. \markchunk{Four score and eight years ago.}
All of these characters should be at the same horizontal position in the
margin, say 3ex to the right of the text chunk's right margin.

\markstart
LaTeX has a package to mark changes with marginal bars, but none seems
available in TeX. The method I'm proposing here is not esthetically   
beautiful, but will get the job done and seems likely to be simple to 
implement. If, however, it is not possible to wrap arbitrary chunks of text
in this way, then I could live with wrapping whole paragraphs.
\markstop

\bye

相关内容