You need to use LATEX_HEADER_EXTRA
instead of LATEX_HEADER
. You also need Org mode release 9.1 or later. Be sure to clean out the ltximg/
subdirectory in order to regenerate clean preview images after you apply the necessary fixes.
The documentation says
The LaTeX export back-end appends values from ‘LATEX_HEADER’ and
‘LATEX_HEADER_EXTRA’ keywords to the LaTeX header. The docstring for
‘org-latex-classes’ explains in more detail. Also note that LaTeX
export back-end does not append ‘LATEX_HEADER_EXTRA’ to the header when
previewing LaTeX snippets (see *note Previewing LaTeX fragments::).
Pre-9.1 releases contained a bug that was fixed with the following commit:
commit e903288e5080775cbd4d87c69deeba3268cda5c1
Author: Nicolas Goaziou <[email protected]>
Date: Sun Jun 25 09:39:32 2017 +0200
ox-latex: Fix LATEX_HEADER_EXTRA keyword
* lisp/ox-latex.el (org-latex-make-preamble): Do not include
LATEX_HEADER_EXTRA keywords' contents when previewing a LaTeX
fragment.
Reported-by: Mario Román <[email protected]>
<http://lists.gnu.org/archive/html/emacs-orgmode/2017-06/msg00477.html>
It was fixed in release 9.1 (I'm not sure when it was introduced). The easiest thing to do is upgrade Org mode. You can get the current stable version from ELPA or check these instructions from the Org mode site.
Or you can apply the following patch:
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index f11a8a63a..ec4b49585 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1623,15 +1623,15 @@ non-nil, only includes packages relevant to image generation, as
specified in `org-latex-default-packages-alist' or
`org-latex-packages-alist'."
(let* ((class (plist-get info :latex-class))
- (class-options (plist-get info :latex-class-options))
- (header (nth 1 (assoc class (plist-get info :latex-classes))))
(class-template
(or template
- (and (stringp header)
- (if (not class-options) header
- (replace-regexp-in-string
- "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
- class-options header t nil 1)))
+ (let* ((class-options (plist-get info :latex-class-options))
+ (header (nth 1 (assoc class (plist-get info :latex-classes)))))
+ (and (stringp header)
+ (if (not class-options) header
+ (replace-regexp-in-string
+ "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
+ class-options header t nil 1))))
(user-error "Unknown LaTeX class `%s'" class))))
(org-latex-guess-polyglossia-language
(org-latex-guess-babel-language
@@ -1644,7 +1644,9 @@ specified in `org-latex-default-packages-alist' or
snippet?
(mapconcat #'org-element-normalize-string
(list (plist-get info :latex-header)
- (plist-get info :latex-header-extra)) ""))))
+ (and (not snippet?)
+ (plist-get info :latex-header-extra)))
+ ""))))
info)
info)))
M-x org-version RET
will provide that) to your question.LATEX_HEADER
: you are supposed to useLATEX_HEADER_EXTRA
if you don't want it to be processed for previews, but even that had a bug. See my answer below.