3

With the following book.org

#+title: My Title
#+author: My Name

#+LATEX_CLASS: memoir
#+LATEX_CLASS_OPTIONS: [oneside]
#+LATEX_HEADER: \usepackage[mag=2000, truedimen]{geometry}

#+INCLUDE: "chap1.org"
#+INCLUDE: "chap2.org"

and with both chap1.org and chap2.org having

* Chapter Title
Lorem Ipsum

I get an empty table of contents following C-c C-e l o.

Normally one needs to run LaTeX twice (to get an .aux file) before a ToC appears. Yet even after a second run the ToC is missing. Why?

ToC is missing

1 Answer 1

3

Run Twice

One solution is to configure org-latex-pdf-process to run LaTeX twice.

(setq org-latex-pdf-process
      '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
        "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))

ToC appears when LaTeX runs twice

This of course comes at the price of twice-as-slow LaTeX runs.

A better solution (for future work) would be to prevent the .aux file from being deleted, and accept that the ToC may be slightly off.

latexmk

Credit for this solution goes to NickD.

Another solution is to use latexmk.

(setq org-latex-pdf-process
      '("latexmk -shell-escape -f -pdf %f"))

latexmk will generate a correct ToC after one run. You may already have latexmk, as it is included in both MacTeX and MikTeX.

Oddly, latexmk is slower (by 30%) than two runs of pdflatex.

5
  • What version of Org mode are you using? The current version uses latexmk in org-latex-pdf-process (assuming you have latexmk installed of course): that takes care of multiple runs, bibtex/biblatex and other such tasks so you don't have to worry about it. I highly recommend that you install latexmk and that you use it in org-latex-pdf-process, instead of running multiple pdflatex's. I also recommend that you use xelatex or lualatex, rather than pdflatex: they are much better in dealing with Unicode.
    – NickD
    Commented Mar 14, 2023 at 14:16
  • You should be able to install latexmk with your distro's installation method: e.g. on Fedora 37, I just did sudo dnf install latexmk.
    – NickD
    Commented Mar 14, 2023 at 14:32
  • @NickD Nice, but if speed is what ultimately matters for frequent previews, two runs of pdflatex are still better. (I'm running Org-mode v. 9.5.5.)
    – Sam7919
    Commented Mar 14, 2023 at 14:58
  • BTW, the default was three invocations of pdflatex, because that was the worst case scenario known (although ISTR horror stories about a pathological case that wouldn't converge no matter what...) The default was changed to latexmk in commit 32739e35e3da37ea8eddaf8c65abc5c1b442a2e5
    – NickD
    Commented Mar 14, 2023 at 19:51
  • Actually, the default depends on whether latexmk is found: it's the default if present, but if you don't have it installed, then it falls back to three invocations of pdflatex.
    – NickD
    Commented Mar 14, 2023 at 20:35

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.