Org LaTeX 预览在视网膜显示器上是模糊的

Org LaTeX preview is fuzzy on retina displays

我的所有 math/scientific 笔记都使用 Emacs 24.4。 org-latex-preview 这太棒了!但最近,我升级到带有视网膜显示屏的 macbook pro,现在我发现我在 org-mode 中的所有方程式都是……模糊的。有没有我可以更改为更高分辨率的设置?

截图如下:

谢谢!

我试过了 emacs-mac-port

如果我在同一个目录中创建 2 个文件 foo.png foo@2x.png,这将有效。

默认orgmode latex预览不支持retina,所以在mac有retina屏幕的情况下,latex预览会很模糊。
不过,我们可以hack org.el 来实现这个功能。只需按照以下步骤操作:

获取正确版本的 emacs

要改用 Emacs 25.1 的 Yamamoto Mitsuharu 版本(具有更多 mac 特定功能):

brew tap railwaycat/emacsmacport
brew install emacs-mac

最后 link 它到您的应用程序文件夹:

brew linkapps emacs-mac

此版本emacs将支持视网膜图像显示。

更改 org-format-latex-options

将比例从 1.0 更改为 2.0,以生成 2 倍大小的图像。

删除 org.elc

向org.el添加功能

(defun galaxy-compose-image-filename-2x(image-file-name)
  (concat (file-name-directory image-file-name) (file-name-base image-file-name) "@2x." (file-name-extension image-file-name)))

并评估函数。

修改函数 org-format-latex

更改片段:

(unless (file-exists-p movefile)
  (org-create-formula-image value movefile options forbuffer processing-type)

(unless (file-exists-p movefile)
  (org-create-formula-image value movefile options forbuffer processing-type)
  (setq filename-2x (galaxy-compose-image-filename-2x movefile))
  (rename-file movefile filename-2x)
  (call-process-shell-command "convert" nil nil nil nil (concat "\"" filename-2x "\" -scale \"50%\" -quality \"100%\"" ) (concat "\"" movefile "\"" )))

并评估函数。

现在,您可以在 mac 视网膜屏幕上预览 2 倍大小图像的 Latex。

几年前,我决定解决这个问题并编写了一个补丁来添加 dvisvgm 作为 Latex 预览的渲染选项。虽然效果很好,但我从未提交过(没有时间或知识如何正式修补 org)。

今天,我很高兴地发现 org-mode v9.0.6 现在有了这个功能!

要激活,首先检查您的系统上是否有 dvisvgm。然后更新 org-mode 并将以下行添加到您的 init.el 文件中:

(setq org-latex-create-formula-image-program 'dvisvgm)

很快!

我找到了一种适用于所有内联图像的解决方案。首先确保任何生成的图像都是使用 2 的比例因子创建的。例如,对于 LaTeX 代码块和内联 LaTeX 片段,这适用于

(plist-put org-format-latex-options :scale 2)

然后让 org 缩放所有内联图像。 对于 LaTeX 代码块,我们可以这样建议 org--create-inline-image

(defun my/image-scale-advice (image)
  (let* ((factor (image-property image :scale))
         (new-factor (if factor
                         (/ factor 2.0)
                       0.5)))
    (image--set-property image :scale new-factor)
    image))
(advice-add 'org--create-inline-image :filter-return #'my/image-scale-advice)

这会将任何现有的比例因子除以 2,或者如果存在 none,则将比例因子设置为 0.5。

对于内联 LaTeX 片段,我们可以这样建议 org--make-preview-overlay

(defun my/overlay-scale-advice (beg end image &optional imagetype)
  (mapc (lambda (ov) (if (equal (overlay-get ov 'org-overlay-type) 'org-latex-overlay)
                                (overlay-put ov
                                             'display
                                             (list 'image :type (or (intern imagetype) 'png) :file image :ascent 'center :scale 0.5))))
        (overlays-at beg)))
(advice-add 'org--make-preview-overlay :after #'my/overlay-scale-advice)

这应该会在 Retina 显示器上显示更清晰的内联图像。