What is the internal LaTeX working logic for \left and \right with delimiters?

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).


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.