Search code examples
emacslatexorg-mode

what is causing wrong page number in TOC for orgmode latex export


System:

  • Windows 10 x64
  • Emacs 26
  • Export using XeLaTex

I am working on a report in orgmode. The table of contents is giving me weird behavior. The page numbers are all lower than they should be by one. For example see the below text for an org document. If I export this as a pdf, then the table of contents shows section one as starting on page 1, even though it starts on page two. What is causing this and how do I fix it?

enter image description here

#+TITLE: A title
#+AUTHOR: An author
#+OPTIONS: toc:nil

* Abstract
    :PROPERTIES: 
    :CUSTOM_ID: abstract
    :UNNUMBERED: t
    :END:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur
tempor scelerisque magna, et varius leo pellentesque sit
amet. Phasellus aliquam pulvinar felis, fermentum commodo quam
tristique viverra. Aliquam erat volutpat. Nullam pellentesque arcu in
justo fermentum, vel molestie metus fringilla. Nulla lorem risus,
efficitur vel porta id, tincidunt aliquam nunc. Mauris eros magna,
molestie et porttitor in, dignissim vitae lorem. Etiam lorem sapien,
rutrum nec aliquet sit amet, malesuada et tortor.

#+BEGIN_QUOTE
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur
tempor scelerisque magna, et varius leo pellentesque sit
amet. Phasellus aliquam pulvinar felis, fermentum commodo quam
tristique viverra. Aliquam erat volutpat. Nullam pellentesque arcu in
justo fermentum, vel molestie metus fringilla. Nulla lorem risus,
efficitur vel porta id, tincidunt aliquam nunc. Mauris eros magna,
molestie et porttitor in, dignissim vitae lorem. Etiam lorem sapien,
rutrum nec aliquet sit amet, malesuada et tortor.
#+END_QUOTE

#+TOC: headlines 4

* Section One

Some Text

** Subsection

** Subsection

* Section Two

** Subsection

** Subsection

* Section Three

** Subsection

** Subsection

Solution

  • I was only compiling the latex file twice, but it needed to compile three times. I changed the relevant code in my init.el file from:

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

    to:

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