I'm using the native cocoa emacs on OSX as well as on debian in a virtual machine.
When I run the aforementioned function in order to generate latex previews (on the same file) in the OSX or in the VM Emacs, I get huge performance differences: it takes at least 10 times as long to generate the previews in OSX as in the VM (running on the same machine, with the same document!!).
I imagine it is one of the programs in the stack of things that work to produce those previews? Or is calling a subprocess very expensive in OSX? (because it appears one is called for each preview)?
I would be happy to provide additional info, just don't know what... Thanks in advance!
There are two approach to preview latex frags:
latex -> pdflatex-> dvi -> dvi2png -> png : fast
latex -> xelatex -> pdf -> imagemagick -> png: slow
may be you used the second one...
Eval this (test) function, and check message, you may find which step is slow.....
(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))))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.