10

I'm using org-mode to export to PDF. I'm going over the same document multiple times and exporting different branches during my evaluation.

I always want the first section in the PDF to start on a clean page, regardless of which subtree I export. So, there should always be a cleanpage after the TOC.

I can manually add newpage everywhere in my org-mode doc, but I have a tree with thousands of branches. I'd rather add this in the latex preamble or .emacs config, once.

Is it possible?

Ivan Perez
  • 400
  • 2
  • 15

3 Answers3

13

Add the following to your init file:

(setq org-latex-toc-command "\\tableofcontents \\clearpage")

Explanation: The variable org-latex-toc-command normally is set to the value "\\tableofcontents" and its value is emitted by the LaTeX exporter into the output TeX file at the place where the TOC is to be placed (normally right after the \begin{document} in the TeX file):

 \begin{document}
 \tableofcontents
 ...

When the TeX file is processed to produce the PDF output file, the LaTeX processor expands the \tablecontents macro to the full TOC.

By modifying the value of org-latex-toc-command, the LaTeX exporter is made to emit the modified string, so the TeX file looks liks this:

 \begin{document}
 \tableofcontents \clearpage
 ...

When the modified TeX file is processed by the LaTeX processor, after \tableofcontents is expanded to the full TOC, the \clearpage macro causes the page to be emitted immediately, leaving the rest of it blank.

Note BTW, that in an emacs string like "\\foo", the first backslash "escapes" the second, so that one backslash is part of the string. More about such escape sequences can be found in the Emacs documentation, e.g. here and here.

NickD
  • 27,023
  • 3
  • 23
  • 42
5

If you don't want to permanently change the value of org-latex-toc-command (as per @NickD answer), you can also include a latex export block before the first section

#+begin_export latex
  \clearpage \tableofcontents \clearpage
#+end_export

* Fist section

Remember to include #+OPTIONS: toc:nil in the preamble to avoid a double TOC

juanerasmoe
  • 316
  • 3
  • 9
  • 3
    This can also be done with file variables. Put this as the first line: `#+COMMENT:-*- org-latex-toc-command: "\\tableofcontents \\clearpage" -*-`. https://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html – Lorem Ipsum Apr 25 '20 at 01:33
  • 2
    `@@latex:\clearpage@@` before main text should work as well. Also, it doesn't need `#+OPTIONS: toc:nil`. – grepcake Jul 05 '20 at 15:59
2

I have been in need to add \clearpage at certain places of my document to format the output in a detailed way.

Add #+latex: \clearpage above or under any heading to break the page at this point.

Hope this helps!