为什么一个盒子中显示的盒子尺寸值是来自前一个盒子的值?
\parindent=0pt
\newdimen\columnwidth%
\columnwidth=100pt%
\def\text{This is the text to fill all the boxes. This is the text to fill all the boxes. This is the text to fill all the boxes. .\vskip\baselineskip}
\def\values{\vbox{ \vskip\baselineskip \bf height \the\ht0 \vskip0.2\baselineskip%
depth \the\dp0 \vskip0.2\baselineskip%
width \the\wd0 \vskip0.2\baselineskip}}%to show the values in the text
%endofdefinitions
{\bf Question about vboxes and their dimensions}\vskip\baselineskip
Why are the values of the previous column shown, not of the current column?\vskip\baselineskip
\hbox{%
\setbox0=\vtop{\hsize\columnwidth %
} %an empty box
\copy0
\hskip0pt\setbox0=\vtop {\hsize\columnwidth\hrule width\hsize\vskip\baselineskip %
\text
\values
\hrule width\hsize\vskip\baselineskip
} %
\copy0%
\hskip10pt\setbox0=\vtop { \hsize\columnwidth\hrule width\hsize\vskip\baselineskip %
\text\text
\values
\hrule width\hsize\vskip\baselineskip
} %
\copy0%
\hskip10pt\setbox0=\vtop { \hsize\columnwidth\hrule width\hsize\vskip\baselineskip %
\text\text\text
\values
\hrule width\hsize\vskip\baselineskip
} %
\copy0%
\hskip10pt\setbox0=\vtop { \hsize\columnwidth\hrule width\hsize\vskip\baselineskip %
\text\text\text\text
\values
\hrule width\hsize\vskip\baselineskip
} %
\copy0%
}%
\bye%
答案1
当框有前一列时,您正在输出值。
\hskip10pt\setbox0=\vtop { \hsize\columnwidth\hrule width\hsize\vskip\baselineskip %
\text\text\text
\values
这里你刚刚排版\text\text\text
,但对框 0 的分配尚未完成,因为vbox
尚未完成,所以框 0 具有来自上一个分配的框
答案2
更简单的例子:
\catcode`@=11
\def\makevoid#1{\setbox#1=\box\voidb@x}
\catcode`@=12
\makevoid0
\setbox0=\hbox{This box has width \the\wd0} % expected 0pt
\box0
\makevoid0
\setbox0=\hbox{\hskip10pt}
\setbox0=\hbox{This box has width \the\wd0} % expected 10pt
\box0
\bye
我添加了\makevoid0
以确保框寄存器无效。你期望它\the\wd0
扩展为多少?
我期望0pt
和10pt
,因为 TeX 无法知道它当前正在构建的框的宽度直到构建已完成。TeX 继续吸收标记并将项目附加到水平列表(因为我们已经告诉它构建一个\hbox
);执行时将完成列表}
。只有在完成之后,构建的水平列表才会分配给框寄存器 0。
让我们看看你的例子。我做了一些改动,主要是为了提高可读性。但是,删除大多数%
字符是故意的。其中许多是不必要的,少数可能是有害:我指的是\copy0%
哪个绝对是错误的。我还删除了无用的\hbox
包装器。
\parindent=0pt
\newdimen\columnwidth
\columnwidth=100pt
\def\text{This is the text to fill all the boxes.
This is the text to fill all the boxes. This is the text
to fill all the boxes.\vskip\baselineskip}
\def\values{{\bf
height \the\ht0 \vskip0.2\baselineskip
depth \the\dp0 \vskip0.2\baselineskip
width \the\wd0 \vskip0.2\baselineskip
}}%to show the values in the text
{\bf Question about vboxes and their dimensions}\vskip\baselineskip
Why are the values of the previous column shown, not of the current column?
\vskip\baselineskip
% -1-
\setbox0=\vtop{\hsize\columnwidth
} %an empty box
\copy0
% -2-
\hskip0pt\setbox0=\vtop {\hsize\columnwidth\hrule width\hsize\vskip\baselineskip
\text
\values
\hrule width\hsize\vskip\baselineskip
}
\copy0
% -3-
\hskip10pt\setbox0=\vtop {\hsize\columnwidth\hrule width\hsize\vskip\baselineskip
\text\text
\values
\hrule width\hsize\vskip\baselineskip
}
\copy0
% -4-
\hskip10pt\setbox0=\vtop {\hsize\columnwidth\hrule width\hsize\vskip\baselineskip
\text\text\text
\values
\hrule width\hsize\vskip\baselineskip
}
\copy0
% -5-
\hskip10pt\setbox0=\vtop {\hsize\columnwidth\hrule width\hsize\vskip\baselineskip
\text\text\text\text
\values
\hrule width\hsize\vskip\baselineskip
}
\copy0
\bye
在 -1- 中,您似乎希望确保盒子寄存器 0 为空。使用\voidb@x
前面所示的方法。或者,,\hbox{\box0}
但这在复杂情况下可能会产生不利影响(盒子寄存器有趣的关于组)。请注意,空框寄存器不包含空框。
现在你应该知道为什么在 -2- 中你得到零长度了。当 TeX 扩展 时\values
,\vtop
当前正在构建的 尚未完成。请注意,TeX 首先构建一个,\vbox
并且只在最后移动参考点。它是不可能的以此方式查询正在构建的盒子的尺寸。