From: "Feng Shu" <tumashu@163.com>
To: emacs-orgmode@gnu.org
Cc: Feng Shu <tumashu@163.com>
Subject: Re: latex fragment png's size too small
Date: Sat, 14 May 2016 21:22:07 +0800 [thread overview]
Message-ID: <87shxkkc5c.fsf@163.com> (raw)
In-Reply-To: <87wpmwn6wk.fsf@163.com> (Feng Shu's message of "Sat, 14 May 2016 20:47:07 +0800")
"Feng Shu" <tumashu@163.com> writes:
> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
>> tumashu <tumashu@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,
--
prev parent reply other threads:[~2016-05-14 13:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-13 7:00 latex fragment png's size too small tumashu
2016-05-14 8:56 ` Nicolas Goaziou
2016-05-14 9:42 ` tumashu
2016-05-14 12:14 ` Nicolas Goaziou
2016-05-14 12:47 ` Feng Shu
2016-05-14 13:22 ` Feng Shu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87shxkkc5c.fsf@163.com \
--to=tumashu@163.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.