73

I've been using LaTeX for about a year or two as part of writing reports in university and want to gain a more in-depth understanding of how it works (I'm a computer science student).

Would Donald Knuth's The TeXbook be a recommended read for me? What does it cover? What is your impression of it, those who have read it?

gablin
  • 17,006
  • 16
    Yes, You should read it. As Knuth says, it gives you every single detail about TeX and how it works. I am Persian and since English was not my mother tongue, I had difficulties understanding TeXBook and I had to read each concept several times until I could understand them. – IRAN Feb 11 '11 at 15:05
  • 7
    read the TeX by Topic from Victor Eikhout. It is much more readable than the TeXbook –  Feb 11 '11 at 15:10
  • 8
    Since this question asks for impressions and experiences of several users, not for a best answer or solution, I suggest converting it to community wiki. – Stefan Kottwitz Feb 11 '11 at 15:10
  • 1
    Since you are a computer science student --- i'd say you should .) – brownian Feb 11 '11 at 15:12
  • 2
  • 2
    since you are a computer science student, you might also dip into the source of TeX: the Program, which demonstrates knuth's philosophy of responsible programming style. echoing @Herbert's comment, do read TeX by Topic to learn how TeX works, but not instead of the TeXbook. – barbara beeton Feb 11 '11 at 16:33
  • 16
    @Herbert: I disagree; the TeXbook has very elegant prose, a natural development, and is much more readable as literature. TeX By Topic, however, is much better as a technical manual: as the title says, it is organized by topic, so there's no danger of having to look in five different places for complete information about some builtin. And it has very useful examples. – Ryan Reich Feb 11 '11 at 21:02
  • @Ryan: feel free. You like this book, I like that book. no more no less ... –  Feb 11 '11 at 21:04
  • @Herbert: I agree. TeX by Topic is more readable and better organized. TeXbook just jumps from one point to the other and makes the reader confused. – IRAN Feb 12 '11 at 06:28
  • 8
    @Vafa: The TeXbook is not organized as a reference manual of TeX as TeX by Topic is. Knuth is clearly aiming to teach the novice reader how to use TeX to produce beautiful books and the advanced reader (dangerous bend sections) more advanced material. As such, Knuth starts with a very basic example of a .tex file and works up to macros, math, tables, and all of the advanced topics. I don't really recall The TeXbook jumping from topic to topic. There's a fairly logical progression of ideas. – TH. Feb 15 '11 at 06:07
  • Also read: The Errors of TeX by Knuth. Reprint in ISBN 0-932633-14-5. –  Jul 02 '22 at 20:29

5 Answers5

56

If you want an in-depth understanding of LaTeX you can start somewhere else. However, if you want to really understand TeX then there is no way to avoid the great TeXBook! (I actually ordered the whole 'Computers & Typesetting, Volumes A-E Boxed Set' just two weeks ago. It's still on its way to Europe -- the US prices are so much cheaper :-) )

It explains a lot of how the TeX engine works. I really just started to understand some of the fine mechanics of it after reading this book.

The sources of The TeXBook are on CTAN, so you could have a peek in it (in source form only). There is also TeX for the Impatient as a full PDF document. However, I didn't read that book yet.

Martin Scharrer
  • 262,582
  • "the US prices are so much cheaper" — weird, because in the U.S. the Indian/east Asian versions of books like that are cheaper than domestic... – Andrew Feb 15 '11 at 03:34
  • @Andrew: That books are, as originals, of course more expensive in Europe because of shipping, customs and the share the retail trader gets. Here it happened that the Amazon.com price (reduced)+shipping was cheaper than the Amazon.de price (also reduced, but less) with free shipping. Anyway, I just figured out that I have to pay customs and claim the book from the customs office, so it isn't really cheaper. The last time I ordered such books (Companion set) from Amazon.com I did so from Ireland which has 0% VAT on books, which made the order smoothly and made me forget about customs this time. – Martin Scharrer Feb 15 '11 at 09:30
  • Tex for impatient -- is an annoying advertisement of The TeXBook. – Yola Feb 18 '22 at 14:14
39

If you want to gain an in-depth understanding of the TeX family, you will certainly read the TeXbook, early or late.

There are electronic versions of "TeX for the Impatient" and "TeX by Topic" (already installed in TeX Live, but not MiKTeX). They are easy to achieve, and can be additional supplements or alternate of TeXbook. Anyway, TeXbook is still worth to read.

Since you are a LaTeX user, you may also read the documented source code of LaTeX, say source2e and classes document, and source code of any package you are interested in. This may be what Martin said a start somewhere else about LaTeX. I learned a lot from others' code, no less than from the books.

Since you want to understand how TeX works, you may also need knowledge of MetaFont, modern TeX engines (eTeX, pdfTeX, XeTeX, LuaTeX, ...), PostScript/PDF drivers (Dvips, dvipdfmx, ...), WEB2C, and so on. For an overview of TeX family, I suggest "An overview of TeX". These may be as important as TeX language itself.

Leo Liu
  • 77,365
  • 1
    The @name syntax doesn't work in answers, just comments. You have a typo "electric versions" should be 'electronic versions', shouldn't it. – Martin Scharrer Feb 11 '11 at 16:19
  • @Martin: I didn't know much about the @ notation, thanks. And for the typo. (I'm not good at English.) The using of double quotes is just a custom. – Leo Liu Feb 12 '11 at 06:00
  • My take on Tex By Topic is that it does not present topics sequentially, so you are sometimes left wondering what something means or does until it is later introduced. For example, \number\count is used in Section 1.3.3 without explanation. – Paul Wintz Sep 06 '23 at 08:31
22

Yes, you should definitely read it. I also have a background in Computer Science, and I first read The TeX Book ~5 years after I learned LaTeX; I seriously regret not having read it sooner.

The argument for a LaTeX user to learn TeX is similar to the argument for a C coder to learn assembly: You can program just fine in C without understanding assembly, but it's often useful to know what is going on behind the scenes.

As for first reading alternative texts, I think there is something to be said about reading the manual written by the guy who created TeX in the first place. Isn't that why most C++ programmers first read Stroustrup's book? I also find Knuth's writing style to be very entertaining.

ESultanik
  • 4,410
  • 1
    I agree; other books and articles are better at explaining different aspects of TeX/LaTeX, but I think the TeXBook does the best job at making TeX interesting. – MSC Aug 08 '14 at 19:10
8

IMHO, no. It is a waste of time, unless you really need to do TeX hacking. You cannot really understand the book in the first read, nor in the second, or third. And, I am not sure there is broad computer science added value to the book.

Yossi Gil
  • 15,951
  • 4
    In computer science, TeX is a good example of macro programming language. (This kind of language is rare) – Leo Liu Feb 13 '11 at 06:19
  • 2
    @Leo: I cannot agree less... There are a number of macro programming languages, including e.g., M4 and the C preprocessor. Some are good, some are not as good. But TeX is not one of them. – Yossi Gil Feb 13 '11 at 11:08
  • OK, I made a mistake. I don't like the disadvantages of TeX macros either. I intended to say, TeX is a widely used and speical language that worth to understand for a CS student, even if we don't like it. – Leo Liu Feb 13 '11 at 14:41
  • @Leo, perhaps a CS student can do better than a CS prof, or better said, me. I could never work out the inner logic, spirit, and/or rationale of the TeX trickery -- yes, I figured it was all very clever, but it would have been even more impressive if the cleverness was hidden, so that you could use it without being so clever yourself -- but this could be just me. – Yossi Gil Feb 14 '11 at 07:20
  • 6
    @Yossi: Like any style of language (imperative, functional, logical, etc.), macro programming languages simply require a different mindset. TeX may have some flaws, but its macro expansion seems pretty solid to me. – TH. Feb 15 '11 at 06:00
  • @TH: I am not so sure that macro programming requires a different mind set, or that it even borders on being a different paradigm. However, even if it was, there are fundamental "clever" ways in which TeX was designed that contradicts that of any other programming language I can think of, and at the same time, so few of the established methods of doing things were reused in TeX. Named Variables? Yuk! Named parameters? Why bother! Control flaw? assembly-like, whether you like it or not. Literals? You must be joking! Expressions? Let's do it the Cobol way, only a bit more complicated. – Yossi Gil Feb 15 '11 at 07:06
  • If you insist, TeX should be compared to PHP, ASP, JSP and the like, in which commands producing text are intermixed with the text itself. These may not be perfect, but at least you can get the gist of each quickly. – Yossi Gil Feb 15 '11 at 07:09
  • @Yossi: You make fair points. But named variables? Nothing local in Plain TeX or LaTeX, but \newX for several values of X mean you don't have to use register numbers. Certainly one can use \def for local macros. No named parameters, sure. The control flow isn't assembly like at all. Assembly gives you conditional jumps. TeX gives you macro expansion. Both Plain TeX and LaTeX have foreach and while loops. Throw in grouping and you can get function calls with local scope for your \defs. I'm not sure I follow your complaint about literals, but expressions are bad. e-TeX fixed that though. – TH. Feb 15 '11 at 08:08
  • 1
    You can work around some of the flaws, sure enough. I can do \newcount to define a new integer variable using the registers, but why should I worry about registers? And why should I even be told that 0-9 and 255 or whatever are special? So much for variables. What I mean in control flow being assembly like is that you do not have true if statement and iteration is complex, you have to really understand expansion. But, please do not take my work for it: try to see how long does it take one to get a working knowledge of "non-standard" language such as postscript, vs. a working knowledge of TeX. – Yossi Gil Feb 15 '11 at 13:18
  • @TH, take a look at recent questions regarding iterations on list of words, and you would see what I mean. I did not see any of the answers using the iterations you mention – Yossi Gil Feb 20 '11 at 23:29
  • @Yossi: "Why should I worry about registers" strikes me as asking why you should learn about the language. I have no idea how you can claim there aren't true if statements, there are many \ifX...\else...\fi statements. As for answers here not giving appropriate control structures as answers, that's not a failing of TeX... – TH. Feb 21 '11 at 07:01
  • 3
    Dear @TH: What I mean is that I do not wish to worry about register numbers. I wish that I could define variables, with types, just as I can with any other programming language, and let the underlying system take care of allocation for me. \newSomething approximates that. Let me also clarify what I say about if statements: they are not general purpose in that you cannot just check the value of a Boolean expression - you would have to define a new Boolean variable using a \newif. This, and other annoyances take all the pleasure from reading the TeXBook IMHO. I just want to get the work done. – Yossi Gil Feb 21 '11 at 08:51
  • @LeoLiu why should Tex Language be a GOOD example of macro language? – Daniel Bandeira May 07 '23 at 00:41
  • If your aim is to use TeX/LaTeX to write a text, mathematical or not, I recommend you avoid reading about TeX like you would avoid the bubonic plague. However, if your aim is to write a PhD thesis on TeX you have no choice. Which does not contradict my admiration for Donald Knuth the mathematician and computer scientist. – Reinhard Neuwirth Mar 05 '24 at 00:38
8

Of course everyone should read the TeXbook. But if you are a proficient LaTeX user who is pressed for time, I'd suggest just a few chapters (until you get hooked). Chapter 7 for character codes and tokens: you should know about tokens. Chapter 12 for TeX's treatment of spacing. Chapter 18 for good style in the input of math formulas. Skim Chapter 20 on macros and Appendix F on font glyphs and their classification. Even if you stop there, you'll have a good appreciation of how LaTeX really works.

jvarilly
  • 445