21

Every now and then I need to compare LaTeX to HTML to someone, and it can be hard to give a succinct answer that demonstrates the purpose of both, and why one wouldn't want to abuse one for the purpose of the other.

Also, the differences cover several areas, such as target medium, layout vs markup, and so on.

Perhaps this would be a good place to collect a few answers for later reference.

1
  • Hi Nyiti! Although your question seems interesting, I think that it will be closed as being "not constructive". We are quite sensitive on such questions, because we really want to avoid discussion and posting "opinions", and this question basically asks for opinions. The fact that all the questions are kept to be very specific and non-vague makes this site so valuable. I hope you understand this, and if you had any questions, feel free to ask (for instance in the site chat).
    – yo'
    Commented Oct 18, 2012 at 17:32

1 Answer 1

17

I'm assuming you're asking about CSS in combination with HTML, since otherwise you can't really get any styling into an HTML document. There are plenty of differences — though don't forget about the many similarities as well.

(La)TeX has a very good knowledge of typesetting requirements and media.

  • (La)TeX will justify text, automatically hyphenate, provide proper spacing, and other typesetting features. (You can use XeTeX for even more typographical features.) The default article class has the text width optimized for readability. Most browsers don't have this type of functionality, and with HTML/CSS you have to manually specify sizes.
  • (La)TeX will paginate content and you can set up different page styles based on left/right pages for physical publishing purposes. HTML has no intrinsic knowledge of "page layout" in terms of a single physical page of paper. You can specify print-specific layouts with CSS, but pagination is not trivial.

(La)TeX and HTML have different positioning systems.

  • Some things are similar, like the layout of text in regions, and fine-grained position adjustment, but one primary way of positioning stuff with CSS is "floats" which allow much more control over positioning than LaTeX floats. At the same time, \hfill doesn't really have a CSS equivalent unless you use tables.

Cascading Style Sheets are cascading.

  • With CSS you can specify styles that are based on a hierarchy of elements on the page, rather than LaTeX's scoped inline style commands. Elements automatically inherit most of the styles from their parent but can be overridden based on any number of factors.

HTML documents are live and responsive.

  • You can't scroll sections of a typeset LaTeX, nor can you make extensive use of JavaScript to manipulate and live-update elements on the page.

  • CSS has @media queries that let you provide different layouts for different target media (everything from screens and printers to screen readers and 3D glasses — anything that any client uses), as well as different viewport sizes.

  • HTML is most often written with the expectation that it will be used in a browser, so it is very common to take advantages of features like the navigator object in JavaScript, "visited" link styling, etc. Nowadays, on mobile devices, you can even get access to hardware sensors such as an accelerometer or GPS.

Browsers get to make up their own features!

  • The only real authorities on what you can do with HTML and CSS (and JavaScript) are the browsers themselves. Many browsers have implemented exclusive new features, and these often lead to spec updates and eventually more widespread adoption. With LaTeX, the available features are dictated by what version of LaTeX you're using, and what packages are available.
3
  • 3
    One thing not mentioned in this (good) answer: Knuth's goals for TeX were quality and archival: (1) reproducing the finest quality printed books, and (2) produce documents that would generate exactly identical (or equivalent) output for decades, despite any changes to (computer- or) printing technology. I think neither of them is a goal for HTML+CSS, which remain a poor fit for both these goals. Commented Jan 2, 2017 at 4:22
  • 1
    Incidentally there are some comments by Knuth about this page versus screen/web thing, in the interview by Advogato here (also published in TUGboat here), in the answer starting with "This wouldn't go too well to the web" and 3 questions or so on each side. (Different browser widths versus a fixed page and all that.) Commented Jan 2, 2017 at 5:25
  • Thank you for this good article but I think it is very important to differentiate between TeX ("typesetting language") and LaTex ("Markup Language"). More information see here: tex.stackexchange.com/questions/202791/… And therefore the question should rather ask for a comparison between Tex (Typography / Typesetting Language) vs CSS (Cascading Style Sheet Language) AND LaTex ("Markup Language") vs HTML (Hyper Text Markup Language).
    – becke-ch
    Commented Feb 21 at 11:23

Not the answer you're looking for? Browse other questions tagged .