I've read the LaTeX Companion and the TeXbook, but I am still struggling to understand how LaTeX works.

  • How \DeclareOption works?
  • Why should I end some lines with %?
  • How penalty works?
  • Where \if@twoside is declared?
  • What does mean \c@tocdepth >\z@?
  • What is the philosophy behind the @ letter?
  • ...

Is there any source of information (books, tutorials, advanced courses) that can help me not to use LaTeX but understand how LaTeX is built and how it works?

  • 2
    texdoc source2e for most of those questions. Some lines should be ended with % to avoid spurious spaces (see this post). @ was chosen as "internal" letter probably because plain.tex uses it too, but before that the internal letter was ~ – Phelype Oleinik Feb 7 at 17:15
  • 1
    Of course the question is also why you want to know these things. If you want to use LaTeX for typesetting documents then knowledge of the internals is not really needed (except maybe for %). If you want to program your own package or documentclass then some things you mention here may be useful but others are still unnecessary. Only if you are doing research into programming languages or if you want to reimplement the kernel or something similar then knowing things like this can help you further, but most people can safely stay away from the internals I guess. – Marijn Feb 7 at 17:57
  • 1
    the questions are also explictly asked with answers on this site, eg tex.stackexchange.com/questions/7453/… and tex.stackexchange.com/questions/48195/… – David Carlisle Feb 7 at 18:00
  • 2
    The short answer to "How to learn LaTeX internals" is that unfortunately there's no such book/tutorial/course/webpage. It seems to be that the culture in the LaTeX community is very “user”-focused: all "friendly" documentation is addressed to the user rather than to the aspiring developer, and if you're the latter you have to learn things on your own by studying examples of source code: there's hardly anything in between. Documentation on creating packages (1, 2, etc) doesn't go into programming techniques… – ShreevatsaR Feb 7 at 18:15
  • 1
    On the other hand you can find lots of stuff by reading questions on this site (a good starting point may be Where do I start LaTeX programming? and its linked questions e.g. this), the source code of various packages (often annotated), and various articles in TUGboat. There's just no single well-organized book-like introduction to LaTeX programming/internals. – ShreevatsaR Feb 7 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.