I use emacs org-mode for keeping track of notes and todos. Sometimes I wish to export notes as a latex file, using the official company style. To get the correct heading styles I run the following elisp:

(add-to-list 'org-latex-classes
                ("\\chapter{%s}" . "\\chapter*{%s}")
                ("\\section{%s}" . "\\section*{%s}")
                ("\\subsection{%s}" . "\\subsection*{%s}")
                ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))

Unfortunately, this doesn't work in .emacs. I get the following error:

Debugger entered--Lisp error: (void-variable org-latex-classes)
  (member (quote ("report" "\\documentclass{report}" ("\\chapter{%s}" . "\\chapter*{%s}") ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))) org-latex-classes)
  (if (member (quote ("report" "\\documentclass{report}" ("\\chapter{%s}" . "\\chapter*{%s}") ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))) org-latex-classes) org-latex-classes (setq org-latex-classes (cons (quote ("report" "\\documentclass{report}" ("\\chapter{%s}" . "\\chapter*{%s}") ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))) org-latex-classes)))
  eval((if (member (quote ("report" "\\documentclass{report}" ("\\chapter{%s}" . "\\chapter*{%s}") ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))) org-latex-classes) org-latex-classes (setq org-latex-classes (cons (quote ("report" "\\documentclass{report}" ("\\chapter{%s}" . "\\chapter*{%s}") ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))) org-latex-classes))) nil)
  call-interactively(eval-last-sexp nil nil)

The command only works if I have run org-export-dispatch to export to PDF before running add-to-list.

I'm kind of a beginner at elisp and configuring Emacs, and even more of a beginner at using Latex. So if someone could tell me how to get the command to work in .emacs I would be very grateful. I'm guessing the list has not been created yet when .emacs is loaded, but I'm at a loss about how to make this work.


Use the following:

(with-eval-after-load 'ox-latex
   (add-to-list 'org-latex-classes
                  ("\\chapter{%s}" . "\\chapter*{%s}")
                  ("\\section{%s}" . "\\section*{%s}")
                  ("\\subsection{%s}" . "\\subsection*{%s}")
                  ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))

This adjusts the variable as soon as the ox-latex package is loaded.


The list org-latex-classes is defined in ox-latex.el, so you need to insert (require 'ox-latex) in your .emacs before adding to it.

  • 3
    Thanks a lot, worked! For the record, how am I supposed to know these things, or find them out? – Fredrik Forséll Apr 28 '15 at 15:05
  • No no no. There's no reason to slow down your Emacs startup by loading all of org on startup. – Clément Jul 30 '16 at 3:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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