tags:

views:

103

answers:

2

What are the differences between how CSS and Latex organize boxes? (Either paragraph or graphical elements.)

+1  A: 

The specs for CSS are not hard to find and of course they contain a chapter on the box model.

The information is somewhat harder to find for LaTeX, but you can look here, where you can read:

LaTeX builds up its pages by pushing around boxes. At first, each letter is a little box, which is then glued to other letters to form words. These are again glued to other words, but with special glue, which is elastic so that a series of words can be squeezed or stretched as to exactly fill a line on the page.

I admit, this is a very simplistic version of what really happens, but the point is that TeX operates on glue and boxes. Letters are not the only things that can be boxes. You can put virtually everything into a box, including other boxes. Each box will then be handled by LaTeX as if it were a single letter.

I think this is very different from CSS, but for details I'm afraid you have to read books, e.g. The TeX book by Knuth, or the LaTeX companion by Mittelbach et. al.

Miel.

Miel
Actually, that chapter of the CSS specs contains nothing about the layout — the layout is described in succeeding chapters, "Visual formatting model" and "Visual formatting model details". It all seems more complicated than TeX's model; it would be nice to find someone who knows enough about both to compare them.
ShreevatsaR
+1  A: 

The general scheme, of having a hierarchical boxed representation of page layout produced from processing of input language, and that is then turned into the rendered page, is basically similar between the two models. The four differences that are most impressed on me are:

  1. The CSS boxes model is a robust abstraction, whilst the layout of boxes in the Tex model is operationally determined: as boxes are being laid out in the Tex model, the code can break apart and re-layout earlier boxes.
  2. While Tex's layout model is text-oriented, like the CSS boxes model, and as opposed, to, say Adobe's InDesign layout model that's very much about fitting together blocks to cover each page, it still has quite a few page-oriented abstraction, like determining "badness" of vertical space in order to place footonotes - there's nothing like that in the CSS boxes model that I can see. Context has a more sophisticated page layout model, that allows both text-oriented and grid-oriented layout together.
  3. Both the CSS model and the Tex model have notions of block-level boxes (vboxes) and inline boxes (hboxes). However, while you can specify using CSS that a block-level box occurs inside an inline box, section 9.2.1 of the CSS2 standard says that the semantics of this is to turn the outer inline box into a block-level box, so the CSS box model basically forbid block-level boxes from accuring within inline boxes. Tex, by contrast, is happy to have vboxes inside hboxes, which offers power to do things like place pieces of text above text inside a paragraph's text.
  4. Most importantly, the CSS box model has no notion of flexible glue, making scaleable page layout much trickier, and is, I guess, the reason why fixed-width page design is dominant.
Charles Stewart
Thanks! Great answer! Your points (3) and (4) are especially interesting.
Steve