7

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
              '("report"
                "\\documentclass{report}"
                ("\\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)
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

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.

2 Answers 2

16

Use the following:

(with-eval-after-load 'ox-latex
   (add-to-list 'org-latex-classes
                '("report"
                  "\\documentclass{report}"
                  ("\\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.

5

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.

2
  • 5
    Thanks a lot, worked! For the record, how am I supposed to know these things, or find them out? Commented Apr 28, 2015 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
    Commented Jul 30, 2016 at 3:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .