How to construct an hbox with negative height?Definition of strut explainedNon-invasive replacement for fbox?Boxes of zero height, depth and width unexpectedly affecting document spacingHow to skip newsavebox?Complex formed/shaped boxes (with coloured rim/frame and height as specified in beginminipage[height=…])Unexpected change in pagination when 'no' change in contents, using `boxedmini2e`A box's reference pointHow do I get the height and depth of a box as a dimension?TeXbook - Chapter 12: Glue - Exercise 12.8How can I get the max height of a group boxes in an environment without incrementing a counter?
Has there been any indication at all that further negotiation between the UK and EU is possible?
How does DC work with natural 20?
How to remove this component from PCB
CircuiTikZ: Start ground relative to the closest component
Why do textbooks often include the solutions to odd or even numbered problems but not both?
Why is it easier to balance a non-moving bike standing up than sitting down?
What are Elsa's reasons for selecting the Holy Grail on behalf of Donovan?
How to make clear to people I don't want to answer their "Where are you from?" question?
Why does Linux list NVMe drives as /dev/nvme0 instead of /dev/sda?
Android Material and appcompat Manifest merger failed in react-native or ExpoKit
Is a single radon daughter atom in air a solid?
Heavily limited premature compiler translates text into excecutable python code
Are all Ringwraiths called Nazgûl in LotR?
Helping ease my back pain by studying 13 hours everyday , even weekends
Can a rogue use Sneak Attack in a Darkness spell cast by another player?
Story about hunting giant lizards for hides on privately owned planet
Where's this swanky house and vineyard near a mountain?
How can you guarantee that you won't change/quit job after just couple of months?
Should an enameled cast iron pan be seasoned?
Greeting with "Ho"
Is declining an undergraduate award which causes me discomfort appropriate?
"Correct me if I'm wrong"
How can lift be less than thrust that is less than weight?
Is there a term for the belief that "if it's legal, it's moral"?
How to construct an hbox with negative height?
Definition of strut explainedNon-invasive replacement for fbox?Boxes of zero height, depth and width unexpectedly affecting document spacingHow to skip newsavebox?Complex formed/shaped boxes (with coloured rim/frame and height as specified in beginminipage[height=…])Unexpected change in pagination when 'no' change in contents, using `boxedmini2e`A box's reference pointHow do I get the height and depth of a box as a dimension?TeXbook - Chapter 12: Glue - Exercise 12.8How can I get the max height of a group boxes in an environment without incrementing a counter?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
According to answer on exercise 12.10 in TeXbook, a box's height may be negative:
Yes it did, but only because none of his boxes had a negative height or depth.
But on p.77 it is said:
The result of
hbox
never has negative height or negative depth, but the
width can be negative.
How does one construct a box with negative height?
Why in the following example prevdepth
is not set to the depth of the new box?
vboxhrule depth -5pt showtheprevdepth hboxworld
(on p.80 it is said that prevdepth
is set to the depth of the new box)
TeXbook p.80 says:
... the reference point of the lowest box is taken as the reference point of the whole, and the glue is set so that the final height has some desired value.
Consider the following input:
tracingonline=1
setbox0=vbox to 20pthboxxvss
showbox0
abox0 b
end
Output is
Notice, that the lowest box is with "x", then comes the glue:
> box0=
vbox(20.0+0.0)x5.2778, glue set 15.69446fil
.hbox(4.30554+0.0)x5.2778
..tenrm x
.glue 0.0 plus 1.0fil minus 1.0fil
But the reference point of the whole is not reference point of "x" (as seen from the image). Is this a contradiction?
boxes box
add a comment |
According to answer on exercise 12.10 in TeXbook, a box's height may be negative:
Yes it did, but only because none of his boxes had a negative height or depth.
But on p.77 it is said:
The result of
hbox
never has negative height or negative depth, but the
width can be negative.
How does one construct a box with negative height?
Why in the following example prevdepth
is not set to the depth of the new box?
vboxhrule depth -5pt showtheprevdepth hboxworld
(on p.80 it is said that prevdepth
is set to the depth of the new box)
TeXbook p.80 says:
... the reference point of the lowest box is taken as the reference point of the whole, and the glue is set so that the final height has some desired value.
Consider the following input:
tracingonline=1
setbox0=vbox to 20pthboxxvss
showbox0
abox0 b
end
Output is
Notice, that the lowest box is with "x", then comes the glue:
> box0=
vbox(20.0+0.0)x5.2778, glue set 15.69446fil
.hbox(4.30554+0.0)x5.2778
..tenrm x
.glue 0.0 plus 1.0fil minus 1.0fil
But the reference point of the whole is not reference point of "x" (as seen from the image). Is this a contradiction?
boxes box
hbox and vbox have the minimum width and height needed to include the contents. Even smash has a height of 0pt.
– John Kormylo
Jun 4 at 14:56
add a comment |
According to answer on exercise 12.10 in TeXbook, a box's height may be negative:
Yes it did, but only because none of his boxes had a negative height or depth.
But on p.77 it is said:
The result of
hbox
never has negative height or negative depth, but the
width can be negative.
How does one construct a box with negative height?
Why in the following example prevdepth
is not set to the depth of the new box?
vboxhrule depth -5pt showtheprevdepth hboxworld
(on p.80 it is said that prevdepth
is set to the depth of the new box)
TeXbook p.80 says:
... the reference point of the lowest box is taken as the reference point of the whole, and the glue is set so that the final height has some desired value.
Consider the following input:
tracingonline=1
setbox0=vbox to 20pthboxxvss
showbox0
abox0 b
end
Output is
Notice, that the lowest box is with "x", then comes the glue:
> box0=
vbox(20.0+0.0)x5.2778, glue set 15.69446fil
.hbox(4.30554+0.0)x5.2778
..tenrm x
.glue 0.0 plus 1.0fil minus 1.0fil
But the reference point of the whole is not reference point of "x" (as seen from the image). Is this a contradiction?
boxes box
According to answer on exercise 12.10 in TeXbook, a box's height may be negative:
Yes it did, but only because none of his boxes had a negative height or depth.
But on p.77 it is said:
The result of
hbox
never has negative height or negative depth, but the
width can be negative.
How does one construct a box with negative height?
Why in the following example prevdepth
is not set to the depth of the new box?
vboxhrule depth -5pt showtheprevdepth hboxworld
(on p.80 it is said that prevdepth
is set to the depth of the new box)
TeXbook p.80 says:
... the reference point of the lowest box is taken as the reference point of the whole, and the glue is set so that the final height has some desired value.
Consider the following input:
tracingonline=1
setbox0=vbox to 20pthboxxvss
showbox0
abox0 b
end
Output is
Notice, that the lowest box is with "x", then comes the glue:
> box0=
vbox(20.0+0.0)x5.2778, glue set 15.69446fil
.hbox(4.30554+0.0)x5.2778
..tenrm x
.glue 0.0 plus 1.0fil minus 1.0fil
But the reference point of the whole is not reference point of "x" (as seen from the image). Is this a contradiction?
boxes box
boxes box
edited Jun 4 at 8:41
Igor Liferenko
asked Jun 4 at 5:50
Igor LiferenkoIgor Liferenko
2,402830
2,402830
hbox and vbox have the minimum width and height needed to include the contents. Even smash has a height of 0pt.
– John Kormylo
Jun 4 at 14:56
add a comment |
hbox and vbox have the minimum width and height needed to include the contents. Even smash has a height of 0pt.
– John Kormylo
Jun 4 at 14:56
hbox and vbox have the minimum width and height needed to include the contents. Even smash has a height of 0pt.
– John Kormylo
Jun 4 at 14:56
hbox and vbox have the minimum width and height needed to include the contents. Even smash has a height of 0pt.
– John Kormylo
Jun 4 at 14:56
add a comment |
2 Answers
2
active
oldest
votes
Short answer: as far as I know, a box directly produced with the hbox
command can't have a negative height, but a box produced with the vbox
command can. A horizontal box can have a negative height if it is stored in a box register, say box0
, and one executes an assignment of the form ht0=〈dimen〉
with a negative 〈dimen〉
.
Example of a vbox
with negative height
Let's consider the following code:
setbox0=vbox to -10ptvsshboxa
This is vboxhrulebox0nointerlineskip hboxtest.
bye
If you do showbox0
before using box0
, you'll see:
> box0=
vbox(-10.0+0.0)x5.00002, glue set - 14.30554fil
.glue 0.0 plus 1.0fil minus 1.0fil
.hbox(4.30554+0.0)x5.00002
..tenrm a
The box is -10pt height and 0pt deep. Because of this negative height, the hrule
lies exactly 10 points below the baseline of the character box a
. Indeed, changing the -10pt
to 0pt
:
setbox0=vbox to 0ptvsshboxa
showbox0
This is vboxhrulebox0nointerlineskip hboxtest.
bye
gives this:
Here is how it works:
The reference point of the outer
vbox
,vboxhrulebox0nointerlineskip hboxtest
, is the same as that ofhboxtest
; it gets aligned with that of the following period, i.e.: lies on the baseline of the paragraph's first and only line.Because of the
nointerlineskip
,box0
sits on top of thehboxtest
, with no separation (no interline glue).The depth of
box0
is that ofhboxa
(hboxa
is a box—not a kern or glue—and the last item ofbox0
), i.e., 0pt. According to what I explain below, this implies that the reference point ofbox0
is at the same vertical position as the bottom ofhboxa
: its baseline.Now, let's consider the case where we do
setbox0=vbox to -10ptvsshboxa
. We mandatebox0
to have height -10pt, i.e., from the reference point we just computed, this means we have to move 10 points down to reach the “top” ofbox0
, which in this precise case is not the top in the usual sense, but means “right before thevbox
's first element”. This implies that thevss
here behaves as avskip
whose value is -10pt minus the height ofhboxa
. This can be verified with:setbox2=hboxa
% Without e-TeX's dimexpr: dimen0=-ht2 advancedimen0 by -10pt setbox0=vbox to -10ptvskipdimen0 hboxa
setbox0=vbox to -10ptvskipdimexpr-ht2-10ptrelax hboxa
〈rest unchanged〉which gives the same result. Indeed, when continuing our walk from after-last-item to before-first-item of
box0
, before getting to thevss
, we are at the top of thehboxa
, so in order to reach the so-called top of thevbox
(what corresponds to “before the first item”), we must move down in order to arrive 10pt below the reference point, and the amplitude of this downward move has to comprise all the height ofhboxa
, plus 10pt. In other words,vbox to -10pt...
says that before-first-item of thevbox
must be10pt
below thevbox
reference point. So, the first thing to do in order to find the vertical position corresponding to the start of avbox
(what I call before-first-item) is to find the reference point; then move up or down depending either on the natural height of the box, or on its prescribed height in the case of avbox to
.The
hrule
inside the outervbox
comes right beforebox0
. Since no interline glue is added after a rule box in vertical mode, thishrule
comes right above the “top” ofbox0
which we just described, i.e.: 10pt below the baseline of thehboxa
.
Negative height, width or depth of constructed boxes
An hbox
command can't produce a box with negative height or depth,1 but it can produce a box with negative width. A vbox
command can't produce a box with negative width (TeXbook p. 81),2 but it can produce a box with negative height or depth. Example for a negative depth:
setbox2=vboxhrule height 0pt depth -2pt
showbox2
shows:
> box2=
vbox(0.0+-2.0)x0.0
.rule(0.0+-2.0)x*
To aid memory, note the symmetry between these two sentences:
The height and depth of a constructed hbox are determined by the maximum distances by which the interior boxes reach above and below the baseline, respectively.
(TeXbook p. 77) and
The width of a computed
vbox
is the maximum distance by which an enclosed box extends to the right of the reference point, taking possible shifting into account.
(TeXbook p. 81). Other box dimensions immediately resulting from an hbox
or vbox
command may be negative.
prevdepth
after a rule box in vertical mode
Regarding prevdepth
, the TeXbook pp. 79 and 80 says:
TeX's implementation of interline glue involves another primitive quantity called
prevdepth
, which usually contains the depth of the most recent box on the current vertical list. However,prevdepth
is set to the sentinel value −1000 pt at the beginning of a vertical list, or just after a rule box; (...)
Since your example does showtheprevdepth
just after a rule box, we are precisely in one of the particular cases where prevdepth
is set to -1000 pt.
Reference point of a constructed vbox
Regarding your addition concerning vbox to 20pthboxxvss
, this is a new question! The answer is in the next two paragraphs after the one you quoted on p. 80:
However, this description of vboxes glosses over some technicalities that come up when you consider unusual cases (...) Therefore, the actual rules (...) (2) If there’s at least one box, but if the final box is followed by kerning or glue, possibly with intervening penalties or other things, the depth is zero.
Depth zero means that the reference point of the box is precisely at the bottom of the vss
(the box doesn't extend below this vss
). This reference point is aligned on a horizontal line with the reference points of the a
and b
character boxes inside the horizontal box that forms the first and only line of your paragraph. Note that this alignment process of reference points does not correspond to the quote you gave, because the latter concerned alignment of boxes inside a vertical list (these alignment processes work in orthogonal directions).
My method to “see“ the reference point of a vbox
is to start after the last item, then move up or down according to the depth computed by the rules given in the paragraph that spans over pages 80 and 81 of the TeXbook. If for instance, the computed depth is 5pt, it means that the reference point of the vbox
is 5pt up from the bottom of its final element. The following extension of your example may help:
setbox2=vboxhrule height 0pt depth 5pt
setbox0=vbox to 20pthboxxvssbox2
avrule height 20ptbox0 b
bye
Explanations:
The width of the
hrule
inbox2
isn't explicitly specified, therefore it is determined by the smallest box or alignment that encloses it, i.e.,box2
(cf. TeXbook p. 221). Since there is nothing else insidebox2
, the width of thehrule
is 0pt; that is why we don't see it on the screenshot.box2
is avbox
whose last element is a box (a rule box), therefore its depth is the depth of that last element (boxmaxdepth
being equal tomaxdimen
by default). The depth ofbox2
is thus 5pt.This implies that the reference point of
box2
lies 5pt above the bottom of its last element, therefore it coincides with the top of thehrule
insidebox2
.The natural height plus depth of all the material inside
box2
is 5pt. Sincebox2
's depth is also 5pt, the natural height ofbox2
is 0pt.This natural height of 0pt is
box2
's height becausebox2
is built withvbox
as opposed tovbox to
. So far, we've explained this:> box2=
vbox(0.0+5.0)x0.0
.rule(0.0+5.0)x*For the same reasons as above, the depth of
box0
is that ofbox2
, namely 5pt, and the reference point ofbox0
lies on the same horizontal line as the top of thehrule
insidebox2
, which coincides with the top ofbox2
(for both possible meanings of the word “top” in this context).The vertical extent of
box2
exactly coversbox0
's 5pt of depth. The remaininghboxxvss
insidebox0
, plus the interline glue inserted beforebox2
, therefore exactly cover the mandated 20pt of height ofbox0
(the precise amount of computed interline glue beforebox2
doesn't matter, because thevss
will adapt to any amount, making it so that the top of thehboxx
lies 20pt above the reference point ofbox0
).The previous point explains why the
vrule height 20pt
reaches up precisely as far as the top of thex
, and down 5pt below the baseline of the paragraph's first and only line (since thevrule
's depth isn't explicitly specified, it is determined by the “smallest box or alignment that encloses it”, namely the horizontal box corresponding to the paragraph's only line, whose deepest element—apart from such rules with free depth—isbox0
).
Footnotes
However, a horizontal box stored in a register can be made to have negative height or depth via assignments such as
ht0=〈dimen〉
ordp0=〈dimen〉
, as pointed out by David Carlisle.But again,
setbox0=vboxhboxawd0=-3pt
does cause box register 0 to contain a vertical box with negative width:> box0=
vbox(4.30554+0.0)x-3.0
.hbox(4.30554+0.0)x5.00002
..tenrm a
So, negative height is equivalent toraise
? Also, it is non-intuitive thathrule depth 5pt
also setsprevdepth
to -1000pt. Why is this useful?
– Igor Liferenko
Jun 4 at 6:37
Regarding the comparison withraise
, I think it's more complicated.raise
is relatively straightforward, but is limited to horizontal mode. It does what the name says. A negative height is essentially useful in vertical mode, I think (it won't make the height of anhbox
negative, e.g.); it interacts withbaselineskip
,lineskiplimit
, etc., with nearby boxes put together in vertical mode. It is possible that some uses ofraise
may have similar effects as a negative-height box (if it prevents some container hbox to have more height... as could avbox
with negative height).
– frougon
Jun 4 at 6:56
Rules are very special boxes. They don't obey... rules of other types of boxes. As the TeXbook says p. 79, “No interline glue is inserted before or after a rule box.” This is usually very useful in layouts (tables, underlining a title, building a macro such asfbox
,frame
ordemobox
...). The TeXbook p. 80 says this is the reason whyprevdepth
is set to -1000 pt after a rule box: “(...) or just after a rule box; this serves to suppress the next interline glue. The user can change the value ofprevdepth
at any time when building a vertical list;“
– frougon
Jun 4 at 7:04
(continuation of TeXbook quote) “thus, for example, thenointerlineskip
macro of Appendix B simply expands toprevdepth=-1000pt
.” So, the particular rule regardingprevdepth
set to -1000pt after a rule box occurring in vertical mode is equivalent to usingnointerlineskip
after every such boxes.
– frougon
Jun 4 at 7:04
(thenointerlineskip
is made unnecessary by the special case applying to rule boxes).
– frougon
Jun 4 at 7:12
|
show 6 more comments
You can have a horizontal box with negative height, as the dimensions of box registers are assignable, but when constructing a box with hbox
the maximum of 0pt and the positive heights of the content is used.
tracingonline1
setbox0=hboxa
showbox0
ht0=-20pt
showbox0
setbox2hboxbox0
showbox2
bye
Produces
hbox(4.30554+0.0)x5.00002
Natural height 4.3pt
hbox(-20.0+0.0)x5.00002
assigned height -20pt
hbox(0.0+0.0)x5.00002
Constructed "natural" height 0pt.
See addition to OP.
– Igor Liferenko
Jun 4 at 8:41
@IgorLiferenko that's a separate question really, but covered in the other answer now.
– David Carlisle
Jun 4 at 10:28
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f494081%2fhow-to-construct-an-hbox-with-negative-height%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Short answer: as far as I know, a box directly produced with the hbox
command can't have a negative height, but a box produced with the vbox
command can. A horizontal box can have a negative height if it is stored in a box register, say box0
, and one executes an assignment of the form ht0=〈dimen〉
with a negative 〈dimen〉
.
Example of a vbox
with negative height
Let's consider the following code:
setbox0=vbox to -10ptvsshboxa
This is vboxhrulebox0nointerlineskip hboxtest.
bye
If you do showbox0
before using box0
, you'll see:
> box0=
vbox(-10.0+0.0)x5.00002, glue set - 14.30554fil
.glue 0.0 plus 1.0fil minus 1.0fil
.hbox(4.30554+0.0)x5.00002
..tenrm a
The box is -10pt height and 0pt deep. Because of this negative height, the hrule
lies exactly 10 points below the baseline of the character box a
. Indeed, changing the -10pt
to 0pt
:
setbox0=vbox to 0ptvsshboxa
showbox0
This is vboxhrulebox0nointerlineskip hboxtest.
bye
gives this:
Here is how it works:
The reference point of the outer
vbox
,vboxhrulebox0nointerlineskip hboxtest
, is the same as that ofhboxtest
; it gets aligned with that of the following period, i.e.: lies on the baseline of the paragraph's first and only line.Because of the
nointerlineskip
,box0
sits on top of thehboxtest
, with no separation (no interline glue).The depth of
box0
is that ofhboxa
(hboxa
is a box—not a kern or glue—and the last item ofbox0
), i.e., 0pt. According to what I explain below, this implies that the reference point ofbox0
is at the same vertical position as the bottom ofhboxa
: its baseline.Now, let's consider the case where we do
setbox0=vbox to -10ptvsshboxa
. We mandatebox0
to have height -10pt, i.e., from the reference point we just computed, this means we have to move 10 points down to reach the “top” ofbox0
, which in this precise case is not the top in the usual sense, but means “right before thevbox
's first element”. This implies that thevss
here behaves as avskip
whose value is -10pt minus the height ofhboxa
. This can be verified with:setbox2=hboxa
% Without e-TeX's dimexpr: dimen0=-ht2 advancedimen0 by -10pt setbox0=vbox to -10ptvskipdimen0 hboxa
setbox0=vbox to -10ptvskipdimexpr-ht2-10ptrelax hboxa
〈rest unchanged〉which gives the same result. Indeed, when continuing our walk from after-last-item to before-first-item of
box0
, before getting to thevss
, we are at the top of thehboxa
, so in order to reach the so-called top of thevbox
(what corresponds to “before the first item”), we must move down in order to arrive 10pt below the reference point, and the amplitude of this downward move has to comprise all the height ofhboxa
, plus 10pt. In other words,vbox to -10pt...
says that before-first-item of thevbox
must be10pt
below thevbox
reference point. So, the first thing to do in order to find the vertical position corresponding to the start of avbox
(what I call before-first-item) is to find the reference point; then move up or down depending either on the natural height of the box, or on its prescribed height in the case of avbox to
.The
hrule
inside the outervbox
comes right beforebox0
. Since no interline glue is added after a rule box in vertical mode, thishrule
comes right above the “top” ofbox0
which we just described, i.e.: 10pt below the baseline of thehboxa
.
Negative height, width or depth of constructed boxes
An hbox
command can't produce a box with negative height or depth,1 but it can produce a box with negative width. A vbox
command can't produce a box with negative width (TeXbook p. 81),2 but it can produce a box with negative height or depth. Example for a negative depth:
setbox2=vboxhrule height 0pt depth -2pt
showbox2
shows:
> box2=
vbox(0.0+-2.0)x0.0
.rule(0.0+-2.0)x*
To aid memory, note the symmetry between these two sentences:
The height and depth of a constructed hbox are determined by the maximum distances by which the interior boxes reach above and below the baseline, respectively.
(TeXbook p. 77) and
The width of a computed
vbox
is the maximum distance by which an enclosed box extends to the right of the reference point, taking possible shifting into account.
(TeXbook p. 81). Other box dimensions immediately resulting from an hbox
or vbox
command may be negative.
prevdepth
after a rule box in vertical mode
Regarding prevdepth
, the TeXbook pp. 79 and 80 says:
TeX's implementation of interline glue involves another primitive quantity called
prevdepth
, which usually contains the depth of the most recent box on the current vertical list. However,prevdepth
is set to the sentinel value −1000 pt at the beginning of a vertical list, or just after a rule box; (...)
Since your example does showtheprevdepth
just after a rule box, we are precisely in one of the particular cases where prevdepth
is set to -1000 pt.
Reference point of a constructed vbox
Regarding your addition concerning vbox to 20pthboxxvss
, this is a new question! The answer is in the next two paragraphs after the one you quoted on p. 80:
However, this description of vboxes glosses over some technicalities that come up when you consider unusual cases (...) Therefore, the actual rules (...) (2) If there’s at least one box, but if the final box is followed by kerning or glue, possibly with intervening penalties or other things, the depth is zero.
Depth zero means that the reference point of the box is precisely at the bottom of the vss
(the box doesn't extend below this vss
). This reference point is aligned on a horizontal line with the reference points of the a
and b
character boxes inside the horizontal box that forms the first and only line of your paragraph. Note that this alignment process of reference points does not correspond to the quote you gave, because the latter concerned alignment of boxes inside a vertical list (these alignment processes work in orthogonal directions).
My method to “see“ the reference point of a vbox
is to start after the last item, then move up or down according to the depth computed by the rules given in the paragraph that spans over pages 80 and 81 of the TeXbook. If for instance, the computed depth is 5pt, it means that the reference point of the vbox
is 5pt up from the bottom of its final element. The following extension of your example may help:
setbox2=vboxhrule height 0pt depth 5pt
setbox0=vbox to 20pthboxxvssbox2
avrule height 20ptbox0 b
bye
Explanations:
The width of the
hrule
inbox2
isn't explicitly specified, therefore it is determined by the smallest box or alignment that encloses it, i.e.,box2
(cf. TeXbook p. 221). Since there is nothing else insidebox2
, the width of thehrule
is 0pt; that is why we don't see it on the screenshot.box2
is avbox
whose last element is a box (a rule box), therefore its depth is the depth of that last element (boxmaxdepth
being equal tomaxdimen
by default). The depth ofbox2
is thus 5pt.This implies that the reference point of
box2
lies 5pt above the bottom of its last element, therefore it coincides with the top of thehrule
insidebox2
.The natural height plus depth of all the material inside
box2
is 5pt. Sincebox2
's depth is also 5pt, the natural height ofbox2
is 0pt.This natural height of 0pt is
box2
's height becausebox2
is built withvbox
as opposed tovbox to
. So far, we've explained this:> box2=
vbox(0.0+5.0)x0.0
.rule(0.0+5.0)x*For the same reasons as above, the depth of
box0
is that ofbox2
, namely 5pt, and the reference point ofbox0
lies on the same horizontal line as the top of thehrule
insidebox2
, which coincides with the top ofbox2
(for both possible meanings of the word “top” in this context).The vertical extent of
box2
exactly coversbox0
's 5pt of depth. The remaininghboxxvss
insidebox0
, plus the interline glue inserted beforebox2
, therefore exactly cover the mandated 20pt of height ofbox0
(the precise amount of computed interline glue beforebox2
doesn't matter, because thevss
will adapt to any amount, making it so that the top of thehboxx
lies 20pt above the reference point ofbox0
).The previous point explains why the
vrule height 20pt
reaches up precisely as far as the top of thex
, and down 5pt below the baseline of the paragraph's first and only line (since thevrule
's depth isn't explicitly specified, it is determined by the “smallest box or alignment that encloses it”, namely the horizontal box corresponding to the paragraph's only line, whose deepest element—apart from such rules with free depth—isbox0
).
Footnotes
However, a horizontal box stored in a register can be made to have negative height or depth via assignments such as
ht0=〈dimen〉
ordp0=〈dimen〉
, as pointed out by David Carlisle.But again,
setbox0=vboxhboxawd0=-3pt
does cause box register 0 to contain a vertical box with negative width:> box0=
vbox(4.30554+0.0)x-3.0
.hbox(4.30554+0.0)x5.00002
..tenrm a
So, negative height is equivalent toraise
? Also, it is non-intuitive thathrule depth 5pt
also setsprevdepth
to -1000pt. Why is this useful?
– Igor Liferenko
Jun 4 at 6:37
Regarding the comparison withraise
, I think it's more complicated.raise
is relatively straightforward, but is limited to horizontal mode. It does what the name says. A negative height is essentially useful in vertical mode, I think (it won't make the height of anhbox
negative, e.g.); it interacts withbaselineskip
,lineskiplimit
, etc., with nearby boxes put together in vertical mode. It is possible that some uses ofraise
may have similar effects as a negative-height box (if it prevents some container hbox to have more height... as could avbox
with negative height).
– frougon
Jun 4 at 6:56
Rules are very special boxes. They don't obey... rules of other types of boxes. As the TeXbook says p. 79, “No interline glue is inserted before or after a rule box.” This is usually very useful in layouts (tables, underlining a title, building a macro such asfbox
,frame
ordemobox
...). The TeXbook p. 80 says this is the reason whyprevdepth
is set to -1000 pt after a rule box: “(...) or just after a rule box; this serves to suppress the next interline glue. The user can change the value ofprevdepth
at any time when building a vertical list;“
– frougon
Jun 4 at 7:04
(continuation of TeXbook quote) “thus, for example, thenointerlineskip
macro of Appendix B simply expands toprevdepth=-1000pt
.” So, the particular rule regardingprevdepth
set to -1000pt after a rule box occurring in vertical mode is equivalent to usingnointerlineskip
after every such boxes.
– frougon
Jun 4 at 7:04
(thenointerlineskip
is made unnecessary by the special case applying to rule boxes).
– frougon
Jun 4 at 7:12
|
show 6 more comments
Short answer: as far as I know, a box directly produced with the hbox
command can't have a negative height, but a box produced with the vbox
command can. A horizontal box can have a negative height if it is stored in a box register, say box0
, and one executes an assignment of the form ht0=〈dimen〉
with a negative 〈dimen〉
.
Example of a vbox
with negative height
Let's consider the following code:
setbox0=vbox to -10ptvsshboxa
This is vboxhrulebox0nointerlineskip hboxtest.
bye
If you do showbox0
before using box0
, you'll see:
> box0=
vbox(-10.0+0.0)x5.00002, glue set - 14.30554fil
.glue 0.0 plus 1.0fil minus 1.0fil
.hbox(4.30554+0.0)x5.00002
..tenrm a
The box is -10pt height and 0pt deep. Because of this negative height, the hrule
lies exactly 10 points below the baseline of the character box a
. Indeed, changing the -10pt
to 0pt
:
setbox0=vbox to 0ptvsshboxa
showbox0
This is vboxhrulebox0nointerlineskip hboxtest.
bye
gives this:
Here is how it works:
The reference point of the outer
vbox
,vboxhrulebox0nointerlineskip hboxtest
, is the same as that ofhboxtest
; it gets aligned with that of the following period, i.e.: lies on the baseline of the paragraph's first and only line.Because of the
nointerlineskip
,box0
sits on top of thehboxtest
, with no separation (no interline glue).The depth of
box0
is that ofhboxa
(hboxa
is a box—not a kern or glue—and the last item ofbox0
), i.e., 0pt. According to what I explain below, this implies that the reference point ofbox0
is at the same vertical position as the bottom ofhboxa
: its baseline.Now, let's consider the case where we do
setbox0=vbox to -10ptvsshboxa
. We mandatebox0
to have height -10pt, i.e., from the reference point we just computed, this means we have to move 10 points down to reach the “top” ofbox0
, which in this precise case is not the top in the usual sense, but means “right before thevbox
's first element”. This implies that thevss
here behaves as avskip
whose value is -10pt minus the height ofhboxa
. This can be verified with:setbox2=hboxa
% Without e-TeX's dimexpr: dimen0=-ht2 advancedimen0 by -10pt setbox0=vbox to -10ptvskipdimen0 hboxa
setbox0=vbox to -10ptvskipdimexpr-ht2-10ptrelax hboxa
〈rest unchanged〉which gives the same result. Indeed, when continuing our walk from after-last-item to before-first-item of
box0
, before getting to thevss
, we are at the top of thehboxa
, so in order to reach the so-called top of thevbox
(what corresponds to “before the first item”), we must move down in order to arrive 10pt below the reference point, and the amplitude of this downward move has to comprise all the height ofhboxa
, plus 10pt. In other words,vbox to -10pt...
says that before-first-item of thevbox
must be10pt
below thevbox
reference point. So, the first thing to do in order to find the vertical position corresponding to the start of avbox
(what I call before-first-item) is to find the reference point; then move up or down depending either on the natural height of the box, or on its prescribed height in the case of avbox to
.The
hrule
inside the outervbox
comes right beforebox0
. Since no interline glue is added after a rule box in vertical mode, thishrule
comes right above the “top” ofbox0
which we just described, i.e.: 10pt below the baseline of thehboxa
.
Negative height, width or depth of constructed boxes
An hbox
command can't produce a box with negative height or depth,1 but it can produce a box with negative width. A vbox
command can't produce a box with negative width (TeXbook p. 81),2 but it can produce a box with negative height or depth. Example for a negative depth:
setbox2=vboxhrule height 0pt depth -2pt
showbox2
shows:
> box2=
vbox(0.0+-2.0)x0.0
.rule(0.0+-2.0)x*
To aid memory, note the symmetry between these two sentences:
The height and depth of a constructed hbox are determined by the maximum distances by which the interior boxes reach above and below the baseline, respectively.
(TeXbook p. 77) and
The width of a computed
vbox
is the maximum distance by which an enclosed box extends to the right of the reference point, taking possible shifting into account.
(TeXbook p. 81). Other box dimensions immediately resulting from an hbox
or vbox
command may be negative.
prevdepth
after a rule box in vertical mode
Regarding prevdepth
, the TeXbook pp. 79 and 80 says:
TeX's implementation of interline glue involves another primitive quantity called
prevdepth
, which usually contains the depth of the most recent box on the current vertical list. However,prevdepth
is set to the sentinel value −1000 pt at the beginning of a vertical list, or just after a rule box; (...)
Since your example does showtheprevdepth
just after a rule box, we are precisely in one of the particular cases where prevdepth
is set to -1000 pt.
Reference point of a constructed vbox
Regarding your addition concerning vbox to 20pthboxxvss
, this is a new question! The answer is in the next two paragraphs after the one you quoted on p. 80:
However, this description of vboxes glosses over some technicalities that come up when you consider unusual cases (...) Therefore, the actual rules (...) (2) If there’s at least one box, but if the final box is followed by kerning or glue, possibly with intervening penalties or other things, the depth is zero.
Depth zero means that the reference point of the box is precisely at the bottom of the vss
(the box doesn't extend below this vss
). This reference point is aligned on a horizontal line with the reference points of the a
and b
character boxes inside the horizontal box that forms the first and only line of your paragraph. Note that this alignment process of reference points does not correspond to the quote you gave, because the latter concerned alignment of boxes inside a vertical list (these alignment processes work in orthogonal directions).
My method to “see“ the reference point of a vbox
is to start after the last item, then move up or down according to the depth computed by the rules given in the paragraph that spans over pages 80 and 81 of the TeXbook. If for instance, the computed depth is 5pt, it means that the reference point of the vbox
is 5pt up from the bottom of its final element. The following extension of your example may help:
setbox2=vboxhrule height 0pt depth 5pt
setbox0=vbox to 20pthboxxvssbox2
avrule height 20ptbox0 b
bye
Explanations:
The width of the
hrule
inbox2
isn't explicitly specified, therefore it is determined by the smallest box or alignment that encloses it, i.e.,box2
(cf. TeXbook p. 221). Since there is nothing else insidebox2
, the width of thehrule
is 0pt; that is why we don't see it on the screenshot.box2
is avbox
whose last element is a box (a rule box), therefore its depth is the depth of that last element (boxmaxdepth
being equal tomaxdimen
by default). The depth ofbox2
is thus 5pt.This implies that the reference point of
box2
lies 5pt above the bottom of its last element, therefore it coincides with the top of thehrule
insidebox2
.The natural height plus depth of all the material inside
box2
is 5pt. Sincebox2
's depth is also 5pt, the natural height ofbox2
is 0pt.This natural height of 0pt is
box2
's height becausebox2
is built withvbox
as opposed tovbox to
. So far, we've explained this:> box2=
vbox(0.0+5.0)x0.0
.rule(0.0+5.0)x*For the same reasons as above, the depth of
box0
is that ofbox2
, namely 5pt, and the reference point ofbox0
lies on the same horizontal line as the top of thehrule
insidebox2
, which coincides with the top ofbox2
(for both possible meanings of the word “top” in this context).The vertical extent of
box2
exactly coversbox0
's 5pt of depth. The remaininghboxxvss
insidebox0
, plus the interline glue inserted beforebox2
, therefore exactly cover the mandated 20pt of height ofbox0
(the precise amount of computed interline glue beforebox2
doesn't matter, because thevss
will adapt to any amount, making it so that the top of thehboxx
lies 20pt above the reference point ofbox0
).The previous point explains why the
vrule height 20pt
reaches up precisely as far as the top of thex
, and down 5pt below the baseline of the paragraph's first and only line (since thevrule
's depth isn't explicitly specified, it is determined by the “smallest box or alignment that encloses it”, namely the horizontal box corresponding to the paragraph's only line, whose deepest element—apart from such rules with free depth—isbox0
).
Footnotes
However, a horizontal box stored in a register can be made to have negative height or depth via assignments such as
ht0=〈dimen〉
ordp0=〈dimen〉
, as pointed out by David Carlisle.But again,
setbox0=vboxhboxawd0=-3pt
does cause box register 0 to contain a vertical box with negative width:> box0=
vbox(4.30554+0.0)x-3.0
.hbox(4.30554+0.0)x5.00002
..tenrm a
So, negative height is equivalent toraise
? Also, it is non-intuitive thathrule depth 5pt
also setsprevdepth
to -1000pt. Why is this useful?
– Igor Liferenko
Jun 4 at 6:37
Regarding the comparison withraise
, I think it's more complicated.raise
is relatively straightforward, but is limited to horizontal mode. It does what the name says. A negative height is essentially useful in vertical mode, I think (it won't make the height of anhbox
negative, e.g.); it interacts withbaselineskip
,lineskiplimit
, etc., with nearby boxes put together in vertical mode. It is possible that some uses ofraise
may have similar effects as a negative-height box (if it prevents some container hbox to have more height... as could avbox
with negative height).
– frougon
Jun 4 at 6:56
Rules are very special boxes. They don't obey... rules of other types of boxes. As the TeXbook says p. 79, “No interline glue is inserted before or after a rule box.” This is usually very useful in layouts (tables, underlining a title, building a macro such asfbox
,frame
ordemobox
...). The TeXbook p. 80 says this is the reason whyprevdepth
is set to -1000 pt after a rule box: “(...) or just after a rule box; this serves to suppress the next interline glue. The user can change the value ofprevdepth
at any time when building a vertical list;“
– frougon
Jun 4 at 7:04
(continuation of TeXbook quote) “thus, for example, thenointerlineskip
macro of Appendix B simply expands toprevdepth=-1000pt
.” So, the particular rule regardingprevdepth
set to -1000pt after a rule box occurring in vertical mode is equivalent to usingnointerlineskip
after every such boxes.
– frougon
Jun 4 at 7:04
(thenointerlineskip
is made unnecessary by the special case applying to rule boxes).
– frougon
Jun 4 at 7:12
|
show 6 more comments
Short answer: as far as I know, a box directly produced with the hbox
command can't have a negative height, but a box produced with the vbox
command can. A horizontal box can have a negative height if it is stored in a box register, say box0
, and one executes an assignment of the form ht0=〈dimen〉
with a negative 〈dimen〉
.
Example of a vbox
with negative height
Let's consider the following code:
setbox0=vbox to -10ptvsshboxa
This is vboxhrulebox0nointerlineskip hboxtest.
bye
If you do showbox0
before using box0
, you'll see:
> box0=
vbox(-10.0+0.0)x5.00002, glue set - 14.30554fil
.glue 0.0 plus 1.0fil minus 1.0fil
.hbox(4.30554+0.0)x5.00002
..tenrm a
The box is -10pt height and 0pt deep. Because of this negative height, the hrule
lies exactly 10 points below the baseline of the character box a
. Indeed, changing the -10pt
to 0pt
:
setbox0=vbox to 0ptvsshboxa
showbox0
This is vboxhrulebox0nointerlineskip hboxtest.
bye
gives this:
Here is how it works:
The reference point of the outer
vbox
,vboxhrulebox0nointerlineskip hboxtest
, is the same as that ofhboxtest
; it gets aligned with that of the following period, i.e.: lies on the baseline of the paragraph's first and only line.Because of the
nointerlineskip
,box0
sits on top of thehboxtest
, with no separation (no interline glue).The depth of
box0
is that ofhboxa
(hboxa
is a box—not a kern or glue—and the last item ofbox0
), i.e., 0pt. According to what I explain below, this implies that the reference point ofbox0
is at the same vertical position as the bottom ofhboxa
: its baseline.Now, let's consider the case where we do
setbox0=vbox to -10ptvsshboxa
. We mandatebox0
to have height -10pt, i.e., from the reference point we just computed, this means we have to move 10 points down to reach the “top” ofbox0
, which in this precise case is not the top in the usual sense, but means “right before thevbox
's first element”. This implies that thevss
here behaves as avskip
whose value is -10pt minus the height ofhboxa
. This can be verified with:setbox2=hboxa
% Without e-TeX's dimexpr: dimen0=-ht2 advancedimen0 by -10pt setbox0=vbox to -10ptvskipdimen0 hboxa
setbox0=vbox to -10ptvskipdimexpr-ht2-10ptrelax hboxa
〈rest unchanged〉which gives the same result. Indeed, when continuing our walk from after-last-item to before-first-item of
box0
, before getting to thevss
, we are at the top of thehboxa
, so in order to reach the so-called top of thevbox
(what corresponds to “before the first item”), we must move down in order to arrive 10pt below the reference point, and the amplitude of this downward move has to comprise all the height ofhboxa
, plus 10pt. In other words,vbox to -10pt...
says that before-first-item of thevbox
must be10pt
below thevbox
reference point. So, the first thing to do in order to find the vertical position corresponding to the start of avbox
(what I call before-first-item) is to find the reference point; then move up or down depending either on the natural height of the box, or on its prescribed height in the case of avbox to
.The
hrule
inside the outervbox
comes right beforebox0
. Since no interline glue is added after a rule box in vertical mode, thishrule
comes right above the “top” ofbox0
which we just described, i.e.: 10pt below the baseline of thehboxa
.
Negative height, width or depth of constructed boxes
An hbox
command can't produce a box with negative height or depth,1 but it can produce a box with negative width. A vbox
command can't produce a box with negative width (TeXbook p. 81),2 but it can produce a box with negative height or depth. Example for a negative depth:
setbox2=vboxhrule height 0pt depth -2pt
showbox2
shows:
> box2=
vbox(0.0+-2.0)x0.0
.rule(0.0+-2.0)x*
To aid memory, note the symmetry between these two sentences:
The height and depth of a constructed hbox are determined by the maximum distances by which the interior boxes reach above and below the baseline, respectively.
(TeXbook p. 77) and
The width of a computed
vbox
is the maximum distance by which an enclosed box extends to the right of the reference point, taking possible shifting into account.
(TeXbook p. 81). Other box dimensions immediately resulting from an hbox
or vbox
command may be negative.
prevdepth
after a rule box in vertical mode
Regarding prevdepth
, the TeXbook pp. 79 and 80 says:
TeX's implementation of interline glue involves another primitive quantity called
prevdepth
, which usually contains the depth of the most recent box on the current vertical list. However,prevdepth
is set to the sentinel value −1000 pt at the beginning of a vertical list, or just after a rule box; (...)
Since your example does showtheprevdepth
just after a rule box, we are precisely in one of the particular cases where prevdepth
is set to -1000 pt.
Reference point of a constructed vbox
Regarding your addition concerning vbox to 20pthboxxvss
, this is a new question! The answer is in the next two paragraphs after the one you quoted on p. 80:
However, this description of vboxes glosses over some technicalities that come up when you consider unusual cases (...) Therefore, the actual rules (...) (2) If there’s at least one box, but if the final box is followed by kerning or glue, possibly with intervening penalties or other things, the depth is zero.
Depth zero means that the reference point of the box is precisely at the bottom of the vss
(the box doesn't extend below this vss
). This reference point is aligned on a horizontal line with the reference points of the a
and b
character boxes inside the horizontal box that forms the first and only line of your paragraph. Note that this alignment process of reference points does not correspond to the quote you gave, because the latter concerned alignment of boxes inside a vertical list (these alignment processes work in orthogonal directions).
My method to “see“ the reference point of a vbox
is to start after the last item, then move up or down according to the depth computed by the rules given in the paragraph that spans over pages 80 and 81 of the TeXbook. If for instance, the computed depth is 5pt, it means that the reference point of the vbox
is 5pt up from the bottom of its final element. The following extension of your example may help:
setbox2=vboxhrule height 0pt depth 5pt
setbox0=vbox to 20pthboxxvssbox2
avrule height 20ptbox0 b
bye
Explanations:
The width of the
hrule
inbox2
isn't explicitly specified, therefore it is determined by the smallest box or alignment that encloses it, i.e.,box2
(cf. TeXbook p. 221). Since there is nothing else insidebox2
, the width of thehrule
is 0pt; that is why we don't see it on the screenshot.box2
is avbox
whose last element is a box (a rule box), therefore its depth is the depth of that last element (boxmaxdepth
being equal tomaxdimen
by default). The depth ofbox2
is thus 5pt.This implies that the reference point of
box2
lies 5pt above the bottom of its last element, therefore it coincides with the top of thehrule
insidebox2
.The natural height plus depth of all the material inside
box2
is 5pt. Sincebox2
's depth is also 5pt, the natural height ofbox2
is 0pt.This natural height of 0pt is
box2
's height becausebox2
is built withvbox
as opposed tovbox to
. So far, we've explained this:> box2=
vbox(0.0+5.0)x0.0
.rule(0.0+5.0)x*For the same reasons as above, the depth of
box0
is that ofbox2
, namely 5pt, and the reference point ofbox0
lies on the same horizontal line as the top of thehrule
insidebox2
, which coincides with the top ofbox2
(for both possible meanings of the word “top” in this context).The vertical extent of
box2
exactly coversbox0
's 5pt of depth. The remaininghboxxvss
insidebox0
, plus the interline glue inserted beforebox2
, therefore exactly cover the mandated 20pt of height ofbox0
(the precise amount of computed interline glue beforebox2
doesn't matter, because thevss
will adapt to any amount, making it so that the top of thehboxx
lies 20pt above the reference point ofbox0
).The previous point explains why the
vrule height 20pt
reaches up precisely as far as the top of thex
, and down 5pt below the baseline of the paragraph's first and only line (since thevrule
's depth isn't explicitly specified, it is determined by the “smallest box or alignment that encloses it”, namely the horizontal box corresponding to the paragraph's only line, whose deepest element—apart from such rules with free depth—isbox0
).
Footnotes
However, a horizontal box stored in a register can be made to have negative height or depth via assignments such as
ht0=〈dimen〉
ordp0=〈dimen〉
, as pointed out by David Carlisle.But again,
setbox0=vboxhboxawd0=-3pt
does cause box register 0 to contain a vertical box with negative width:> box0=
vbox(4.30554+0.0)x-3.0
.hbox(4.30554+0.0)x5.00002
..tenrm a
Short answer: as far as I know, a box directly produced with the hbox
command can't have a negative height, but a box produced with the vbox
command can. A horizontal box can have a negative height if it is stored in a box register, say box0
, and one executes an assignment of the form ht0=〈dimen〉
with a negative 〈dimen〉
.
Example of a vbox
with negative height
Let's consider the following code:
setbox0=vbox to -10ptvsshboxa
This is vboxhrulebox0nointerlineskip hboxtest.
bye
If you do showbox0
before using box0
, you'll see:
> box0=
vbox(-10.0+0.0)x5.00002, glue set - 14.30554fil
.glue 0.0 plus 1.0fil minus 1.0fil
.hbox(4.30554+0.0)x5.00002
..tenrm a
The box is -10pt height and 0pt deep. Because of this negative height, the hrule
lies exactly 10 points below the baseline of the character box a
. Indeed, changing the -10pt
to 0pt
:
setbox0=vbox to 0ptvsshboxa
showbox0
This is vboxhrulebox0nointerlineskip hboxtest.
bye
gives this:
Here is how it works:
The reference point of the outer
vbox
,vboxhrulebox0nointerlineskip hboxtest
, is the same as that ofhboxtest
; it gets aligned with that of the following period, i.e.: lies on the baseline of the paragraph's first and only line.Because of the
nointerlineskip
,box0
sits on top of thehboxtest
, with no separation (no interline glue).The depth of
box0
is that ofhboxa
(hboxa
is a box—not a kern or glue—and the last item ofbox0
), i.e., 0pt. According to what I explain below, this implies that the reference point ofbox0
is at the same vertical position as the bottom ofhboxa
: its baseline.Now, let's consider the case where we do
setbox0=vbox to -10ptvsshboxa
. We mandatebox0
to have height -10pt, i.e., from the reference point we just computed, this means we have to move 10 points down to reach the “top” ofbox0
, which in this precise case is not the top in the usual sense, but means “right before thevbox
's first element”. This implies that thevss
here behaves as avskip
whose value is -10pt minus the height ofhboxa
. This can be verified with:setbox2=hboxa
% Without e-TeX's dimexpr: dimen0=-ht2 advancedimen0 by -10pt setbox0=vbox to -10ptvskipdimen0 hboxa
setbox0=vbox to -10ptvskipdimexpr-ht2-10ptrelax hboxa
〈rest unchanged〉which gives the same result. Indeed, when continuing our walk from after-last-item to before-first-item of
box0
, before getting to thevss
, we are at the top of thehboxa
, so in order to reach the so-called top of thevbox
(what corresponds to “before the first item”), we must move down in order to arrive 10pt below the reference point, and the amplitude of this downward move has to comprise all the height ofhboxa
, plus 10pt. In other words,vbox to -10pt...
says that before-first-item of thevbox
must be10pt
below thevbox
reference point. So, the first thing to do in order to find the vertical position corresponding to the start of avbox
(what I call before-first-item) is to find the reference point; then move up or down depending either on the natural height of the box, or on its prescribed height in the case of avbox to
.The
hrule
inside the outervbox
comes right beforebox0
. Since no interline glue is added after a rule box in vertical mode, thishrule
comes right above the “top” ofbox0
which we just described, i.e.: 10pt below the baseline of thehboxa
.
Negative height, width or depth of constructed boxes
An hbox
command can't produce a box with negative height or depth,1 but it can produce a box with negative width. A vbox
command can't produce a box with negative width (TeXbook p. 81),2 but it can produce a box with negative height or depth. Example for a negative depth:
setbox2=vboxhrule height 0pt depth -2pt
showbox2
shows:
> box2=
vbox(0.0+-2.0)x0.0
.rule(0.0+-2.0)x*
To aid memory, note the symmetry between these two sentences:
The height and depth of a constructed hbox are determined by the maximum distances by which the interior boxes reach above and below the baseline, respectively.
(TeXbook p. 77) and
The width of a computed
vbox
is the maximum distance by which an enclosed box extends to the right of the reference point, taking possible shifting into account.
(TeXbook p. 81). Other box dimensions immediately resulting from an hbox
or vbox
command may be negative.
prevdepth
after a rule box in vertical mode
Regarding prevdepth
, the TeXbook pp. 79 and 80 says:
TeX's implementation of interline glue involves another primitive quantity called
prevdepth
, which usually contains the depth of the most recent box on the current vertical list. However,prevdepth
is set to the sentinel value −1000 pt at the beginning of a vertical list, or just after a rule box; (...)
Since your example does showtheprevdepth
just after a rule box, we are precisely in one of the particular cases where prevdepth
is set to -1000 pt.
Reference point of a constructed vbox
Regarding your addition concerning vbox to 20pthboxxvss
, this is a new question! The answer is in the next two paragraphs after the one you quoted on p. 80:
However, this description of vboxes glosses over some technicalities that come up when you consider unusual cases (...) Therefore, the actual rules (...) (2) If there’s at least one box, but if the final box is followed by kerning or glue, possibly with intervening penalties or other things, the depth is zero.
Depth zero means that the reference point of the box is precisely at the bottom of the vss
(the box doesn't extend below this vss
). This reference point is aligned on a horizontal line with the reference points of the a
and b
character boxes inside the horizontal box that forms the first and only line of your paragraph. Note that this alignment process of reference points does not correspond to the quote you gave, because the latter concerned alignment of boxes inside a vertical list (these alignment processes work in orthogonal directions).
My method to “see“ the reference point of a vbox
is to start after the last item, then move up or down according to the depth computed by the rules given in the paragraph that spans over pages 80 and 81 of the TeXbook. If for instance, the computed depth is 5pt, it means that the reference point of the vbox
is 5pt up from the bottom of its final element. The following extension of your example may help:
setbox2=vboxhrule height 0pt depth 5pt
setbox0=vbox to 20pthboxxvssbox2
avrule height 20ptbox0 b
bye
Explanations:
The width of the
hrule
inbox2
isn't explicitly specified, therefore it is determined by the smallest box or alignment that encloses it, i.e.,box2
(cf. TeXbook p. 221). Since there is nothing else insidebox2
, the width of thehrule
is 0pt; that is why we don't see it on the screenshot.box2
is avbox
whose last element is a box (a rule box), therefore its depth is the depth of that last element (boxmaxdepth
being equal tomaxdimen
by default). The depth ofbox2
is thus 5pt.This implies that the reference point of
box2
lies 5pt above the bottom of its last element, therefore it coincides with the top of thehrule
insidebox2
.The natural height plus depth of all the material inside
box2
is 5pt. Sincebox2
's depth is also 5pt, the natural height ofbox2
is 0pt.This natural height of 0pt is
box2
's height becausebox2
is built withvbox
as opposed tovbox to
. So far, we've explained this:> box2=
vbox(0.0+5.0)x0.0
.rule(0.0+5.0)x*For the same reasons as above, the depth of
box0
is that ofbox2
, namely 5pt, and the reference point ofbox0
lies on the same horizontal line as the top of thehrule
insidebox2
, which coincides with the top ofbox2
(for both possible meanings of the word “top” in this context).The vertical extent of
box2
exactly coversbox0
's 5pt of depth. The remaininghboxxvss
insidebox0
, plus the interline glue inserted beforebox2
, therefore exactly cover the mandated 20pt of height ofbox0
(the precise amount of computed interline glue beforebox2
doesn't matter, because thevss
will adapt to any amount, making it so that the top of thehboxx
lies 20pt above the reference point ofbox0
).The previous point explains why the
vrule height 20pt
reaches up precisely as far as the top of thex
, and down 5pt below the baseline of the paragraph's first and only line (since thevrule
's depth isn't explicitly specified, it is determined by the “smallest box or alignment that encloses it”, namely the horizontal box corresponding to the paragraph's only line, whose deepest element—apart from such rules with free depth—isbox0
).
Footnotes
However, a horizontal box stored in a register can be made to have negative height or depth via assignments such as
ht0=〈dimen〉
ordp0=〈dimen〉
, as pointed out by David Carlisle.But again,
setbox0=vboxhboxawd0=-3pt
does cause box register 0 to contain a vertical box with negative width:> box0=
vbox(4.30554+0.0)x-3.0
.hbox(4.30554+0.0)x5.00002
..tenrm a
edited Jun 5 at 5:37
answered Jun 4 at 6:23
frougonfrougon
3,565918
3,565918
So, negative height is equivalent toraise
? Also, it is non-intuitive thathrule depth 5pt
also setsprevdepth
to -1000pt. Why is this useful?
– Igor Liferenko
Jun 4 at 6:37
Regarding the comparison withraise
, I think it's more complicated.raise
is relatively straightforward, but is limited to horizontal mode. It does what the name says. A negative height is essentially useful in vertical mode, I think (it won't make the height of anhbox
negative, e.g.); it interacts withbaselineskip
,lineskiplimit
, etc., with nearby boxes put together in vertical mode. It is possible that some uses ofraise
may have similar effects as a negative-height box (if it prevents some container hbox to have more height... as could avbox
with negative height).
– frougon
Jun 4 at 6:56
Rules are very special boxes. They don't obey... rules of other types of boxes. As the TeXbook says p. 79, “No interline glue is inserted before or after a rule box.” This is usually very useful in layouts (tables, underlining a title, building a macro such asfbox
,frame
ordemobox
...). The TeXbook p. 80 says this is the reason whyprevdepth
is set to -1000 pt after a rule box: “(...) or just after a rule box; this serves to suppress the next interline glue. The user can change the value ofprevdepth
at any time when building a vertical list;“
– frougon
Jun 4 at 7:04
(continuation of TeXbook quote) “thus, for example, thenointerlineskip
macro of Appendix B simply expands toprevdepth=-1000pt
.” So, the particular rule regardingprevdepth
set to -1000pt after a rule box occurring in vertical mode is equivalent to usingnointerlineskip
after every such boxes.
– frougon
Jun 4 at 7:04
(thenointerlineskip
is made unnecessary by the special case applying to rule boxes).
– frougon
Jun 4 at 7:12
|
show 6 more comments
So, negative height is equivalent toraise
? Also, it is non-intuitive thathrule depth 5pt
also setsprevdepth
to -1000pt. Why is this useful?
– Igor Liferenko
Jun 4 at 6:37
Regarding the comparison withraise
, I think it's more complicated.raise
is relatively straightforward, but is limited to horizontal mode. It does what the name says. A negative height is essentially useful in vertical mode, I think (it won't make the height of anhbox
negative, e.g.); it interacts withbaselineskip
,lineskiplimit
, etc., with nearby boxes put together in vertical mode. It is possible that some uses ofraise
may have similar effects as a negative-height box (if it prevents some container hbox to have more height... as could avbox
with negative height).
– frougon
Jun 4 at 6:56
Rules are very special boxes. They don't obey... rules of other types of boxes. As the TeXbook says p. 79, “No interline glue is inserted before or after a rule box.” This is usually very useful in layouts (tables, underlining a title, building a macro such asfbox
,frame
ordemobox
...). The TeXbook p. 80 says this is the reason whyprevdepth
is set to -1000 pt after a rule box: “(...) or just after a rule box; this serves to suppress the next interline glue. The user can change the value ofprevdepth
at any time when building a vertical list;“
– frougon
Jun 4 at 7:04
(continuation of TeXbook quote) “thus, for example, thenointerlineskip
macro of Appendix B simply expands toprevdepth=-1000pt
.” So, the particular rule regardingprevdepth
set to -1000pt after a rule box occurring in vertical mode is equivalent to usingnointerlineskip
after every such boxes.
– frougon
Jun 4 at 7:04
(thenointerlineskip
is made unnecessary by the special case applying to rule boxes).
– frougon
Jun 4 at 7:12
So, negative height is equivalent to
raise
? Also, it is non-intuitive that hrule depth 5pt
also sets prevdepth
to -1000pt. Why is this useful?– Igor Liferenko
Jun 4 at 6:37
So, negative height is equivalent to
raise
? Also, it is non-intuitive that hrule depth 5pt
also sets prevdepth
to -1000pt. Why is this useful?– Igor Liferenko
Jun 4 at 6:37
Regarding the comparison with
raise
, I think it's more complicated. raise
is relatively straightforward, but is limited to horizontal mode. It does what the name says. A negative height is essentially useful in vertical mode, I think (it won't make the height of an hbox
negative, e.g.); it interacts with baselineskip
, lineskiplimit
, etc., with nearby boxes put together in vertical mode. It is possible that some uses of raise
may have similar effects as a negative-height box (if it prevents some container hbox to have more height... as could a vbox
with negative height).– frougon
Jun 4 at 6:56
Regarding the comparison with
raise
, I think it's more complicated. raise
is relatively straightforward, but is limited to horizontal mode. It does what the name says. A negative height is essentially useful in vertical mode, I think (it won't make the height of an hbox
negative, e.g.); it interacts with baselineskip
, lineskiplimit
, etc., with nearby boxes put together in vertical mode. It is possible that some uses of raise
may have similar effects as a negative-height box (if it prevents some container hbox to have more height... as could a vbox
with negative height).– frougon
Jun 4 at 6:56
Rules are very special boxes. They don't obey... rules of other types of boxes. As the TeXbook says p. 79, “No interline glue is inserted before or after a rule box.” This is usually very useful in layouts (tables, underlining a title, building a macro such as
fbox
, frame
or demobox
...). The TeXbook p. 80 says this is the reason why prevdepth
is set to -1000 pt after a rule box: “(...) or just after a rule box; this serves to suppress the next interline glue. The user can change the value of prevdepth
at any time when building a vertical list;“– frougon
Jun 4 at 7:04
Rules are very special boxes. They don't obey... rules of other types of boxes. As the TeXbook says p. 79, “No interline glue is inserted before or after a rule box.” This is usually very useful in layouts (tables, underlining a title, building a macro such as
fbox
, frame
or demobox
...). The TeXbook p. 80 says this is the reason why prevdepth
is set to -1000 pt after a rule box: “(...) or just after a rule box; this serves to suppress the next interline glue. The user can change the value of prevdepth
at any time when building a vertical list;“– frougon
Jun 4 at 7:04
(continuation of TeXbook quote) “thus, for example, the
nointerlineskip
macro of Appendix B simply expands to prevdepth=-1000pt
.” So, the particular rule regarding prevdepth
set to -1000pt after a rule box occurring in vertical mode is equivalent to using nointerlineskip
after every such boxes.– frougon
Jun 4 at 7:04
(continuation of TeXbook quote) “thus, for example, the
nointerlineskip
macro of Appendix B simply expands to prevdepth=-1000pt
.” So, the particular rule regarding prevdepth
set to -1000pt after a rule box occurring in vertical mode is equivalent to using nointerlineskip
after every such boxes.– frougon
Jun 4 at 7:04
(the
nointerlineskip
is made unnecessary by the special case applying to rule boxes).– frougon
Jun 4 at 7:12
(the
nointerlineskip
is made unnecessary by the special case applying to rule boxes).– frougon
Jun 4 at 7:12
|
show 6 more comments
You can have a horizontal box with negative height, as the dimensions of box registers are assignable, but when constructing a box with hbox
the maximum of 0pt and the positive heights of the content is used.
tracingonline1
setbox0=hboxa
showbox0
ht0=-20pt
showbox0
setbox2hboxbox0
showbox2
bye
Produces
hbox(4.30554+0.0)x5.00002
Natural height 4.3pt
hbox(-20.0+0.0)x5.00002
assigned height -20pt
hbox(0.0+0.0)x5.00002
Constructed "natural" height 0pt.
See addition to OP.
– Igor Liferenko
Jun 4 at 8:41
@IgorLiferenko that's a separate question really, but covered in the other answer now.
– David Carlisle
Jun 4 at 10:28
add a comment |
You can have a horizontal box with negative height, as the dimensions of box registers are assignable, but when constructing a box with hbox
the maximum of 0pt and the positive heights of the content is used.
tracingonline1
setbox0=hboxa
showbox0
ht0=-20pt
showbox0
setbox2hboxbox0
showbox2
bye
Produces
hbox(4.30554+0.0)x5.00002
Natural height 4.3pt
hbox(-20.0+0.0)x5.00002
assigned height -20pt
hbox(0.0+0.0)x5.00002
Constructed "natural" height 0pt.
See addition to OP.
– Igor Liferenko
Jun 4 at 8:41
@IgorLiferenko that's a separate question really, but covered in the other answer now.
– David Carlisle
Jun 4 at 10:28
add a comment |
You can have a horizontal box with negative height, as the dimensions of box registers are assignable, but when constructing a box with hbox
the maximum of 0pt and the positive heights of the content is used.
tracingonline1
setbox0=hboxa
showbox0
ht0=-20pt
showbox0
setbox2hboxbox0
showbox2
bye
Produces
hbox(4.30554+0.0)x5.00002
Natural height 4.3pt
hbox(-20.0+0.0)x5.00002
assigned height -20pt
hbox(0.0+0.0)x5.00002
Constructed "natural" height 0pt.
You can have a horizontal box with negative height, as the dimensions of box registers are assignable, but when constructing a box with hbox
the maximum of 0pt and the positive heights of the content is used.
tracingonline1
setbox0=hboxa
showbox0
ht0=-20pt
showbox0
setbox2hboxbox0
showbox2
bye
Produces
hbox(4.30554+0.0)x5.00002
Natural height 4.3pt
hbox(-20.0+0.0)x5.00002
assigned height -20pt
hbox(0.0+0.0)x5.00002
Constructed "natural" height 0pt.
answered Jun 4 at 6:49
David CarlisleDavid Carlisle
511k4311601918
511k4311601918
See addition to OP.
– Igor Liferenko
Jun 4 at 8:41
@IgorLiferenko that's a separate question really, but covered in the other answer now.
– David Carlisle
Jun 4 at 10:28
add a comment |
See addition to OP.
– Igor Liferenko
Jun 4 at 8:41
@IgorLiferenko that's a separate question really, but covered in the other answer now.
– David Carlisle
Jun 4 at 10:28
See addition to OP.
– Igor Liferenko
Jun 4 at 8:41
See addition to OP.
– Igor Liferenko
Jun 4 at 8:41
@IgorLiferenko that's a separate question really, but covered in the other answer now.
– David Carlisle
Jun 4 at 10:28
@IgorLiferenko that's a separate question really, but covered in the other answer now.
– David Carlisle
Jun 4 at 10:28
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f494081%2fhow-to-construct-an-hbox-with-negative-height%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
hbox and vbox have the minimum width and height needed to include the contents. Even smash has a height of 0pt.
– John Kormylo
Jun 4 at 14:56