让 Emacs `spacemacs` 接受根据 orgmode header 更改 latex 编译器的函数

Getting Emacs `spacemacs` to accept function that changes latex compiler based upon orgmode header

我在 emacs 25.3 上使用了最新的主版本 0.200。10.x Spacemacs。我正在尝试实现 orgmode documentation 推荐的功能,以允许用户定义 he/she 想要使用的 Latex 编译器。我实现了这个功能,但它似乎没有用。 Latex 编译步骤继续使用 pdflatex 而不是文件 header 中指定的 xelatex。所以我想弄清楚要做什么调整。

;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
;; but adapted to use latexmk 4.20 or higher.
(defun my-auto-tex-cmd ()
  "When exporting from .org with latex, automatically run latex,
     pdflatex, or xelatex as appropriate, using latexmk."
  (let ((texcmd)))
  ;; default command: oldstyle latex via dvi
  (setq texcmd "latexmk -dvi -pdfps -quiet %f")
  ;; pdflatex -> .pdf
  (if (string-match "LATEX_CMD: pdflatex" (buffer-string))
      (setq texcmd "latexmk -pdf -quiet %f"))
  ;; xelatex -> .pdf
  (if (string-match "LATEX_CMD: xelatex" (buffer-string))
      (setq texcmd "latexmk -pdflatex=xelatex -pdf -quiet %f"))
  ;; LaTeX compilation command
  (setq org-latex-to-pdf-process (list texcmd)))

(add-hook 'org-export-latex-after-initial-vars-hook 'my-auto-tex-cmd)

根据 Spacemacs 问题 list I need to make a change in the spacemacs-configuration-layers setting a la:

dotspacemacs-configuration-layers '(
  (latex :variables latex-build-command "LaTeX"))

问题是,在 dotspacemacs-configuration-layers 中进行更改似乎无法让我应用基于文件特定设置的更改。

有谁知道在 spacemacs 中实现上述功能的正确方法 (my-auto-tex-cmd)?

我在博客中找到了解决方案 post .

实际的elisp代码是:

;; Default packages included in every tex file, pdflatex or xelatex
(setq org-latex-packages-alist
      '(("" "graphicx" t)
        ("" "longtable" nil)
        ("" "float" nil)))

;; source: https://lists.gnu.org/archive/html/emacs-orgmode/2013-06/msg00240.html
(defun my-auto-tex-cmd (backend)
  "When exporting from .org with latex,
  automatically run latex, pdflatex, or xelatex as appropriate,
  using latexmk."
  (let ((texcmd))
    (setq texcmd "latexmk -pdf %f")
    (if (string-match "LATEX_CMD: pdflatex" (buffer-string))
        (progn
          (setq texcmd "latexmk -pdf -pdflatex='pdflatex -file-line-error --shell-escape -synctex=1' %f")
          (setq org-latex-default-packages-alist
                '(("AUTO" "inputenc" t)
                  ("T1"   "fontenc"   t)
                  (""     "fixltx2e"  nil)
                  (""     "wrapfig"   nil)
                  (""     "soul"      t)
                  (""     "textcomp"  t)
                  (""     "marvosym"  t)
                  (""     "wasysym"   t)
                  (""     "latexsym"  t)
                  (""     "amssymb"   t)
                  (""     "hyperref"  nil)))))
    (if (string-match "LATEX_CMD: xelatex" (buffer-string))
        (progn
          (setq texcmd "latexmk -pdflatex='xelatex -file-line-error --shell-escape -synctex=1' -pdf %f")
          (setq org-latex-default-packages-alist
                '(("" "fontspec" t)
                  ("" "xunicode" t)
                  ("" "url" t)
                  ;; ("" "rotating" t)
                  ;; ("" "memoir-article-styles" t)
                  ;; ("american" "babel" t)
                  ;; ("babel" "csquotes" t)
                  ;; ("" "listings" nil)
                  ("svgnames" "xcolor" t)
                  ("" "soul" t)
                  ("xetex, colorlinks=true, urlcolor=FireBrick, plainpages=false, pdfpagelabels, bookmarksnumbered" "hyperref" nil)
                  ))
          (setq org-latex-classes
                (cons '("memarticle"
                        "\documentclass[11pt,oneside,article]{memoir}"
                        ("\section{%s}" . "\section*{%s}")
                        ("\subsection{%s}" . "\subsection*{%s}")
                        ("\subsubsection{%s}" . "\subsubsection*{%s}")
                        ("\paragraph{%s}" . "\paragraph*{%s}")
                        ("\subparagraph{%s}" . "\subparagraph*{%s}"))
                      org-latex-classes))))

    (setq org-latex-pdf-process (list texcmd))))
(add-hook 'org-export-before-parsing-hook 'my-auto-tex-cmd)