Where do I start LaTeX programming?

Being aware of the fact that this post is quite old, I would like to add two further resources which might be interesting when it comes to programming.

I think there are three categories which need to be mastered (perhaps not all in the same degree) in order to become comfortable around TeX programming:

  1. TeX programming. That's very basic, it deals with expansion control, counters, scopes, basic looping constructs and so on.

  2. TeX typesetting. That's on a higher level, it includes control over boxes, lines, glues, modes, and perhaps about 1000 parameters.

  3. Macro packages like LaTeX.

First, when I started programming in TeX, I found it difficult to get even one of them straight. I read the TeX Book, which is very strong when it comes to (2) and which is the best reference for (1) I am aware of. However, it does not introduce (1) very well, because its aim is to teach typesetting, not programming.

Since then, I have learned a lot - and I wrote an article about (1) which might be of interest for you. Furthermore, I stumbled about an online text book about TeX, which covers (1) and (2) pretty well - although it is only available in german.

Here are the resources:

  1. TeX programming notes (written by me). It is shipped with pgfplots or can be found here: http://pgfplots.sourceforge.net/TeX-programming-notes.pdf

  2. a free online book about TeX (in German!) https://epdf.pub/einfuehrung-in-tex.html

  3. As soon as you start programming packages, you will certainly want a user interface, i.e. key-value. Joseph Wright wrote an introductory article about it and I contributed a section about the relatively new pgfkeys. I would recommend using it, it is quite simple (provided one uses the mentioned article as introduction instead of the the complicated reference manual which is part of pgfmanual.pdf). The article can be found at http://www.tug.org/TUGboat/tb30-1/tb94wright-keyval.pdf .

I must honestly admit that I have longed for a good introduction about how to program in LaTeX - but I never found one. Finally, I got stuck with pgf which implements a lot of the utility functions, but I found it easier to understand.

Besides pgf, the best documentation for LaTeX that I found (besides the clsguide mentioned by Stefan) are the the LaTeX kernel sources (which he mentioned as well). But they are cryptic and require a very deep understanding about (1) and (2) before you can even read them.


You could start with LaTeX2ε for class and package writers aka clsguide.

We already have some information regarding this on the site, for example:

  • Style/class tutorials

  • Is there a comprehensive and complete LaTeX reference?

You could learn much if you would read the commentes LaTeX2ε sources aka source2e. To understand it best, you could learn TeX or use a TeX reference.


When I first got in contact with LaTeX, I bought Lamport’s LaTeX: A Document Preparation System, but, alas, I found it too superficial and didn’t understand many (even basic) things.

So, as I later took notice that all started with Knuth’s TeX, I felt that it might be the logical way to begin with looking at TeX. In consequence I bought Knuth’s The TeXbook, since it is the program’s manual written by the program’s inventor and creator. Actually it really was the right decision! It precisely describes exactly how TeX works:

  • how the input (file) is read and tokenized
  • how you define macros
  • how you use registers to do calculations

This book helped me to really understand TeX. In my opinion it can be considered as fundamental literature to gain a thorough understanding of TeX and as a basis for LaTeX.

(N.B.: I fell so deeply in love with TeX while reading The TeXbook that I never felt the need to use any other format. ;-) )