Org mode 中,不能显示 .eps 格式的图片吗?

使用 org-toggle-inline-images 的方式发现,.eps的图片不能显示,其他格式(.jpg, .png)正常。

有遇到过的吗?

这有个类似的:

我从 scimax 里 get 到了解决方法!

;; * Enable pdf and eps images in org-mode
;; Suggested on the org-mode maillist by Julian Burgos
(add-to-list 'image-file-name-extensions "pdf")
(add-to-list 'image-file-name-extensions "eps")

(add-to-list 'image-type-file-name-regexps '("\\.eps\\'" . imagemagick))
(add-to-list 'image-file-name-extensions "eps")
(add-to-list 'image-type-file-name-regexps '("\\.pdf\\'" . imagemagick))
(add-to-list 'image-file-name-extensions "pdf")
1 个赞

使用上面的方法, eps 文件在org 中显示出来的像素很低,有人知道原因吗?

和 LaTeX 公式预览类似的原因。

不行啊,@2x 在我这没有效果。 我是 linux

看来是 imagemagick 的问题,试试换个参数吧。

这能换吗?

我是直接在 org 文件中显示 .eps 的,并没有先手动转为 png。
也许 org 是调用了 imagemagick 在后台自动完成的转换?
莫非 imagemagick 有个配置文件吗?我没有发现啊

Emacs 不能直接显示某些类型的图片,包括 PostScript , PDF, DVI ,需要用外部程序转换成 jpeg png

感谢解答!我有点了解了。 我注意到在显示 latex 公式时, 在.org 文件所在目录下会生成一个文件夹,里面放了各个公式的 .png, 这应该就是您说的 外部程序转换 的中间结果了。

对于 XXX.eps 文件, 在终端使用 -density 选项可以把 eps 转成像素较高的 png:

convert -density 300 XXX.eps XXX.png

但是我不太清楚怎么样在 Emacs 中设置,使得:
当我想显示一幅 .eps 格式的图片时,Emacs能自动使用这样的转换方式,将其转成 .png后, 再呈现到 buffer中

另外,我用这种方式,配置后,也没有发现转换的中间结果(即 .png 或 .jpg 文件),也许是存放到了一个特殊的路径下吧:

(add-to-list 'image-file-name-extensions "eps")
(add-to-list 'image-type-file-name-regexps '("\\.eps\\'" . imagemagick))
(setq image-file-name-extensions
   (quote
    ("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm" "xpm" "pbm" "pgm" "ppm" "pnm" "svg" "pdf" "bmp")))

(setq org-image-actual-width 600)

(setq org-imagemagick-display-command "convert -density 600 \"%s\" -thumbnail \"%sx%s>\" \"%s\"")
(defun org-display-inline-images (&optional include-linked refresh beg end)
  "Display inline images.
Normally only links without a description part are inlined, because this
is how it will work for export.  When INCLUDE-LINKED is set, also links
with a description part will be inlined.  This
can be nice for a quick
look at those images, but it does not reflect what exported files will look
like.
When REFRESH is set, refresh existing images between BEG and END.
This will create new image displays only if necessary.
BEG and END default to the buffer boundaries."
  (interactive "P")
  (unless refresh
    (org-remove-inline-images)
    (if (fboundp 'clear-image-cache) (clear-image-cache)))
  (save-excursion
    (save-restriction
      (widen)
      (setq beg (or beg (point-min)) end (or end (point-max)))
      (goto-char beg)
      (let ((re (concat "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([^]\n]+?"
                        (substring (org-image-file-name-regexp) 0 -2)
                        "\\)\\]" (if include-linked "" "\\]")))
            old file ov img)
        (while (re-search-forward re end t)
          (setq old (get-char-property-and-overlay (match-beginning 1)
                                                   'org-image-overlay)
        file (expand-file-name
                      (concat (or (match-string 3) "") (match-string 4))))
          (when (file-exists-p file)
            (let ((file-thumb (format "%s%s_thumb.png" (file-name-directory file) (file-name-base file))))
              (if (file-exists-p file-thumb)
                  (let ((thumb-time (nth 5 (file-attributes file-thumb 'string)))
                        (file-time (nth 5 (file-attributes file 'string))))
                    (if (time-less-p thumb-time file-time)
            (shell-command (format org-imagemagick-display-command
                           file org-image-actual-width org-image-actual-width file-thumb) nil nil)))
                (shell-command (format org-imagemagick-display-command
                                         file org-image-actual-width org-image-actual-width file-thumb) nil nil))
              (if (and (car-safe old) refresh)
                  (image-refresh (overlay-get (cdr old) 'display))
                (setq img (save-match-data (create-image file-thumb)))
                (when img
                  (setq ov (make-overlay (match-beginning 0) (match-end 0)))
                  (overlay-put ov 'display img)
                  (overlay-put ov 'face 'default)
                  (overlay-put ov 'org-image-overlay t)
                  (overlay-put ov 'modification-hooks
                               (list 'org-display-inline-remove-overlay))
                  (push ov org-inline-image-overlays))))))))))

出自 emacs - Inline PDF images in org-mode - Stack Overflow ,对 Org 添加利用外部应用显示额外图片格式的范例。可能对你有帮助。

另外,Emacs 的 Image Magick 不是通过外部工具转换,而是用编译时内建的图片支持,所以不会产生中间文件,但是支持的参数有限,我没找到能直接操作控制内置 imagemagick 的方法。

1 个赞

我参照您给的方法,在 image-file-name-extensions中加上 eps 然后就可以了!!

这段 lisp 似乎是通过 xxx.eps 生成了一个 xxx_thumb.png的临时文件。

是的,同样可以用在那些其他不支持的格式上。

用了这段代码后,图片上方的

#+ATTR_ORG: :width 450

不起作用了.

另外还有个问题,如果图片本来就是 .png / .jpg ,这段代码还会多次一举的生成 _thumb.png 文件。

因为是个 dirty hack,所以问题比较大。 等我有空再看看。