# How does Tex layout engine work

Would it be correct to say that somewhere within Tex, there is a layout algorithm? If there is, is a description of the algorithm and abstractions it consumes and produces available?

A question and answer here address How does Tex actually work, but don't cover the layout process I am hypothesising.

Another question here asks if Tex layout can be decoupled from it's macros, and a comment on that links to Knuth's paper Breaking paragraphs in to lines, which seems like a relevant place to start reading.

Sorry if I've chosen a poor tag. I need to add at least one, and none I've found matching "algorithm" or "layout" seem appropriate.

• The thing is, there is not one single 'layout algorithm'. You have already linked to the key one at the engine level: breaking paragraphs into lines (there's also breaking pages). A lot of the rest, for example floats, is done in macros ... so depend on the format in use. – Joseph Wright Oct 22 '18 at 8:20
• The process of breaking paragraphs into line, and breaking paragraphs and lines into pages, is described in detail in the TeXbook. I think that is the reference; clearly, output routines (the ones that generates the page) can be different in different engines and even in different packages. – Rmano Oct 22 '18 at 8:21
• The full documented sources are available as source (tex.web) or as a book tex the program (volume B where volume A is the TeXBook with user documentation) amazon.com/Computers-Typesetting-B-TeX-Program/dp/0201134373) – David Carlisle Oct 22 '18 at 9:00
• It isn't clear what answer you could want other than say tex.stackexchange.com/questions/77918/… I think this is a duplicate. That doesn't mention "layout engine" but that isn't a defined term and so your initial question "does tex contain a layout engine" can perhaps be answered just by saying that tex is a layout engine so asking how tex works and how its layout works are not separable questions. (I haven't voted to close as duplicate as I have gold tex-core badge so it would close immediately if I did: better to allow voting in this case, I think) – David Carlisle Oct 22 '18 at 10:32
• What do you mean by a layout engine, i.e. what do you want to know? IMO (as I said in that comment) I think if you read the Knuth-Plass paper you'll get a fair idea of how many layout things are achieved (not including things like floats or “alignments” ≈ tables), then The TeXbook, the TeX program, or other sources like TeX by Topic should cover the rest. If you've skimmed these and are sure your question isn't answered, you can ask it more clearly. – ShreevatsaR Oct 22 '18 at 11:40