Those questions were came up when I was looking through The TeXbook around page 225 and solving the exercise 21.6 in there:

  1. In \leaders, are \vrule and \hrule essentially the same ? On the other word, what's difference between \vrule and \hrule in \leaders?

  2. Why both \vrule and \hrule can be used in \leaders? I wonder it's restricted horizontal mode under \leaders. Why both rules can be used in there. Is there any specific reason?

  • 1
    In tex.pdf the procedure for the output of a leader (§626) checks if type(leader_box) = rule_node then [...], so I'd guess that it doesn't distinguish hrule and vrule... Commented Nov 18, 2019 at 3:29
  • tex.pdf is new to me. What's that, and where can I find it?
    – agnagic
    Commented Nov 18, 2019 at 10:35
  • 1
    It's the documented source of TeX. If you're a command line person using TeXLive, then texdoc tex opens that file. Otherwise, there's a copy in texdoc.net. But apparently my guess was completely wrong :-) Commented Nov 18, 2019 at 11:46
  • Thanks for suppling the source. Actually both \hrule and \vrule are denoted as \rule together in analysis with \showbox. The more I think about it, the more I get confused why \rules are distinguished into \vrule and \hrule in general usage...
    – agnagic
    Commented Nov 18, 2019 at 12:22

2 Answers 2

  1. There is absolutely no difference between \vrule and \hrule when used in \leaders, except for the defaults (for \vrule a default width of 0.4pt and “running” height and depth, and for \hrule a default height+depth of 0.4pt+0pt and “running” width). In other words, if you explicitly specify the width, height and depth, then there is no difference at all.

  2. Regarding "I wonder [whether] it's restricted horizontal mode under \leaders": the specification inside \leaders is not restricted horizontal mode; it is simply a box specification. The question of horizontal/vertical mode applies only to how boxes are put together.

  3. Regarding "why rules are distinguished into \vrule and \hrule in general usage": it's only for convenience in indicating your intent or avoiding mistakes, e.g. in vertical mode a \hrule stays within the same list but a \vrule starts a new paragraph, while in horizontal mode a \vrule stays within the same list but a \hrule shows an error. I guess this also answers "Why both rules can be used in there": in \leaders there's less scope for error, or wanting the "wrong" kind of rule is less weird, etc. (As The TeXbook says on p. 225 that you mentioned: "This is a case where \hrule makes sense in horizontal mode, because it gives a horizontal rule in text.")

Elaborating on (1) above: this is clear if you look at the source code of TeX. (Invoke texdoc tex.pdf or get Volume B of Computers and Typesetting.) The source is not organized in a way that makes it easy to "prove" this, but the following is based on reading all the sections where any of the strings "vrule" or "hrule" appears, and their dependencies. Basically, it works as follows:

  • TeX defines internal command codes vrule and hrule (in section §208, part of “Part 15: The Command Codes”). The primitives \vrule and \hrule are defined to have these command codes (in §265 of “Part 18: The Hash Table”). So when \vrule or \hrule is seen in the input, TeX translates it into the internal command vrule or hrule respectively.
  • Similarly, TeX defines internal command code leader_ship (possibly a pun on the fact that it's used for both leaders and \shipout, and the word "leadership") for \shipout, \leaders, \cleaders and \xleaders.

These commands (vrule and hrule) can be encountered in two contexts.

  1. When in the main control loop TeX encounters the vrule or hrule command in horizontal mode / vertical mode / math mode, the action that it takes is given:

    • for mmode + hrule: in §1046 (insert_dollar_sign, i.e. show error and re-sync),
    • for (the common cases) vmode + hrule, or hmode + vrule, or mmode + vrule: §1056 (just call scan_rule_spec to get a rule node, and append to the tail of the current list).
    • for vmode + vrule: in §1090 (start new paragraph and back up input, i.e. go to previous case),
    • for hmode + hrule: in §1094 (show error etc).
  2. The other is in the case of leaders. When in the main control loop TeX encounters any of these "leader" commands, the action it takes is given:

    • for any_mode(leader_ship): in §1073 (call scan_box with flag saying which kind of leader or shipout). This scan_box procedure is defined in §1084: it too (in the case of leaders and current command being vrule/hrule) calls scan_rule_spec and then calls box_end (which looks for the trailing \hskip or \vskip in §1078, depending on the current mode).

To summarize the control flow in the cases so far:

control flow

The main case is therefore the call to scan_rule_spec. This function is defined in §463, and it is the only place (apart from the top-level cases in (1) above) where vrule versus hrule matters:


Here, as you can see, the newly created rule node starts with a default of “running” dimensions (i.e. “running the rule up to the boundary of the innermost enclosing box”, per §138 and §139), but depending on whether the command is "hrule" or "vrule", different width / height / depth is assigned. But any following width or height or depth specified immediately overrides those defaults, so as long as they are specified, the effect is exactly the same whether the command was originally "vrule" or "hrule".

  • On the defaults: Although with finite values they are equivalent, note that \hrule is the only way (apart from some tricks with fractions maybe) to get a running dimension ("*") for width, and \vrule for height. Commented Nov 20, 2019 at 1:29

Not equivalent at all. First let's analyze what happens in vertical mode.

A call \leaders\vrule will use the defaults for a \vrule when height, depth or width are not supplied. For instance,

\def\init{\hsize=3cm\parindent=0pt x\par}

\vbox{\init\leaders\vrule width1pt\vskip1cm}


\vbox{\init\leaders\vrule height1pt\vskip1cm}


will draw 1cm high rules, the first 1pt wide, the second 0.4pt wide. To the contrary,

\def\init{\hsize=3cm\parindent=0pt x\par}

\vbox{\init\leaders\hrule width1pt\vskip1cm}


\vbox{\init\leaders\hrule height1pt\vskip1cm}


will print two 1cm high rules, the first 1pt wide, the second 3cm wide (an ugly big black rectangle), because the default is to use the width of the enclosing box that comes out to be 3cm because of \init that typesets a paragraph.

You can try and see the differences in horizontal mode.

  • Then, If I added next two lines above, can I say those two are equal? \vbox{\init\leaders\hrule width0.4pt\vskip1cm} and \vbox{\init\leaders\vrule\vskip1cm}. Also, there is another question. it looks that even if height was supplied in \leaders in vertical mode, it would be canceled because of skip supplied in \leaders. Is it right?
    – agnagic
    Commented Nov 18, 2019 at 12:08
  • @mowgiu Yes, it's (almost) irrelevant. I'll supply something later.
    – egreg
    Commented Nov 18, 2019 at 12:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .