3 ms·
TeX by Topic was a much clearer resource to me than the TeXBook although one eventually has to go back and read that. TeX seems like a reasonable approximation
by fusiongyro 10y ago
TeX by Topic was a much clearer resource to me than the TeXBook although one eventually has to go back and read that. TeX seems like a reasonable approximation of it, but it's definitely slanted towards text-heavy and mathematical stuff, which is pretty far from what something like InDesign is mostly about. I'm just an appreciator, not an implementer, but this is my overview of typesetting text:
First, you have to build words from letters; this is where kerning comes into it.
Second, you have to build lines. TeX calls this "horizontal mode" and this is where inter-word spacing and justification matter. TeX uses a "boxes-and-glue" model, so during line building it's essentially putting stretchable glue between each word, and then when the line is built, it spreads the space evenly between all the pieces of glue to achieve justification. Glue has a natural size as well as minimum and maximum values; this along with hyphenation has to do with calculating the line "badness."
Third, you have to build paragraphs. This is what TeX calls "vertical mode." Between each line of text, it inserts vertical glue that works similarly to the horizontal glue mentioned above. Another glue is used between paragraphs. TeX worries about widow and orphan lines here; other calculations are made to prevent or allow them. This is like badness but I think it has another name.
Finally, you have to build pages. With TeX, this happens periodically as it notices it has enough material (or you force it by calling the right kind of eject). By default, this invokes a page building macro which you can customize. This part of TeX feels pretty 1970s and hackish, but essentially, there is a variable that contains a box with the supposed contents of the page, your job is to assign a box to a certain location and remove some of the contents of the input box. LaTeX's "float" mechanism is actually built on top of this mechanism, but as it's pretty procedural, you can certainly achieve other effects here.
So that's the birds-eye-view I acquired a few years ago when I did some in depth playing with TeX. First you build words, then lines, then paragraphs, then pages. There are different considerations at each stage of that but TeX attempts to subsume everything in that overall flow.
I think that process probably generalizes nicely for some things and is almost inadequate for others. I'm not sure how ConTeXt achieves the grid layout; I imagine they are relying on some complicated Lua code to pull it off, because TeX really doesn't care unless you make it.
- Mikhail_Edoshin 10y agoThere's also TeX: The Program that is a literate code for TeX. It's in Pascal though and littered with literate macros, so it's rather hard to read.