A box's reference point

1,146

Solution 1

Every box has height width and depth (any of which may be zero or negative) the reference point is by definition the point from which these lengths are measured. The box containing other boxes or not has no bearing on that.

Note that the height depth and width are assignable properties and need bear no relationship to the box contents.

If \box0 contains some content then after

\ht0=5pt
\dp0=6pt
\wd0=7pt

the height depth and width of box 0 will be 5pt 6pt and 7pt. In horizontal mode, the box will be positioned such that its reference point is placed at the current position, and the current position will move 7pt to the right (whatever the box contents). Similarly in vertical mode the box will be placed with baselineskip glue from the previous box calculated from the previous depth and the nominal 5pt height.


If you do not assign the box dimensions then they will be set depending on the box contents.

if set using \vbox the reference point of the box is at the left edge, at the vertical position of the last box in its content (with some details to be filled in if the last item is not a box or has over-large deoth)

If set using vtop the reference point is at the left edge at the height of the reference point of the first item of the content if it is a box, or at the top of the outer box otherwise.

For \vcenter it is a at the left edge of the box positined such that placing the reference point on teh baseline centres the box on the math axis.

Solution 2

There are only a few ways to create boxes in TeX, and each of them has a well-defined notion of where the reference point ends up. See page 222 of The TeXbook (part of Chapter 21: Making Boxes):

Now let’s summarize all of the ways there are to specify boxes explicitly to TeX. (1) A character by itself makes a character box, in horizontal mode; this character is taken from the current font. (2) The commands \hrule and \vrule make rule boxes, as just explained. (3) Otherwise you can make hboxes and vboxes, which fall under the generic term ⟨box⟩. A ⟨box⟩ has one of the following seven forms:

\hbox⟨box specification⟩{⟨horizontal material⟩} (see Chapter 12)
\vbox⟨box specification⟩{⟨vertical material⟩} (see chapter 12)
\vtop⟨box specification⟩{⟨vertical material⟩} (see Chapter 12)
\box⟨register number⟩ (see Chapter 15)
\copy⟨register number⟩ (see Chapter 15)
\vsplit⟨register number⟩to⟨dimen⟩ (see Chapter 15)
\lastbox (see Chapter 21)

[…]

In math modes an additional type of box is available: \vcenter⟨box specification⟩{⟨vertical material⟩} (see Chapter 17).

For each of these, there is a well-defined procedure for where the reference point ends up, based on the reference points of its constituents. Characters from a font already come w.r.t. a reference point. For the others, it's best to see this in pictures (taken from A Beginner's Book of TeX's Chapter 8: Boxes, which I recommend reading):

hbox

vbox etc

While creating the box, you can specify the width to be positive or zero or negative (instead of letting TeX compute them from the things you put inside it). You can raise or lower boxes. You can explicitly assign the width or height or depth of a box, to change them. But in all cases the behaviour is predictable and well-defined, so the answer is just: the reference point is wherever you asked TeX to put it. :-) If you know how you made the box, you'll also know where its reference point is.

Share:
1,146

Related videos on Youtube

Evan Aad
Author by

Evan Aad

Updated on August 01, 2022

Comments

  • Evan Aad
    Evan Aad over 1 year

    The following illustration of a generic box appears on p. 63 of the TeXbook:

    A generic box

    What is a box's reference point in the following pathological cases?

    1. The box has either (a) no width, or (b) no height and no depth, or (c) both a and b?

    2. The box has a positive width and either a positive height or a positive depth (or both), which were not explicitly assigned but calculated automatically, and one of the following cases holds.

      1. The box doesn't contain sub-boxes (but may contain other elements, e.g. glue)?
      2. The box contains at least one sub-box, but some of the sub-boxes -- possibly all of them! -- is shifted to the left or to the right, or raised or lowered?
    • Steven B. Segletes
      Steven B. Segletes about 6 years
      Define reference point. For example, in \rotatebox, the reference point may be defined for the rotation. In general, the fact that \ht and \dp have TeX meaning implies that the baseline is a common reference point for all boxes. Multi-line boxes often use [t], [c], and [b] reference points, which have a specific defined meaning. Of course, any package-defined reference point has no relevance to "tex-core"
    • Evan Aad
      Evan Aad about 6 years
      @StevenB.Segletes: I'm just beginning learning about boxes. I've added to my post an illustration of a generic box, which shows it has a reference point.
    • Steven B. Segletes
      Steven B. Segletes about 6 years
      The answer is where the left side of the box meets the baseline, I think, in all cases you mention.
    • Evan Aad
      Evan Aad about 6 years
      @StevenB.Segletes: And where does this occur in the situations I described?
    • ShreevatsaR
      ShreevatsaR about 6 years
      It's also interesting to ask about the cases where the width or height or depth are negative, I guess.
    • ShreevatsaR
      ShreevatsaR about 6 years
      Anyway, the answer to your question (AFAIK) is that there are a few ways to create boxes (\hbox, \vbox, \vtop, \vcenter, ...) and each of them has a well-defined answer to where the reference point is put.
    • Evan Aad
      Evan Aad about 6 years
      @ShreevatsaR: I agree. But I imagine that once I know the answer to the positive case, the negative case will be simply the mirror image, no?
    • Steven B. Segletes
      Steven B. Segletes about 6 years
      If you put on your Gutenberg printing-press hat, it should become a much clearer mental picture, since TeX is designed to mimic the process of literal type-setting.
    • Evan Aad
      Evan Aad about 6 years
      @StevenB.Segletes: The cases I enumerated are exactly those where a Gutenberg printing-press visualization breaks down. Does a Gutenberg printing-press have a piece-of-type of width 0?
    • David Carlisle
      David Carlisle about 6 years
      @StevenB.Segletes I'm pretty sure Mr Gutenberg didn't have any boxes of width 0pt and height -4cm :-)
    • Steven B. Segletes
      Steven B. Segletes about 6 years
      @DavidCarlisle C'mon, I can certainly visualize a piece of type that, in its limit, has zero height, width, and/or depth. There is no conceptual confusion that need arise from that. Negative, maybe a bit of mental stretch to visualize it, but not too much.
    • Johannes_B
      Johannes_B about 6 years
      Completely unrelated: Have you seen the youtube videos of Knuth explaining TeX in the early eighties? youtube.com/watch?v=C3vILM2cNuo More advanced videos follow up.
    • Dr. Manuel Kuehner
      Dr. Manuel Kuehner over 5 years
      @Johannes_B Thanks for the Knuth video link! I will watch it late night :)
  • Evan Aad
    Evan Aad about 6 years
    But how can I determine where the reference point of a given box is? Suppose, for instance, I have a vertical box a containing a single horizontal box b that is shifted 1cm to the right. Where is a's reference point?
  • David Carlisle
    David Carlisle about 6 years
    @EvanAad by definition it is at the left edge of the box \dp from the bottom and \ht from the top. If you have not explictly set those lengths as above then it depends how the box contents were assigned, and your question should be rather different, for example "what is the height of a box defined via \vtop as opposed to \vbox ?"
  • Evan Aad
    Evan Aad about 6 years
    Yes, I assumed that these measurements were not explicitly assigned.
  • David Carlisle
    David Carlisle about 6 years
    @EvanAad then in the example in your comment the answer is that the reference point is 1cm to the left of the reference point of the inner hbox, and with \vtop and \vbox it will be at the same vertical position as the reference point of the inner box, and with \vcenter it may be above or below the reference point of the inner box depending on that boxes height and depth
  • Evan Aad
    Evan Aad about 6 years
    OK, I think the key is the term 'current position` that you used in your answer. Is the current position always defined, from the moment the TeX "stomach" starts digesting the first token till after it's done digesting the last token? If so, can I output this position to the log, or in some other way see where it is at an arbitrary moment that of my choosing?
  • David Carlisle
    David Carlisle about 6 years
    @EvanAad it is a property of the current horizontal or vertical list, that is the meaning of horizontal and vertical mode, in h-mode boxes are placed with there reference point at the current position, which then moves left by the width, in vertical mode boxes are placed with their reference point below the current position prefixed by glue of an amount depending on the depth of the last existing item on the list and the height of the box being added and \baselineskip and \lineskip lengths
  • Evan Aad
    Evan Aad about 6 years
    And is there always a current horizontal list and/or a current vertical list? For instance, what's the current list just before the first token has been digested, and where is its "current point"?
  • David Carlisle
    David Carlisle about 6 years
    the initial list is "the main vertical list" as the only relevant property of an empty list is its current point it doesn't really make sense to ask where that is, it is just the point at which any content will be added.
  • David Carlisle
    David Carlisle about 6 years
    the default reference point for tex output is 1in from the top and 1in from the left of the page although pdftex allows that to be changed with \pdfhorigin and \pdfvorigin
  • Evan Aad
    Evan Aad about 6 years
    Thank you. Would you be so kind as to add this information to your answer, please?