vbox 的复仇

vbox 的复仇

是的,它们回来了。而且来势汹汹。那些我们称之为\vboxes 的讨厌的小虫子,我之前曾与。 (还有布鲁诺

\parskip=0pt
\def\unquo{\unvbox0\smallskip}
\def\bquo#{\smallskip\dimen255=\prevdepth\setbox0\vbox\bgroup\prevdepth=\dimen255
  \narrower\noindent\strut\aftergroup\unquo\let\next= }

\hsize=20pc
Some text which goes on for a while, in fact, hopefully long enough to
produce a line break.
\bquo{A quote which goes on for a while, so long in fact, that I was hoping to
see a line break somewhere durin this ouote.}
And then some more text.
\bye

在此处输入图片描述

不!那是什么空间?与报价之前的数量不一样我可以告诉你那么多。你肯定会告诉我\smallskipamount3pt plus 1pt minus 1pt,但那不可能2pt。不可能。

帮帮忙。拜托。

答案1

您需要重置\prevdepth:这样做\unvbox0不起作用。

TeXbook,第 282 页:

\unvbox<8 bit number>, … 的值\prevdepth不受影响。

另一方面,这样做\box会影响\prevdepth(同一页面),因此我们通过分离最后一个框并用重新连接来解决问题\box

\parskip=0pt
\def\unquo{\unvbox0 \setbox0=\lastbox\nointerlineskip\box0 \smallskip}
\def\bquo#{\smallskip\dimen255=\prevdepth\setbox0\vbox\bgroup\prevdepth=\dimen255
  \narrower\noindent\strut\aftergroup\unquo\let\next= }

\hsize=20pc

\dimen0=5\baselineskip
\advance\dimen0 2\smallskipamount
\def\ruler{\leavevmode\smash{\vrule height 0pt depth \dimen0}\kern-0.4pt}


\ruler
Some text which goes on for a while, in fact, hopefully long enough to
produce a line break.
\bquo{A quote which goes on for a while, so long in fact, that I was hoping to
see a line break somewhere durin this quote.}
And then some more text.
\bye

我添加了一把具有所需长度的标尺来显示间距是否正确。

\unquo宏也可以更紧凑地定义如下

\def\unquo{\unvbox0 \nointerlineskip\lastbox\smallskip}

在此处输入图片描述

当然,也可以通过以下方式获得相同的结果

\long\def\bquo#1{\smallskip{\narrower#1\par}\smallskip}

答案2

如果您更改ouote为,则会获得相同的间距guote,因此它具有与第一个相同的深度。

添加

\tracingoutput1
\tracingonline2
\showboxbreadth20
\showboxdepth3

A不同之处在于,以.开头的行之前的 baselinskip 值\unvbox不会按照您需要的方式传播深度:

This is TeX, Version 3.1415926 (TeX Live 2011/Cygwin) (format=tex 2012.5.4)  12 JUL 2012 18:21
**ssp
(./ssp.tex

Completed box being shipped out [1]
\vbox(667.20255+0.0)x240.0
.\vbox(0.0+0.0)x240.0, glue set 14.0fil
..\glue -22.5
..\hbox(8.5+0.0)x240.0, glue set 240.0fil
...\vbox(8.5+0.0)x0.0
...\glue 0.0 plus 1.0fil
..\glue 0.0 plus 1.0fil minus 1.0fil
.\vbox(643.20255+0.0)x240.0, glue set 567.20255fill
..\glue(\topskip) 3.05556
..\hbox(6.94444+1.94444)x240.0, glue set - 0.26826
...\hbox(0.0+0.0)x20.0
...\tenrm S
...\tenrm o
...\tenrm m
...\tenrm e
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm t
...\tenrm e
...\tenrm x
...\tenrm t
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm w
...\tenrm h
...\tenrm i
...\tenrm c
...\kern-0.27779
...\tenrm h
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm g
...\tenrm o
...etc.
..\penalty 400
..\glue(\baselineskip) 3.11111
..\hbox(6.94444+1.94444)x240.0, glue set 56.61072fil
...\tenrm f
...\tenrm u
...\tenrm l
...\tenrm l
...\tenrm y
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm l
...\tenrm o
...\tenrm n
...\tenrm g
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm e
...\tenrm n
...\tenrm o
...\tenrm u
...\tenrm g
...\tenrm h
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm t
...\tenrm o
...etc.
..\glue 3.0 plus 1.0 minus 1.0
..\glue(\baselineskip) 1.55556
..\hbox(8.5+3.5)x240.0, glue set 0.90999
...\glue(\leftskip) 20.0
...\rule(8.5+3.5)x0.0
...\tenrm A
...\glue 3.33333 plus 1.66498 minus 1.11221
...\tenrm q
...\tenrm u
...\tenrm o
...\tenrm t
...\tenrm e
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm w
...\tenrm h
...\tenrm i
...\tenrm c
...\kern-0.27779
...\tenrm h
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm g
...\tenrm o
...\kern0.27779
...etc.
..\penalty 150
..\glue(\baselineskip) 1.55556
..\hbox(6.94444+1.94444)x240.0, glue set 0.3171
...\glue(\leftskip) 20.0
...\tenrm i
...\tenrm n
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm f
...\tenrm a
...\tenrm c
...\tenrm t
...\tenrm ,
...\glue 3.33333 plus 2.08331 minus 0.88889
...\tenrm t
...\tenrm h
...\tenrm a
...\tenrm t
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm I
...\glue 3.33333 plus 1.66498 minus 1.11221
...\tenrm w
...\kern-0.27779
...\tenrm a
...etc.
..\penalty 150
..\glue(\baselineskip) 3.11111
..\hbox(6.94444+1.94444)x240.0, glue set 76.49979fil
...\glue(\leftskip) 20.0
...\tenrm s
...\tenrm o
...\tenrm m
...\tenrm e
...\tenrm w
...\tenrm h
...\tenrm e
...\tenrm r
...\tenrm e
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm d
...\tenrm u
...\tenrm r
...\tenrm i
...\tenrm n
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm t
...\tenrm h
...\tenrm i
...etc.
..\glue 3.0 plus 1.0 minus 1.0
..\glue(\parskip) 0.0
..\glue(\baselineskip) 3.11111
..\hbox(6.94444+0.0)x240.0, glue set 104.91646fil
...\hbox(0.0+0.0)x20.0
...\tenrm A
...\tenrm n
...\tenrm d
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm t
...\tenrm h
...\tenrm e
...\tenrm n
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm s
...\tenrm o
...\tenrm m
...\tenrm e
...\glue 3.33333 plus 1.66666 minus 1.11111
...\tenrm m
...\tenrm o
...\tenrm r
...\tenrm e
...\glue 3.33333 plus 1.66666 minus 1.11111
...etc.
..\glue 0.0 plus 1.0fill
.\glue(\baselineskip) 17.55556
.\hbox(6.44444+0.0)x240.0, glue set 117.5fil
..\glue 0.0 plus 1.0fil minus 1.0fil
..\tenrm 1
..\glue 0.0 plus 1.0fil minus 1.0fil

 )
Output written on ssp.dvi (1 page, 540 bytes).

相关内容