配置 org 模式以使用 LuaLaTeX

Configure org mode to use LuaLaTeX

我正在使用 emacs 的 org-mode 来排版笔记并通过 LaTeX 将它们导出为 pdf 格式。一切正常,除非我使用 Unicode 符号,例如

\begin{equation}
  \left( \frac{P^2}{2m} + V(x,y,z) \right) Ψ = E Ψ
\end{equation}

我在哪里使用 Ψ。使用 #+latex_compiler: lualatex

(setq org-latex-pdf-process
      '("lualatex -shell-escape -interaction nonstopmode %f"
        "lualatex -shell-escape -interaction nonstopmode %f")) 

我已经设法使用 LuaLaTeX 将或多或少的问题导出到 PDF,但是公式的预览 (C-c C-x C-l) 对于带有 Unicode 符号的公式完全损坏。

我需要在我的 emacs 配置中进行哪些更改才能在 org-mode 中将 LuaLaTeX 用于 与 LaTeX 相关的所有内容

将以下代码添加到您的 init 文件中(N.B。它向 org-preview-latex-process-alist 的值添加一个元素,因此必须添加此代码 org 加载后 - 您可能还需要 (require 'org)):

;; lualatex preview
(setq org-latex-pdf-process
  '("lualatex -shell-escape -interaction nonstopmode %f"
    "lualatex -shell-escape -interaction nonstopmode %f")) 

(setq luamagick '(luamagick :programs ("lualatex" "convert")
       :description "pdf > png"
       :message "you need to install lualatex and imagemagick."
       :use-xcolor t
       :image-input-type "pdf"
       :image-output-type "png"
       :image-size-adjust (1.0 . 1.0)
       :latex-compiler ("lualatex -interaction nonstopmode -output-directory %o %f")
       :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O")))

(add-to-list 'org-preview-latex-process-alist luamagick)

(setq org-preview-latex-default-process 'luamagick)

我必须添加 math-enabled 字体 (XITS),所以 org 文件本身现在看起来像这样:

#+LATEX_HEADER: \usepackage{unicode-math}
#+LATEX_HEADER: \setmainfont{XITS}
#+LATEX_HEADER: \setmathfont{XITS Math}
#+LATEX_HEADER: \setmathfont[range={\mathcal,\mathbfcal},StylisticSet=1]{XITS Math}

* A formula for lua
\begin{equation}
  \left( \frac{P^2}{2m} + V(x,y,z) \right) Ψ = E Ψ
\end{equation}

导出为 PDF 和预览似乎都有效。

我将 windows 10 与 Emacs 26.1 一起使用,@NickD 的解决方案只对我做了一些小改动

(setq org-latex-pdf-process
  '("lualatex -shell-escape -interaction nonstopmode %f"
    "lualatex -shell-escape -interaction nonstopmode %f"))

(setq luamagick '(luamagick :programs ("lualatex" "magick")
       :description "pdf > png"
       :message "you need to install lualatex and imagemagick."
       :use-xcolor t
       :image-input-type "pdf"
       :image-output-type "png"
       :image-size-adjust (1.0 . 1.0)
       :latex-compiler ("lualatex -interaction nonstopmode -output-directory %o %f")
       :image-converter ("magick convert -density %D -trim -antialias %f -quality 100 %O")))

(add-to-list 'org-preview-latex-process-alist luamagick)

(setq org-preview-latex-default-process 'luamagick)

使用 magick 而不是 convertconvert 不起作用,因为有一个名为 convert.exe

的默认 windows 程序

还有一个 lualatex 您的 org-preview-latex-process-alist 条目,如下所示:

(setq org-preview-latex-process-alist
  '((lualatex :programs ("lualatex" "dvisvgm")
                  :description "dvi > svg"
                  :message "you need to install the programs: lualatex and dvisvgm."
                  :image-input-type "dvi"
                  :image-output-type "svg"
                  :image-size-adjust (1.0 . 1.0)
                  :latex-compiler
                  ("lualatex --interaction=nonstopmode --shell-escape --output-format=dvi --output-directory=%o %f")
                  :image-converter
                  ("dvisvgm %f -n -b min -c %S -o %O"))))
(setq org-preview-latex-process 'lualatex)