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?

3 Answers 3

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.

2
  • You might show the doc of that variable and make clear what that value does. That might be more helpful.
    – Drew
    Jul 13, 2018 at 2:21
  • @Drew: Edited, PTAL.
    – NickD
    Jul 13, 2018 at 2:54
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

2
  • 3
    This can also be done with file variables. Put this as the first line: #+COMMENT:-*- org-latex-toc-command: "\\tableofcontents \\clearpage" -*-. gnu.org/software/emacs/manual/html_node/emacs/… Apr 25, 2020 at 1:33
  • 2
    @@latex:\clearpage@@ before main text should work as well. Also, it doesn't need #+OPTIONS: toc:nil.
    – Artem Yu
    Jul 5, 2020 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!

Your Answer

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

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