6

I am reading about latex and in several books is written that to be able to size the delimiter to the vertical size of formula I need to use \left and \right. I understand that part. But I am interested what is the internal LaTeX working logic for \left and \right with delimiters? What \left and \right are doing at the software level?

  • 1
    The exact algorithm for sizing and the parameters it uses is explained in appendix G of the TeXBook (it is controlled by the underlying TeX engine, not by LaTeX) – David Carlisle Sep 1 '18 at 14:15
13

When TeX encounters material in math mode, it creates a math list. A math list is a list of nodes (they are called noad here), sometimes containing sublists, representing all the things written in math mode.

If you write

$f\left( stuff \right)$

the block with the delimiters is put into a sublist with math class inner, as if you wrote

$f\mathinner{\left( stuff \right)}$

Then TeX converts the \mathinner part without \left( and \right) into a horizontal list to determine it's height and depth. Then TeX tries to add delimiters with height+depth equal to 2*max(height,depth) from this inner material.

How does TeX create this delimiters? The \delcode of the delimiter points to a character in a font, if this is big enough, TeX inserts it. Otherwise the character might contain a next field indicating the codepoint of the next larger variant. Then TeX tries again with the bigger one. This repeats until TeX found a delimiter large enough or an extensible delimiter. Extensible delimiters have multiple parts which can be stacked on top of each other and repeated to form arbitrary large delimiters. They are always big enough, but they have to consist mostly of vertical segments.

The last part can be customized with the just released new version of LuaTeX.

For further details, it is best to read The TeXbook, Appendix G, Rule 19 (see also p. 152).

  • +1, great answer, maybe Moriambar should have made a post about that in his "appendix G question series". – TeXnician Sep 1 '18 at 14:31
  • To be fussy, the field that points to the next larger character is labeled NEXTLARGER in the output of the tftopl program. (I wouldn’t have remarked this if you hadn’t written next within backticks… ;-) – GuM Sep 1 '18 at 23:48
  • @GuM I recently worked a lot with the LuaTeX font table, so I used the name from there and expected it to be the "standard" name. But you're right, tftopl might be a better reference. Feel free to edit it in. – Marcel Krüger Sep 1 '18 at 23:59
  • I think that it is more than enough to have the name used by tftopl cited in the comments! :-) Added: Rather, I’m going to improve the reference to Appendix G. – GuM Sep 2 '18 at 0:03
3

This is not quite an answer, but in a comment, the formatting is lost. Let's start with line 22328 and following of tex.web:

@ We have dealt with all constructions of math mode except `\.{\\left}' and
`\.{\\right}', so the picture is completed by the following sections of
the program.

@<Put each...@>=
primitive("left",left_right,left_noad);
@!@:left_}{\.{\\left} primitive@>
primitive("right",left_right,right_noad);
@!@:right_}{\.{\\right} primitive@>

So what does this say? This has nothing to do with LaTeX, they are TeX primitives. And basically, this says you should read the TeX book (as David Carlisle already commented the important part for this is appendix G) to understand what's going on here.

Alternatively, you may dig into the source code which is documented (see link above). So you could simply look up the missing references and you would, for instance, go on with line 13514:

And finally, we have |left_noad| and |right_noad| types, to implement
\TeX's \.{\\left} and \.{\\right}.

But as it would take quite some time to find all the corresponding source code, I come back to my recommendation to read the TeX book.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.