"Feng Shu" <tuma...@163.com> writes: > Nicolas Goaziou <m...@nicolasgoaziou.fr> writes: > >> tumashu <tuma...@163.com> writes: >> >>> The problem is that the pic is too small and nearly can not see the >>> words in the picture, it will force user config it, if we use a larger >>> pic, it can work although it is ugly >> >> Then is :scale 1.2 enough? > > I tested in bare emacs, 1.2 seem ok.
I have found the other problem, the below two version of org-create-formula-image-with-dvipng generate different size png, for they use different dpi. I think, we should hold :scale to 1.0 and fix size problem in function `org-create-formula-image-with-dvipng'. #+BEGIN_SRC emacs-lisp ;; Old version (defun org-create-formula-image-with-dvipng (string tofile options buffer) "This calls dvipng." (require 'ox-latex) (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"))) (princ (format "dpi:%s" dpi)) (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)))) (let ((latex-header (org-create-formula--latex-header))) (with-temp-file texfile (insert latex-header) (insert "\n\\begin{document}\n" string "\n\\end{document}\n"))) (let ((dir default-directory)) (condition-case nil (progn (cd tmpdir) (call-process "latex" nil nil nil texfile)) (error nil)) (cd dir)) (if (not (file-exists-p dvifile)) (progn (message "Failed to create dvi file from %s" texfile) nil) (condition-case nil (if (featurep 'xemacs) (call-process "dvipng" nil nil nil "-fg" fg "-bg" bg "-T" "tight" "-o" pngfile dvifile) (call-process "dvipng" nil nil nil "-fg" fg "-bg" bg "-D" dpi ;;"-x" scale "-y" scale "-T" "tight" "-o" pngfile dvifile)) (error nil)) (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 tofile 'replace) (loop for e in '(".dvi" ".tex" ".aux" ".log" ".png" ".out") do (if (file-exists-p (concat texfilebase e)) (delete-file (concat texfilebase e)))) pngfile)))) ;; New version (defun org-create-formula-image-with-dvipng (string tofile options buffer) "This calls dvipng." (require 'ox-latex) (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")) (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0)) ;; This assumes that the display has the same pixel width in ;; the horizontal and vertical directions (dpi (number-to-string (* scale (if buffer (org--get-display-dpi) 120)))) (fg (or (plist-get options (if buffer :foreground :html-foreground)) "Black")) (bg (or (plist-get options (if buffer :background :html-background)) "Transparent"))) (princ (format "dpi: %s" dpi)) (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)))) (let ((latex-header (org-create-formula--latex-header))) (with-temp-file texfile (insert latex-header) (insert "\n\\begin{document}\n" string "\n\\end{document}\n"))) (let ((dir default-directory)) (ignore-errors (cd tmpdir) (call-process "latex" nil nil nil texfile)) (cd dir)) (if (not (file-exists-p dvifile)) (progn (message "Failed to create dvi file from %s" texfile) nil) (ignore-errors (if (featurep 'xemacs) (call-process "dvipng" nil nil nil "-fg" fg "-bg" bg "-T" "tight" "-o" pngfile dvifile) (call-process "dvipng" nil nil nil "-fg" fg "-bg" bg "-D" dpi ;;"-x" scale "-y" scale "-T" "tight" "-o" pngfile dvifile))) (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 tofile 'replace) (dolist (e '(".dvi" ".tex" ".aux" ".log" ".png" ".out")) (when (file-exists-p (concat texfilebase e)) (delete-file (concat texfilebase e)))) pngfile)))) #+END_SRC > >> If it is too ugly, it will also force users configuring it anyway. >> >> Regards, --