I did some online research (e.g. here) but couldn't figure out how to solve the following problem so far (of course, I might have overlooked something since the whole emacs community is new to me).

For my daily work I will use the editor mainly to edit LaTeX documents, thus, I'm trying to set it up properly.

Most of my own .sty and .csl files rely heavily on LaTeX3. To get it going I have to load the specific packages with \usepackage and afterwards parse the document with ctrl+c ctrl+n. I set up parsing automatically by inserting the line (setq TeX-parse-self t) into my .emacs file. So far, it works fine, but the problem is that I have to load the particular packages (xparse and/or expl3) explicitly with \usepackage or \RequirePackage in the specific document to get them parsed. Since the macros of both packages are part of the LaTeX kernel right know that adds some unnecessarly loaded packages to each file.

How can I add a hook to my .emacs/init file that parses both packages every time I'm using LaTeX-mode without adding them to the document with one of LaTeX's package loading commands? I guess that should be possible since both files exist inside the style directory of AUCTeX: .../elpa/auctex-13.2.1/style/expl3.el resp. .../elpa/auctex-13.2.1/style/xparse.el

1 Answer 1


Since AUCTeX release 13.2.3 (2023-12-07) support for completion, fontification etc. for ltcmd (former xparse) is available out of the box (see https://tex.stackexchange.com/a/703376/105447), so you only need to worry about expl3. It is easy to load the style file for it in the hook(s) for your mode(s) of interest with (TeX-run-style-hooks "expl3").

To add this by default in every document, you can have something like the following in your init file:

(add-hook 'LaTeX-mode-hook 'my/LaTeX-mode-setup)
(defun my/LaTeX-mode-setup ()
  (TeX-run-style-hooks "expl3"))

Now, this loads the expl3 style file whenever the mode is enabled. This makes sense, since most of what once was expl3 is now part of the LaTeX kernel and available by default anyway. But, if you don't want the style file enabled by default, you can do it document wise by means of the local style file of your document.

  • I added your code and it parses xparse.el and therefore expl3.el on startup. Thanks. Only the syntax highlighting of latex3 code remains faint (dim gray). But of course, it is the solution to my question!
    – lukeflo
    Commented Oct 9, 2023 at 14:13
  • @lukeflo Mhm, as I commented at TeX.SX, as far as I can tell, expl3 macros should be fontified once you load the expl3 style file. Can you inspect the active faces on one of your files? (Use C-u C-x =). You should find font-latex-sedate-face among the faces.
    – gusbrs
    Commented Oct 9, 2023 at 14:19
  • Ok, thanks. I was able to change the colour of the font-latex-sedate-face. It doesn't only affect latex3 commands but all unknown macros. At least it is much better recognisable that way.
    – lukeflo
    Commented Oct 9, 2023 at 17:48
  • @lukeflo Ah, so it is indeed working. :-) Great! problem solved. And, yes font-latex-sedate-face is applied to all matches to font-latex-match-simple-command, which essentially catches anything that starts with \ and whose characters are valid in a macro name. So it is indeed the "catch all" macro face which you end up seeing if some other class face was not also applied on top of it.
    – gusbrs
    Commented Oct 9, 2023 at 18:10
  • @lukeflo Also, please add a self-answer to your TeX.SX question as well. I'd say that one is solved with just loading the style files then. And it's only fair that AUCTeX does not stay in the register as "not supporting expl3" when it actually does. It is not complete, true, but it is probably as good as it currently gets for any existing alternative.
    – gusbrs
    Commented Oct 9, 2023 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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