【问题标题】:Getting Emacs `spacemacs` to accept function that changes latex compiler based upon orgmode header让 Emacs `spacemacs` 接受基于 orgmode 标头更改乳胶编译器的函数
【发布时间】:2017-12-03 20:38:34
【问题描述】:

我在 emacs 25.3 上使用了最新的主版本 0.200.10.x Spacemacs。我试图实现一个由orgmodedocumentation 推荐的函数,允许用户定义他/她想要使用的Latex 编译器。我实现了这个功能,但它似乎没有用。乳胶编译步骤继续使用pdflatex,而不是文件头中指定的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 我需要更改spacemacs-configuration-layers 设置a la

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

问题是在dotspacemacs-configuration-layers 中进行更改似乎不允许我根据文件特定设置应用更改。

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

【问题讨论】:

    标签: emacs latex org-mode


    【解决方案1】:

    我在博客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)
    

    【讨论】:

      猜你喜欢
      • 2022-01-08
      • 2011-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-11
      相关资源
      最近更新 更多