项目分享: Org Mode 中 LaTeX 预览与导出的优化 (Improved LaTeX Preview).

新版本移除了 org-format-latex-options 吗?Doom Emacs 的默认 org 配置产生了报错。

    Message: Symbol's value as variable is void
    Details: (org-format-latex-options)
    Backtrace:
      (plist-put org-format-latex-options :scale 1.5)
      (+org-init-appearance-h)
      (run-hooks org-load-hook)
      (byte-code "\300\301\302\"\210\303\304!\210\305\306!\207" [add-hook org-mode-hook #[0 "\300\301\302\...
      (org-babel-do-load-languages 'org-babel-load-languages '((emacs-lisp . t) (python . t) (latex . t)))
      (load-with-code-conversion "/home/charl/.config/doom/config.el" "/home/charl/.config/doom/config.el"...
      (load "~/.config/doom/config" nil nomessage)
      (condition-case e (load path noerror 'nomessage) ((debug doom-error) (signal (car e) (cdr e))) ((deb...
      (doom-load "~/.config/doom/config")
      (let ((doom-module-context [1 105 -105 :user nil nil nil])) (doom-load "~/.config/doom/config"))
      (let ((old-custom-file custom-file)) (let ((doom-module-context [2 -111 -111 :config use-package nil...
      (let ((doom-context doom-context)) (let ((tail (ensure-list 'modules))) (while tail (let ((context (...

在 mac 上试了一下,emacs-plus@29 显示有一些问题:

image

公式的下面像被裁剪过一样,我安装的是 mactex 2023,使用 lualatex

dvisvgm -V1
dvisvgm 3.0.3 (aarch64-apple-darwin20.6.0)
------------------------------------------
brotli:   1.0.9
clipper:  6.2.1
freetype: 2.13.0
kpathsea: 6.3.5
potrace:  1.16
xxhash:   0.8.1
zlib:     1.2.13

org-latex-preview-process-alist:image-converter 里加一个 --exact-bbox 试试看?

(setq org-latex-preview-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"
	 :latex-compiler ("%l -interaction nonstopmode -output-directory %o %f")
	 :latex-precompiler ("%l -output-directory %o -ini -jobname=%b \"&%L\" mylatexformat.ltx %f")
	 :image-converter ("dvipng --follow -D %D -T tight --depth --height -o %B-%%09d.png %f")
	 :transparent-image-converter
	 ("dvipng --follow -D %D -T tight -bg Transparent --depth --height -o %B-%%09d.png %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"
	 :latex-compiler ("%l -interaction nonstopmode -output-directory %o %f")
	 :latex-precompiler ("%l -output-directory %o -ini -jobname=%b \"&%L\" mylatexformat.ltx %f")
	 :image-converter
	 ("dvisvgm --page=1- --optimize --clipjoin --relative --no-fonts --exact-bbox --bbox=preview --libgs=/opt/homebrew/Cellar/ghostscript/10.03.0/lib/libgs.10.03.dylib -v4 -o %B-%%9p.svg %f")) ;;我自己的设置
	(imagemagick
	 :programs ("pdflatex" "convert")
	 :description "pdf > png"
	 :message "you need to install the programs: latex and imagemagick."
	 :image-input-type "pdf"
	 :image-output-type "png"
	 :latex-compiler ("pdflatex -interaction nonstopmode -output-directory %o %f")
	 :latex-precompiler ("pdftex -output-directory %o -ini -jobname=%b \"&pdflatex\" mylatexformat.ltx %f")
	 :image-converter ("convert -density %D -trim -antialias %f -quality 100 %B-%%09d.png"))))

果然可以了,感谢!

1 个赞

请问这个优化现在已经在9.7.6中了么?

没有合并到 master 呢吧

org-latex-preview 还有不少问题,见 Issues · tecosaur/org-latex-preview-todos · GitHub ,其中「 Convention for Org mode functions to support org-async #28」我挺关心的,因为改为异步导致了一些问题影响使用。

了解了,感谢