--- a/lisp/org-latex.el +++ b/lisp/org-latex.el @@ -964,7 +964,6 @@ When PUB-DIR is set, use this as the publishing directory." (concat filename ".tex") filename))) (auto-insert nil); Avoid any auto-insert stuff for the new file - (TeX-master (boundp 'TeX-master)) (buffer (if to-buffer (if (eq to-buffer 'string) (get-buffer-create "*Org LaTeX Export*") @@ -1105,9 +1104,11 @@ When PUB-DIR is set, use this as the publishing directory." (or (eq (char-before) ?\n) (insert ?\n)) + (when (and to-buffer + (not (derived-mode-p 'latex-mode))) + (latex-mode)) (run-hooks 'org-export-latex-final-hook) - (if to-buffer - (unless (eq major-mode 'latex-mode) (latex-mode)) + (unless to-buffer (save-buffer)) (org-export-latex-fix-inputenc) (run-hooks 'org-export-latex-after-save-hook)