【问题标题】:Why does org-preview-latex-fragment work about 10 times slower in OSX than on linux?为什么 org-preview-latex-fragment 在 OSX 中的工作速度比在 linux 上慢 10 倍?
【发布时间】:2014-03-27 22:53:01
【问题描述】:

我在 OSX 和虚拟机中的 debian 上使用本机 cocoa emacs。

当我在 OSX 或 VM Emacs 中运行上述函数以生成乳胶预览(在同一文件上)时,我得到 巨大 的性能差异:它至少需要 10 倍长时间在 OSX 中生成预览,就像在 VM 中一样(在同一台机器上运行,使用相同的文档!!)。

我想它是生成这些预览的一堆东西中的一个程序?或者在 OSX 中调用子进程非常昂贵? (因为似乎每次预览都会调用一个)?

我很乐意提供更多信息,只是不知道是什么... 提前致谢!

【问题讨论】:

  • 试试 Emacs 的通用 OSX 版本而不是“cocoa”怎么样?:emacsformacosx.com 或者,您使用“cocoa”这个词是不是“plain / vanilla / regular”的另一种说法?用于 OSX 的 Emacs?
  • 你链接的可可版本。与此相反,还有 Aquamacs,我似乎记得 carbon-emacs(虽然 cocoa 可能是它的延续)。

标签: linux macos emacs latex org-mode


【解决方案1】:

有两种方法可以预览latex frags:

  1. latex -> pdflatex-> dvi -> dvi2png -> png : 快速

  2. latex -> xelatex -> pdf -> imagemagick -> png: 慢

可能你用的是第二个...

【讨论】:

  • 听起来很有道理!你知道如何检查实际执行的是哪种方式吗?
  • 另外,因为 OSX 和 linux 共享完全相同的配置,我怀疑这是普遍缓慢的原因。但是,可能是两个操作系统都使用了较慢的方法,所以这仍然有用,谢谢!
  • 另外,最后,我检查了 org-latex-create-formula-image-program 是“dvi2png”,所以我想我可能还是在使用快速方法......
【解决方案2】:

评估这个(测试)函数,并检查消息,你可能会发现哪一步很慢.....

       (defun test (&optional options buffer)
         "This calls dvipng."
         (require 'ox-latex)
         (setq  test-timestamp  (float-time))
         (message "test1: %s" (- (float-time) test-timestamp))
         (let* ((tmpdir (if (featurep 'xemacs)
                 (temp-directory)
               temporary-file-directory))
         (texfilebase (make-temp-name
                   (expand-file-name "orgtex" tmpdir)))
         (texfile (concat texfilebase ".tex"))
         (dvifile (concat texfilebase ".dvi"))
         (pngfile (concat texfilebase ".png"))
         (fnh (if (featurep 'xemacs)
                         (font-height (face-font 'default))
                       (face-attribute 'default :height nil)))
         (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0))
         (dpi (number-to-string (* scale (floor (* 0.9 (if buffer fnh 140.))))))
         (fg (or (plist-get options (if buffer :foreground :html-foreground))
             "Black"))
         (bg (or (plist-get options (if buffer :background :html-background))
             "Transparent")))
           (message "test2: %s" (- (float-time) test-timestamp))
           (if (eq fg 'default) (setq fg (org-dvipng-color :foreground))
             (unless (string= fg "Transparent") (setq fg (org-dvipng-color-format fg))))
           (if (eq bg 'default) (setq bg (org-dvipng-color :background))
             (unless (string= bg "Transparent") (setq bg (org-dvipng-color-format bg))))
           (message "test3: %s" (- (float-time) test-timestamp))
           (let ((latex-header (org-create-formula--latex-header)))
             (with-temp-file texfile
        (insert latex-header)
        (insert "\n\\begin{document}\n" "$y=ax+b+c+d$" "\n\\end{document}\n")))
           (message "test4: %s" (- (float-time) test-timestamp))
           (let ((dir default-directory))
             (condition-case nil
          (progn
            (cd tmpdir)
            (call-process "latex" nil nil nil texfile))
        (error nil))
             (cd dir))
           (message "test5: %s" (- (float-time) test-timestamp))
           (if (not (file-exists-p dvifile))
        (progn (message "Failed to create dvi file from %s" texfile) nil)
             (condition-case nil
          (call-process "dvipng" nil nil nil
                "-fg" fg "-bg" bg
                "-D" dpi
                ;;"-x" scale "-y" scale
                "-T" "tight"
                "-o" pngfile
                dvifile)
        (error nil))
             (message "test6: %s" (- (float-time) test-timestamp))
             (if (not (file-exists-p pngfile))
          (if org-format-latex-signal-error
              (error "Failed to create png file from %s" texfile)
            (message "Failed to create png file from %s" texfile)
            nil)
        ;; Use the requested file name and clean up
        (copy-file pngfile "~/testpic.png" 'replace)
        (message "test7: %s" (- (float-time) test-timestamp))
        pngfile))))

【讨论】:

  • 谢谢!奇怪的是,有几个很慢! 5,6,7...但更奇怪的是,Linux VM 始终优于 OSx,1.2 到 3 倍 - 尽管最后一次测试在 linux 上失败。
  • 我认为唯一缓慢的步骤是运行乳胶,因为 time_consum(5)= time(step5)-time(step4)
  • 实际上,对于我来说,在 linux 和 OSX 上,第 6 步和第 7 步都比第 5 步花费大约 50%...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-10
  • 1970-01-01
  • 2014-02-24
  • 1970-01-01
  • 2015-10-07
  • 1970-01-01
相关资源
最近更新 更多