I am currently playing around with org-mode in Spacemacs to render some file as LaTeX. I want to add a preamble and a new function to change the default \maketitle org-mode uses.

I am using a #+SETUPFILE so my org file looks like:

#+SETUPFILE: ../setup_file.org

<-content here->

In my setup_file.org I include all the headers, including some LATEX_HEADERS that will call my custom preamble and my \psetheader function:

#+OPTIONS: toc:nil 
#+STARTUP: align fold nodlcheck hidestars oddeven lognotestate 
#+LATEX_HEADER: \documentclass[11pt]{article}
#+LATEX_HEADER: \input{../header.tex}
#+LATEX_HEADER: \psetheader
#+KEYWORDS: orgmode pdf latex

Finally, the header.tex file just includes the packages I need and the \psetheader command. Now, the rendering fails, it produces a document, but is not quite there. When I open the .tex file, I find that org has included a preamble on top:

% Created 2023-04-07 Fri 19:37
% Intended LaTeX compiler: pdflatex

I have tried to just render just the body, as this post suggests, but then no preamble is rendered into the .tex file and it fails to build. There is an option to just make nil the default preamble temporarily? I have tried to create a org-latex-class, but it does not play nice with my header command.

1 Answer 1


The problem is that you specify \documentclass as a #+LATEX_HEADER in your setup file. Instead, you should specify it in two pieces, using #+LATEX_CLASS and #+LATEX_CLASS_OPTIONS[1]:

#+OPTIONS: toc:nil 
#+STARTUP: align fold nodlcheck hidestars oddeven lognotestate 
#+LATEX_CLASS: article
#+LATEX_HEADER: \input{../header.tex}
#+KEYWORDS: orgmode pdf latex

After that, you don't have to worry about zeroing out the default preamble. It will consist of \usepackage declarations that will load the packages into TeX's memory, but if you don't use them, they'll just sit there, bothering noone.

If you really want to zero it out, overriding the article class in org-latex-classes is indeed the way to go, but I suggest you don't go there unless you really have to.

Finally, in order to impose a new title structure, you can either redefine \maketitle in your own header.tex and leave it at that. But since you seem to want your own command \psetheader, then you can redefine the variable org-latex-title-command whose default value is "\\maketitle" (remember that backslashes have to be escaped with another backslash in an elisp string). Use customize preferably (or set it in your init file: (setq org-latex-title-command "\\psetheader") ). Assuming \psetheader works like \maketitle, it does NOT go in the preamble, so you don't add it as a #+LATEX_HEADER in your setup file: it has to be inserted right after the \begin{document}. Redefining the org-latex-title-command is the way to accomplish that.

[1] See also LaTeX header and sectioning structure for a specific example.

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.