3

Recently, I've decided it would be a useful and interesting skill to be able to program LaTeX classes, macros etc, and so had a look around about what resources existed (this question was very helpful). However on the way, I was reminded about the ongoing LaTeX3 project, and ended up looking into this, thus leading to my discovery of expl3, which as far as I can tell is going to form the 'programming layer' of LaTeX3 when it is released.

This then raised the question: is it worth trying to come to grips with the mishmash of languages and commands which constitute the current LaTeX source/package/class etc coding, and thus have the advantage of working with something fundamentally designed around LaTeX2e, with which I imagine I'll remain working for the time being, or should I just focus my efforts on learning expl3?

The latter seems to me to be the better option, given that in the future (we hope) it is going to be the only language of which knowledge is required or indeed useful; as well as this it certainly seems easier to learn just expl3 than to try and come to grips with the multiple facets of LaTeX2e programming which currently exist (as laid out well here).

My sole hesitation then (asides from the daunting task of learning the thing - I am finding comprehensive documentation hard to come by, however I am aware this is something the LaTeX3 project is aiming to solve, so am hopeful for the future), is that when using my knowledge in LaTeX2e-based documents, I may find myself limited in that I am using a language which is not 'fundamental' to the system. I know expl3 currently exists as a package, which is how I would implement my knowledge (if needed), but I was wondering (perhaps this should be split into a separate question?) whether there is anything coding-wise (or anything else for that matter) which I might wish to do in LaTeX (coding a document class to creating a fancy macro) for which expl3 would be insufficient or too unwieldy to realistically be implementable?


On a side note, would people recommend familiarity with other (better-documented) programming languages before attempting to learn either expl3 or the alternative? I worry that I am throwing myself somewhat in the deep end here, as whilst my knowledge of LateX is decent, I have encountered little programming so far in my digital life.

I know there are about three different questions in one here, and if they should be split up I am more than willing to edit them out and repost elsewhere.

As always, any help at all is appreciated greatly :)


P.s. On the note of expl3 resources, I have found this and this, both of which look promising.

  • 4
    I think you should try programming in a sane language first. You could write a book on TeX named "Counterexamples in Computer Science". – Hood Chatham Feb 7 '18 at 21:43
  • 1
    Learn both of them... to get the best of both worlds. Understanding existing classes (those without expl3 content) are written using LaTeX2e, so knowledge in expl3 does not help much. More advanced packages like sunitx, xpatch, tasks etc. use expl3 to extend LaTeX2e (as of now); But in general, I find this question is too broad – user31729 Feb 7 '18 at 21:49
  • 2
    @aidangallagher4: I think in my case it was a process running in parallel ... in doubt, start with LaTeX2e first. – user31729 Feb 7 '18 at 21:59
  • 3
    Although expl3 might be a tolerably sane way to write macros (much better than the alternative), there's much more complexity to doing things with LaTeX (writing documentclasses etc.) than just the programming language. I really think this is the wrong question to ask. (For example, Adobe Photoshop might have been original written in Pascal and later in C++, but neither learning Pascal nor C++ will make you better at using Photoshop.) I elaborated a bit on related matters in this answer so not typing it all again. – ShreevatsaR Feb 7 '18 at 22:27
  • 3
    Well, might you want your class to, say, make section headings bold? Or might you want to typeset the author's name, date and title flush left? Or might you need to start a new paragraph? Or ensure that your class is consistent with, say, loading graphicx? Even if you plan for your class to redefine every macro in the LaTeX format, you need to know something about how they work in order to not end up with something which violates user expectations too violently. And that's not to mention the underlying TeX layer. How long do you want to wait before you can actually use your code? – cfr Feb 8 '18 at 0:51
7

Although I think that the question is quite broad, I try to answer it with the focus on package and class writing. I will use shortened versions of your questions:

  • Is it worth to learn the stable TeX/LaTeX2e languages or should I just focus my efforts on learning expl3?

    Let's just differentiate what you want: You will use LaTeX syntax throughout your document, i.e. at the place your package will be used. This is a level where you should rely on LaTeX2e syntax (e.g. no underscores). On the other hand you want to "program" your package and there you can use expl3 which is mightier and more comfortable for macro writing.

    Personally I always encourage people to learn expl3 for programming TeX, because it is a huge improvement in "sanity of programming" (as called in the comments). But remember that programming TeX is not everything and you have to have the document in mind (e.g. that's where xparse steps in).

    So you should not focus on only one of both, but you probably need to understand TeX/LaTeX as well as expl3 in the long run (maybe you do not need to learn every detail of TeX programming if learning expl3, because coding can be done in expl3).

  • I there anything which I might wish to do in LaTeX2e (e.g. coding a document class to creating a fancy macro) for which expl3 would be insufficient/impractical?

    At the moment probably yes, because expl3 is far from being complete and you will encounter this at some points. But basically you can use it to create document classes as well as packages (e.g. as \ProvideExplPackage) and from my own experience I am able to state that it is at many points shortening your code a lot. There are also new fancy concepts like coffins or regex which really help coding a package.

    But things you should not use expl3 for include document-design-level code like pgf/TikZ-heavy packages or classes, because expl3's space-ignorance will cause more trouble than it's worth. If you want to write such a package, you should definitely use the LaTeX2e mechanisms.

  • Is it recommended to be familiar with another programming language before attempting to learn either expl3 or the alternative?

    I've learnt programming before using TeX and I recognized that this knowledge was not really helpful for learning LaTeX2e. But when I started to learn expl3 I found it very advantageous to know something about programming, especially concepts like variables, functions and scoping.

    In my view you can benefit from knowing a programming language, but especially if you understood the document level of LaTeX2e you might be able to understand LaTeX programming well enough (if you have the patience to read documentation).

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.