ob-ipython内联retina分辨率图片

折腾了两个小时终于搞定了,哈哈哈哈

1 个赞

首先需要用Emacs mac port版本 (GitHub - railwaycat/homebrew-emacsmacport: Emacs mac port formulae for the Homebrew package manager) 上游版本的本身不支持retina分辨率图片,无法可想。然后需要安装imagemagick,因为图片缩放用到命令行的convert工具。最后在配置文件里加入以下代码即可:

(when (and (fboundp 'mac-high-resolution-image-file-name)
           (fboundp 'mac-possibly-use-high-resolution-monitors-p))
  (defun my-ob-ipython-write-base64-string-retina (oldfunc &rest args)
    (let ((file (car args)) (b64-string (cdr args)))
      (if (mac-possibly-use-high-resolution-monitors-p)
          (let ((file2x (mac-high-resolution-image-file-name file)))
            (apply oldfunc file2x b64-string)
            (shell-command (concat "convert " file2x " -resize 50% " file)))
        (apply oldfunc args))))
  (advice-add  'ob-ipython--write-base64-string :around
               #'my-ob-ipython-write-base64-string-retina))

用mac port的话为啥不直接plot成svg

因为我用的版本打开内联svg就死锁了

我又试了一下svg,我原本以为是死机了,其实没有,但是非常非常慢。在我的顶配MBP15上打开一张图大概要半分钟。可能是因为我画了一段音频波形吧,几十万顶点的svg抗不住。png的话瞬开。

喔喔原来是这样