3

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.

Benjohn
  • 201
  • 1
    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 08:20
  • 1
    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 08: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) https://www.amazon.com/Computers-Typesetting-B-TeX-Program/dp/0201134373) – David Carlisle Oct 22 '18 at 09:00
  • 3
    It isn't clear what answer you could want other than say https://tex.stackexchange.com/questions/77918/how-does-tex-actually-work 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
  • 2
    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
  • I like to say that TeX simply put boxes inside other boxes. Every letter, line, paragraph and page (text area) is just a box. The most complicated parts deal with line breaking, hyphenation and page breaking. – John Kormylo Oct 22 '18 at 16:31
  • @DavidCarlisle Thanks – I'm hoping for a description of the underlying algorithm(s) Tex uses for layout. I'd like to understand it in computer science terms, for interest, and to perhaps make use of this in other (non Tex) places. From Knuth's paper and wikipedia, I understand it's a dynamic programming approach. From other answers and comments, I get the impression Tex's macro system allows this algorithm (or variants) to be employed in various ways? So I'd like to understand this interaction too. – Benjohn Oct 23 '18 at 20:57
  • From the TeXbook: “Communication with output routines. It would be possible to write an entire book about TeX output routines; but the present appendix is already too long”. – egreg Oct 23 '18 at 22:39
  • you haven't defined "layout" the line breaking algorithm is in tex-the-program page breaking also there but more minimal, but for example float placement is in the latex macro code documented in source2e.pdf, if you want column balancing then that is in multicol package documentation, there is no single "layout algorithm" anywhere you ar asking for the full documentation of the tex programmng stack which is available but not really anything you can put as an answer here. – David Carlisle Oct 24 '18 at 08:17

0 Answers0