# Understanding LaTeX packages syntax

I've been using LaTeX for a few years for typesetting maths documents but I kind of feel there are two "kinds" of latex: the one I write my documents in and the one packages are written.

My goal is not to write a package, but trying to solve problems by my own. I often find myself searching for solutions to every problem I face and the answers always involve this syntax I'm talking about, full of @s, and things like \expandafter, \makeatletter, \makeatother, \catcode. Since I can't understant it, I simply copy it blindly.

What's the recommended resources for learning this not-so-basic latex stuff?

• I wrote a book, in order to learn (part of) it. It's in Italian, so it may not be what you're looking for. – egreg Jul 14 '13 at 20:12
• Welcome to TeX.SX! I'd recommend this book which covers plain TeX. – mafp Jul 14 '13 at 20:25
• I checked profs.scienze.univr.it/~gregorio/introtex.pdf and I guess that's what I was looking for, but unfortunately I can't speak italian. But I'll take a look at the references later, thanks – Post as a guest Jul 14 '13 at 20:27
• Much of this has been covered in other answers on the site: trying to explain everything in a single answer is really too much to expect. For example, you might look at What do \makeatletter and \makeatother do? to get some feel for \makeatletter. The usual recommendations (The TeXbook and TeX by Topic) almost always apply when looking at programming TeX. – Joseph Wright Jul 15 '13 at 12:31

Read the TeXbook. You have to pay for it, but it's worth it: not only is it totally complete (even more so than TeX By Topic, recommended by mafp in the comments) but it is an instruction manual rather than a reference manual. It has one drawback: it documents the plain TeX format in addition to the actual base TeX language, and completely disregards LaTeX and other formats (as it rightfully should). Unfortunately, it makes no clear distinction between what is a built-in feature of TeX and what is defined by the format, whereas TBT does (by not addressing the format at all). In practice, this means that you should skim the main text once and then focus on the dangerous bend stuff, which is the reference material.

I have heard complaints that the TeXbook is too chatty or written with a poor style. The fact that it has a style at all does open it up to such criticisms, but also makes it possible for it to interface with the reader on an intuitive level. If your intuition differs from Knuth's, there is no shame, but TeX is an outrageously difficult language to understand so it may help to appreciate the slightly eccentric mind of its creator.

• Then, for LaTeX, one has to read the documented source source2e.pdf – egreg Jul 15 '13 at 13:42
• @egreg: As a reference, yes. But it's not very well-written. I think the exam document class is very nicely constructed and may (as just one example) provide a better introduction. – Ryan Reich Jul 15 '13 at 15:13

LaTeX2e is very difficult to program in; I suggest you use the experimental versions of the LaTeX3 format. To load it, all you need is

\usepackage{expl3}


and documentation is available with texdoc expl3 and texdoc source3.