From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Feng Shu" Subject: Re: latex fragment png's size too small Date: Sat, 14 May 2016 21:22:07 +0800 Message-ID: <87shxkkc5c.fsf@163.com> References: <4929388c.9b00.154a8ea644b.Coremail.tumashu@163.com> <878tzd6ms0.fsf@saiph.selenimh> <8737pkzvii.fsf@saiph.selenimh> <87wpmwn6wk.fsf@163.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1a17-0006n5-9s for emacs-orgmode@gnu.org; Sat, 14 May 2016 09:54:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b1a13-0002zu-SR for emacs-orgmode@gnu.org; Sat, 14 May 2016 09:54:05 -0400 Received: from mproxyhzb1.163.com ([123.58.178.201]:49957) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1a11-0002yx-IN for emacs-orgmode@gnu.org; Sat, 14 May 2016 09:54:01 -0400 In-Reply-To: <87wpmwn6wk.fsf@163.com> (Feng Shu's message of "Sat, 14 May 2016 20:47:07 +0800") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Cc: Feng Shu "Feng Shu" writes: > Nicolas Goaziou writes: > >> tumashu 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, --