[Tex/LaTex] A LaTeX course for intermediate users stuck on the learning curve

teaching

Background: This question is aimed primarily at those of us who have been using LaTeX for quite some time but feel like they do not have a very "principled understanding" of it even though they would like to (i.e. those of us who want to go from intermediate to advanced but feel lost at sea).

TL;DR: Does anyone know of a course like structure (MOOC or otherwise…Udemy and Coursera have nothing of value) for intermediate LaTeX users to learn LaTeX in a "principled fashion"? Those of you who teach LaTeX at your universities, how are your courses structured (if you don't mind sharing)?


To keep this question relatively short, I'd simply like to say I've been using LaTeX now for a number of years and have never ceased to be amazed by its capabilities and even more so by the incredible support group here on TeX.SE. I've read several of the other questions somewhat related to this:

The frustrating thing is that most educational LaTeX material seems to be geared towards either those who are just starting out or those who are much more advanced. For example, I look at the content of that Udemy course (and this is not meant to be a knock against it) and am rather surprised by the "advanced content" (all things I am fully comfortable with doing and have done before). But I look at something like the computer science behind TeX/LaTeX by Eijkhout and immediately feel a bit out of my depth.

So far my approach to learning has been to simply learn what's necessary as I encounter different problems (and post here on TeX.SE when I can't progress). Even when I have seen questions on here that I feel like I may know how to answer, I never do because I know several of the gurus here have a "proper" way of going about it all. I also know some members teach LaTeX at their universities (egreg and gonzalo come to mind).

In sum, I am eager to learn LaTeX in a "principled way" (understand the code for packages, be able to write my own, etc etc) but am lost as to how to do it effectively without a course like structure. Simply reading through the TeXbook, LaTeX and Friends, The LaTeX Companion, etc. etc. is not really cutting it anymore (it's so easy to get overwhelmed by the sheer volume of different books that one has great difficulty proceeding in a linear fashion). A well-defined structure would help a great deal.

Best Answer

The problem: different users have different interests (and needs) and therefore different ideas of what counts as "intermediate" (beyond the basics), as pointed out by Joseph Wright in a comment above. This was perfectly elaborated by Christian Feuersänger in this answer from 2011: he categorized three kinds of things that post-beginner (La)TeX users may like to learn (which I'm rephrasing), and only you can decide what is important to you:

  1. TeX's features for typesetting specifically: the box-glue-penalty model, alignments, a few parameters and features built into the program like \parshape and the like. Basically: viewing TeX's output (each page) as a giant box made up of boxes laid out in sequences vertically (e.g. lines of text) and horizontally (e.g. characters within a line) with appropriate glue between them, and learning how to make a page look like some predetermined ideal you already have in mind.

  2. TeX's facility for programming: the intricacies of macro expansion: what do terms like \xdef, \expandafter, protected and fragile, \csname mean? How do you write macros that do the work you want them to do? How can you use the features provided by expl3 to make this easier?

  3. The package ecosystem: the facilities provided by LaTeX itself, and by the most important of the thousands of packages available on CTAN. For example, LaTeX itself provides features like automatic numbering (you just type \section and somewhere behind the scenes a counter is incremented and it comes out numbered), cross-referencing (\label and \ref), and so on. There are packages for specific fields (mathematics, chemistry, linguistics), for specific languages, for specific kinds of documents (presentations, drawings), etc.


Now the fact is, for most people who are users of LaTeX, the thing that is probably most useful to them, and in that way most worth knowing, is (3). “How to draw X in TikZ” is something about the features present in the TikZ package. The knowledge that package Y exists for drawing chemical diagrams or grammatical parse trees is something specific to the domain you work in. The knowledge that the “recommended” way to set page margins to use package geometry, or whether to use beamer or powerdot or prosper for presentations, or that \usepackage{hyperref} should come towards the end of your list of included packages, are all of this nature.

In short, a lot of this is knowledge about the “state of the world”: about what packages people happen to have written, what features (and bugs!) those packages happen to have, even how good and up-to-date those packages are — all of these are “contingent” and will even change with time. There is no “core” to this, and not necessarily much consistency because they were written by many different people. You can look at the “banner ad” at https://www.ctan.org/pkg to see a bit of the menagerie of packages that exist. This is the core of the difficulty you mention in the question (learn LaTeX in a "principled way" […] great difficulty proceeding in a linear fashion … A well-defined structure would help), and it is unavoidable as far as I can tell.

A post-beginner (“intermediate” or “advanced”) LaTeX course that goes deeper into any of this will be restricted to some people's uses for LaTeX, and possibly go out of date. And yet this is what most people want and need, so you can consider specific books targeting specific users' needs: the linked LaTeX for Administrative Work by Nicola Talbot above (see its table of contents), or Grätzer's More Math into LaTeX (not free, but see what's available on CTAN to get an idea) are particularly good examples of this.


That leaves categories (2) (macros) and (1) (typesetting primitives). Some people, by "intermediate" or "advanced", mean (2): being able to write and understand macros. This is essentially a new way to program, compared to any other form of programming you may be familiar with. See Notes on Programming in TeX for a (very useful) flavour of things. People have written a BASIC interpreter, the incomparable xii.tex, an Othello game (named reverxii as a tribute to the former), a controller for a Mars Rover… so it's definitely possible to do things in it. Much of LaTeX3 work hitherto has apparently gone into expl3 which makes this easier. This is something one can probably pursue, trying harder and harder exercises until they're proficient at writing macros. (I'm not aware of such a book or resource.)

Personally I find programming in macros rather perverse. :-) (Not just xii.tex and the like, but even the code of typical packages, and of LaTeX itself.) Whatever its other merits, TeX does not have a great programming language in it (see the answers to this question). (There are some comments of Knuth indicating this was intentional, but he did not foresee that people would go to great lengths to program in it anyway.) So personally (and this is a minority opinion in the TeX community, perhaps I am even a minority of one, simply out of not having thought this through well enough): I would prefer a style of TeX usage that involves as few macros as possible. (This is not specific to LaTeX: it would apply to ConTeXt, to plain-TeX packages like opmac, probably every way in which TeX is used currently.)

Nevertheless it (proficiency in TeX macros) is something learnable, and may be a concrete answer to your question.


Finally, that leaves (1) (typesetting). At heart TeX has a startlingly simple and unexpectedly versatile model of typesetting: breaking paragraphs into lines using the box-glue-penalty model. It sounds like something that's only about normal paragraphs of text (and that's what it was designed for), but with appropriate choices of your boxes, glues and penalties, you can achieve practically everything you've ever seen in a document typeset with (La)TeX (and more). The power of this model, despite its unifying simplicity (which was something noted by early reviewers of TeX, like Kernighan who worked on troff), was something of a surprise even to Knuth and he says it took him years to learn more and more things that could be done with it. (Of course from a certain perspective you could call these things hacks, but I find them very elegant.)

This is the part I personally am most interested in (somewhat unusually I think); this is also the thing that is directly against LaTeX's philosophy, which is to focus on the content / document structure, and leave the formatting to the packages you use. And if you're happy with that, you probably don't have to learn deeper here (unless you want to write your own packages that provide formatting, and suddenly you have to learn all the things that your packages were helpfully trying to hide from you). If you do want to learn more about what I consider the core of TeX typesetting, I can recommend what I think are the two best resources (even better to learn from than The TeXbook, which you can read next):

  • The book A Beginner's Book of TeX by Seroul and Levy. This is such a lovely book: it is gentle and assumes nothing, focuses on only a subset of TeX, yet everything is introduced so appropriately and made to seem natural (including making some typical mistakes and explaining why they go wrong), that the design of TeX will appear to make sense.

  • The paper Breaking Paragraphs into Lines by Knuth and Plass. A tour de force: discusses the problem, formulates it mathematically, defines desirability criteria, compares approaches, shows the power of this model (lots of sophisticated examples), then goes into the algorithm with its “bells and whistles” before concluding with an inspiring history.

For more on this aspect of TeX you can read The TeXbook, some other stuff that came out of the Stanford TeX project by Knuth and his associates, some talks and articles by Frank Mittelbach, some stuff by people who have written TeX-like or TeX-inspired systems (there are a few in existence, like SILE and Patoline, and a bigger graveyard of unfinished systems but some of whose authors wrote something useful before their projects died), etc.

But I'll say this upfront: even though this is a lot of fun to learn, it won't help you much when actually using LaTeX. Existing packages have reached a power and complexity beyond what you can easily arrive at from first principles (e.g. LaTeX's float/figure placement is implemented entirely in the macro layer). More on this below…


You mentioned

understand the code for packages, be able to write my own, etc etc

This unfortunately will take some work for anything nontrivial, because the entire system isn't set up for you to succeed at it (it optimizes for the end users, not package writers). The macros of LaTeX or major packages tend to be frightfully complicated because they are the outcome of decades (30+ years in LaTeX's case) of development: starting with something simple, they have grown to encompass all conceivable cases, be robust against various failure modes, etc. (Do you want \section{...} to not break when you stick a macro into its argument? Do you want the code of \section to be simple and readable? Pick one.)

Moreover, most packages are written assuming various functionality of other packages (and, if they have something to do with formatting, the exact formatting of other packages), they may use advanced macro techniques to be robust and comprehensive, these macros in turn assume aspects of other packages, etc.

In short, getting from “I know to use a few packages” to “I understand most of the stuff about most packages and if not I can read and understand them, or write my own” (like some of the top users on this site), involves some combination of all of (1), (2) and (3): you need to know how macros work, know what typesetting abilities exist, and both of these for all other packages you use or which typical users may use along with yours. (You can find packages whose documentation mentions “this package has been tested in combination with the following packages…”.)


So to conclude/reiterate: there are these three different categories, and if you really care about all of them (and not how to be a more skilful LaTeX user who knows how to use which packages, which is what is ultimately useful in real life), then you may have to pursue all three in parallel instead of in any structured manner.

My own preference (“learning style” :P) is to learn things bottom-up, from simplest onwards (without caring for utility), and this usually happens to be the historical order too (things generally get more complex with time: they get easier but rarely simpler), so I'd recommend the following path:

  • Learn (or think about) the main reason TeX was written: to set type (in other words: a not horribly inconvenient way to specify how characters should be picked up from certain fonts and placed on a page), the box-glue model, why its macros exist, simple macros (e.g. \def\line{\hbox to\hsize} and \def\centerline#1{\line{\hss#1\hss}}), building up to more complex things like page layout, etc. Learn enough about plain TeX, even if you're not going to use it. (The book I mentioned, by Seroul & Levy, takes basically this approach.) Read The TeXbook. Read historical material from Digital Typography. Skim through early issues of TUGboat.
  • The big jump that happens with LaTeX: look at some of LaTeX source code (open texdoc source2e and jump to a random page), learn whatever you need till it makes sense. :-)
  • Look at some sample packages which interest you, or answers on this site that seem to have hairy code, understand how they work, etc.

This path is of course very different from learning to do useful things with LaTeX, so I won't recommend it to anyone (also I haven't even got far enough in the first step!). Still, this is one approach that may be somewhat “structured” in the sense you mean. In my case, it has led to fewer things I am completely mystified by and feel “out of my depth”: I may not understand everything (or much), but at least now I can usually get some idea of what's going on and get what I'd need to learn first, when looking at any given situation.