如何在纯 TeX 中将 vbox 排版为网格?

如何在纯 TeX 中将 vbox 排版为网格?

注意:下面更新

我知道这是一个备受争议的话题,这在纯 TeX 中几乎是不可能的,但我想要的仅仅是一个vbox高度为baselineskip。在网上搜索后,我找到了以下最小工作示例中的代码(背景网格取自这个答案):

\newbox\gridbox
\setbox\gridbox\line{%
  \special{color push rgb .8 .8 1}%
  \vrule height\baselineskip width0pt \hrulefill
  \special{color pop}}
\def\grid{\vtop to0pt{\hrule height0pt\kern-\dimexpr\baselineskip-\topskip\relax
    \vbox to\dimexpr\vsize+2pt\relax{\leaders\copy\gridbox\vfil}\vss}}
\def\pagebody{\vbox to\vsize{\boxmaxdepth=\maxdepth \grid\pagecontents}}

\parskip=0pt \vsize=\dimexpr\topskip+44\baselineskip\relax % 45 lines per page

\def\headfont{
  \font\rm=cmr17
  \baselineskip=20pt
  \rm
}

\def\head#1 \par{\vskip2\baselineskip\nobreak
  \setbox0=\vbox{{\headfont\noindent#1\par}}
  \dimen0=\ht0%                     \dimen0 = 11.80556pt
  \advance\dimen0 by\baselineskip%  \dimen0 = 23.80556pt
  \divide\dimen0 by\baselineskip%   \dimen0 = 0.00002pt
  \multiply\dimen0 by\baselineskip% \dimen0 = 12.0pt
  \vbox to\dimen0{\vfil\box0}
  \nobreak\vskip2\baselineskip\nobreak
  \noindent
}

\def\1{\head Lorem ipsum

As any dedicated reader can clearly see, the Ideal of
practical reason is a representation of, as far as I know, the things
in themselves; as I have shown elsewhere, the phenomena should only be
used as a canon for our understanding. The paralogisms of practical
reason are what first give rise to the architectonic of practical
reason. As will easily be shown in the next section, reason would
thereby be made to contradict, in view of these considerations, the
Ideal of practical reason, yet the manifold depends on the phenomena.
Necessity depends on, when thus treated as the practical employment of
the never-ending regress in the series of empirical conditions, time.
Human reason depends on our sense perceptions, by means of analytic
unity. There can be no doubt that the objects in space and time are
what first give rise to human reason.

Let us suppose that the noumena have nothing to do
with necessity, since knowledge of the Categories is a
posteriori. Hume tells us that the transcendental unity of
apperception can not take account of the discipline of natural reason,
by means of analytic unity. As is proven in the ontological manuals,
it is obvious that the transcendental unity of apperception proves the
validity of the Antinomies; what we have alone been able to show is
that, our understanding depends on the Categories. It remains a
mystery why the Ideal stands in need of reason. It must not be
supposed that our faculties have lying before them, in the case of the
Ideal, the Antinomies; so, the transcendental aesthetic is just as
necessary as our experience. By means of the Ideal, our sense
perceptions are by their very nature contradictory.

}

\1\1

\bye

head我创建一个vbox,然后计算其高度,baselineskip添加,将总数除以baselineskip然后再次乘以,因此我得到一个四舍五入为 的高度。每次操作后,我都会显示使用baselineskip的值,并在每行后的注释中添加这些值。dimen0\showthe

让我惊讶的是,乘法后dimen0是 12pt,而不是我预期的 24pt。不过,只需添加另一个 ,即可轻松规避此问题baselineskip

我感到疑惑的第二件事是输出仍然没有显示,也就是说,第二个块相对于网格的位置显然与第一个块不相同。这是为什么呢?

为什么在纯 TeX 中设置网格仍然如此困难?gridLaTeX 中已经有这个包好几年了,而且由于 LaTeX 只是 TeX 之上的一种宏语言,我不明白为什么这些功能也没有转换为纯 TeX。

为了记录,我使用的是 TeX Live 2014 中的 XeTeX 3.14159265-2.6-0.99991。


更新:在采纳建议后wipet 的回答我现在有这个例子,其中章节名称跨越多行:

\newbox\gridbox
\setbox\gridbox\line{%
  \special{color push rgb .8 .8 1}%
  \vrule height\baselineskip width0pt \hrulefill
  \special{color pop}}
\def\grid{\vtop to0pt{\hrule height0pt\kern-\dimexpr\baselineskip-\topskip\topskip=10pt\relax
    \vbox to\dimexpr\vsize+2pt\relax{\leaders\copy\gridbox\vfil}\vss}}
\def\pagebody{\vbox to\vsize{\boxmaxdepth=\maxdepth \grid\pagecontents}}

\parskip=0pt \vsize=\dimexpr\topskip+44\baselineskip\relax % 45 lines per page

\def\headfont{
  \font\rm=cmr17
  \baselineskip=20pt
  \rm\setbox\strutbox=\hbox{\vrule height.7\baselineskip depth.3\baselineskip width0pt}
}

\setbox\strutbox=\hbox{\vrule height.7\baselineskip depth.3\baselineskip width0pt}

\def\head#1 \par{\null\nobreak%\vskip\baselineskip
  \setbox0=\hbox{\vbox{{\headfont\noindent#1\par}}}
  \dimen0=\ht0%                     \dimen0 = 11.80556pt
  \advance\dimen0 by\baselineskip%  \dimen0 = 23.80556pt
  \divide\dimen0 by\baselineskip%   \dimen0 = 0.00002pt
  \multiply\dimen0 by\baselineskip% \dimen0 = 12.0pt
  \vskip\dimen0
  \ht0=0pt \dp0=0pt \box0
  \nobreak\vskip2\baselineskip\nobreak
  \noindent
}

\def\1{\head Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.
Sed sit amet ipsum mauris

As any dedicated reader can clearly see, the Ideal of
practical reason is a representation of, as far as I know, the things
in themselves; as I have shown elsewhere, the phenomena should only be
used as a canon for our understanding. The paralogisms of practical
reason are what first give rise to the architectonic of practical
reason. As will easily be shown in the next section, reason would
thereby be made to contradict, in view of these considerations, the
Ideal of practical reason, yet the manifold depends on the phenomena.
Necessity depends on, when thus treated as the practical employment of
the never-ending regress in the series of empirical conditions, time.
Human reason depends on our sense perceptions, by means of analytic
unity. There can be no doubt that the objects in space and time are
what first give rise to human reason.

Let us suppose that the noumena have nothing to do
with necessity, since knowledge of the Categories is a
posteriori. Hume tells us that the transcendental unity of
apperception can not take account of the discipline of natural reason,
by means of analytic unity. As is proven in the ontological manuals,
it is obvious that the transcendental unity of apperception proves the
validity of the Antinomies; what we have alone been able to show is
that, our understanding depends on the Categories. It remains a
mystery why the Ideal stands in need of reason. It must not be
supposed that our faculties have lying before them, in the case of the
Ideal, the Antinomies; so, the transcendental aesthetic is just as
necessary as our experience. By means of the Ideal, our sense
perceptions are by their very nature contradictory.

}

\1\1

\bye

但是,这并没有产生我想要的输出:

网格示例 1

如您所见,\null(空的\hbox)会创建一个空行,而这并不是我想要的页面顶部的行(\vskip没有这种副作用)。省略\null也不会产生所需的结果,如下所示:

网格示例 2

现在章节标题‘走进’了顶部边缘。

添加负片\vskip可以解决页面顶部的多余间隙问题,但在页面中间的正文和章节(/部分)标题之间留下的空间太小。

关于这个还能做什么?

答案1

我建议将高度和深度为零的框插入到网格中,而不是插入计算宽度的 vbox。您的解决方案 ( \vbox to\dimen0) 打破了 intelineskip 计算,\baselineskip因为 lineskip 加上 lineskiplimit 在这里起作用。这就是您的解决方案不保留网格的原因。

 \def\head#1 \par{\null\nobreak\vskip\baselineskip
  \setbox0=\hbox{\vbox{{\headfont\noindent#1\par}}}
  \dimen0=\ht0%                     \dimen0 = 11.80556pt
  \advance\dimen0 by\baselineskip%  \dimen0 = 23.80556pt
  \divide\dimen0 by\baselineskip%   \dimen0 = 0.00002pt 
  \multiply\dimen0 by\baselineskip% \dimen0 = 12.0pt    
  \vskip\dimen0 
  \ht0=0pt \dp0=0pt \box0
  \nobreak\vskip2\baselineskip
  \noindent
}

请注意,以下材料在垂直列表中:

\null ...    this iserts one line. If this material is on the top of the page then
             this \null is placed on the first baseline.
\nobreak ... the following skips are protected
\vskip n\baselineskip  ... (as your wish)
\vskip\dimen0          ... the skip calculated from original width of the box
                           rounded to the multiply of \baselineskip
\box with height and depth set to zero
\nobreak
\vskip k\baselineskip  ... (as your wish)

“……为什么在纯 TeX 中设置网格仍然如此困难?”恕我直言,在纯 TeX 中设置网格很简单。但您必须将许多类似 vskip 的寄存器( 等)设置\abovedisplayskip\parskip适当的值。

相关内容