在 org mode 文件中, 如果加上 setupfile:
#+SETUPFILE: ~/resources/org-latex-setup/marktex.setup
而这个 setupfile 包含一些必须 xelatex 才能用的 package (fontspec).
但 xenops 用的是 latex, pdflatex, 就会导致编译失败.
想要让 setupfile 存在的情况下让 xenops 继续正常工作. 我觉得有 2 种方法.
第一种想法是不用 pdflatex, 而用 xelatex, 但我没成功, 而且我也不想用这种方法, 在 setupfile 比较长的时候, 我担心它会影响 xenops 的速度. 但主要问题是我没有成功, 我是这样改的:
(setq xenops-math-latex-process-alist
'((dvipng
:programs ("latex" "dvipng")
:description "dvi > png"
:message "you need to install the programs: latex and dvipng."
:image-input-type "dvi"
:image-output-type "png"
:image-size-adjust (1.0 . 1.0)
:latex-compiler ("latex -interaction nonstopmode -shell-escape -output-format dvi -output-directory %o %f")
:image-converter ("dvipng -D %D -T tight -o %O %f"))
(dvisvgm
:programs ("latex" "dvisvgm")
:description "dvi > svg"
:message "you need to install the programs: latex and dvisvgm."
:image-input-type "dvi"
:image-output-type "svg"
:image-size-adjust (1.7 . 1.5)
:latex-compiler ("latex -interaction nonstopmode -shell-escape -output-format dvi -output-directory %o %f")
:image-converter ("dvisvgm %f -n -b %B -c %S -o %O"))
(imagemagick
:programs ("latex" "convert")
:description "pdf > png"
:message "you need to install the programs: latex and imagemagick."
:image-input-type "pdf"
:image-output-type "png"
:image-size-adjust (1.0 . 1.0)
:latex-compiler ("xelatex -interaction nonstopmode -shell-escape -output-directory %o %f")
:image-converter ("convert -density %D -trim -antialias %f -quality 100 %O")))
)
其实就是把 imagemagick 这里的 pdflatex 改成 xelatex. 但不行, 错误依然一模一样. 我把 xenops-math-latex-process-alist 前面的 latex 改成 xelatex, 又会报错找不到 dvi.
第二种想法是让 xenops 忽略 setupfile, 这是我倾向的做法, 但我想不到写法. xenops 做法是:
(defun xenops-math-latex-make-latex-document (latex colors)
"Make the LaTeX document for a single math image.
LATEX is the string of LaTeX code. COLORS is a pair (FG, BG)
containing the foreground and background colors."
(cl-flet ((get-latex-header () (org-latex-make-preamble
(org-export-get-environment (org-export-get-backend 'latex))
org-format-latex-header
'snippet)))
(let ((latex-header
(if (eq major-mode 'org-mode)
(get-latex-header)
(cl-destructuring-bind
(org-latex-packages-alist org-latex-default-packages-alist)
(list (cdr (xenops-math-latex-get-preamble-lines)) nil)
(get-latex-header)))))
(cl-destructuring-bind (fg bg) colors
(concat latex-header
"\n\\begin{document}\n"
"\\definecolor{fg}{rgb}{" fg "}\n"
"\\definecolor{bg}{rgb}{" bg "}\n"
"\n\\pagecolor{bg}\n"
"\n{\\color{fg}\n"
latex
"\n}\n"
"\n\\end{document}\n")))))
问题就在 get-latex-header 函数的实现:
(get-latex-header () (org-latex-make-preamble
(org-export-get-environment (org-export-get-backend 'latex))
org-format-latex-header
'snippet))
使得 setupfile 的内容被包含进来. 但我想不到咋修改才能让 get-latex-header 返回的和没有 setupfile 一致.