From: FengShu <tumashu@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [patch] A experimental toy which is used to preview latex fragements
Date: Fri, 23 Mar 2012 16:22:20 +0800 [thread overview]
Message-ID: <874ntfyber.fsf@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 274 bytes --]
Hi everyone!
This is a experimental toy, which use
'(car org-latex-to-pdf-process) to convert latex formula fragements ,the
converting path is "latex->pdf->png" using imagemagick.
I'm not a programmer and only know little elisp,so the code quality
is poor...
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Ihis-is-a-experimental-toy-which-use-car-org-latex-t.patch --]
[-- Type: text/x-diff, Size: 5204 bytes --]
From 6a3fbe47d967f8d234d3aead058148cc46b7d376 Mon Sep 17 00:00:00 2001
From: FengShu <tumashu@gmail.com>
Date: Fri, 23 Mar 2012 16:05:37 +0800
Subject: [PATCH] Ihis is a experimental toy, which use '(car
org-latex-to-pdf-process) to convert latex formula,the
converting path is "latex->pdf->png" using imagemagick.
---
lisp/org.el | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 105 insertions(+), 1 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index 811b41b..7eea801 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -16966,7 +16966,7 @@ Some of the options can be changed using the variable
(setq executables-checked t))
(unless (file-exists-p movefile)
- (org-create-formula-image
+ (org-create-formula-image-with-imagemagick
txt movefile opt forbuffer))
(if overlays
(progn
@@ -17168,6 +17168,99 @@ inspection."
(loop for e in '(".dvi" ".tex" ".aux" ".log" ".png") do
(delete-file (concat texfilebase e)))
pngfile))))
+;; convert tex file to pdf ,than convert pdf file to pngfile used imagemagick
+(defun org-create-formula-image-with-imagemagick (string tofile options buffer)
+ "This calls imagemagick."
+ (require 'org-latex)
+ (let* ((tmpdir (if (featurep 'xemacs)
+ (temp-directory)
+ temporary-file-directory))
+ (texfilebase (make-temp-name
+ (expand-file-name "orgtex" tmpdir)))
+ (texfile (concat texfilebase ".tex"))
+ (pdffile (concat texfilebase ".pdf"))
+ (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")))
+ (if (eq fg 'default) (setq fg (org-latex-color :foreground)))
+ (if (eq bg 'default) (setq bg (org-latex-color :background)))
+ (with-temp-file texfile
+ (insert (org-splice-latex-header
+ org-format-latex-header
+ org-export-latex-default-packages-alist
+ org-export-latex-packages-alist t
+ org-format-latex-header-extra))
+ (insert "\n\\begin{document}\n"
+ "\\definecolor{fg}{rgb}{" fg "}\n"
+ "\\definecolor{bg}{rgb}{" bg "}\n"
+ "\n\\pagecolor{bg}\n"
+ "\n{\\color{fg}\n"
+ string
+ "\n}\n"
+ "\n\\end{document}\n" )
+ (require 'org-latex)
+ (org-export-latex-fix-inputenc))
+ (let ((dir default-directory))
+ (condition-case nil
+ (progn
+ (cd tmpdir)
+ (setq cmd (car org-latex-to-pdf-process))
+ (while (string-match "%b" cmd)
+ (setq cmd (replace-match
+ (save-match-data
+ (shell-quote-argument texfile))
+ t t cmd)))
+ (while (string-match "%f" cmd)
+ (setq cmd (replace-match
+ (save-match-data
+ (shell-quote-argument (file-name-nondirectory texfile)))
+ t t cmd)))
+ (while (string-match "%o" cmd)
+ (setq cmd (replace-match
+ (save-match-data
+ (shell-quote-argument (file-name-directory texfile)))
+ t t cmd)))
+ (shell-command cmd))
+ (error nil))
+ (cd dir))
+ (if (not (file-exists-p pdffile))
+ (progn (message "Failed to create pdf file from %s" texfile) nil)
+ (condition-case nil
+ (if (featurep 'xemacs)
+ (call-process "convert" nil nil nil
+ "-density" "96"
+ "-trim"
+ "-antialias"
+ pdffile
+ "-quality" "100"
+;; "-sharpen" "0x1.0"
+ pngfile)
+ (call-process "convert" nil nil nil
+ "-density" dpi
+ "-trim"
+ "-antialias"
+ pdffile
+ "-quality" "100"
+;; "-sharpen" "0x1.0"
+ pngfile))
+ (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 '(".pdf" ".tex" ".aux" ".log" ".png") do
+ (delete-file (concat texfilebase e)))
+ pngfile))))
(defun org-splice-latex-header (tpl def-pkg pkg snippets-p &optional extra)
"Fill a LaTeX header template TPL.
@@ -17239,6 +17332,17 @@ SNIPPETS-P indicates if this is run to create snippet images for HTML."
((eq attr :background) 'background))))
(color-values (face-attribute 'default attr nil))))))
+(defun org-latex-color (attr)
+ "Return an rgb color specification for latex color package."
+ (apply 'format "%s,%s,%s"
+ (mapcar 'org-normalize-color
+ (if (featurep 'xemacs)
+ (color-rgb-components
+ (face-property 'default
+ (cond ((eq attr :foreground) 'foreground)
+ ((eq attr :background) 'background))))
+ (color-values (face-attribute 'default attr nil))))))
+
(defun org-normalize-color (value)
"Return string to be used as color value for an RGB component."
(format "%g" (/ value 65535.0)))
--
1.7.9.1
next reply other threads:[~2012-03-23 8:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-23 8:22 FengShu [this message]
2012-03-24 13:34 ` Need Help: [patch] A experimental toy which is used to preview latex fragements FengShu
2012-03-24 17:32 ` Nick Dokos
2012-03-24 17:45 ` Nick Dokos
2012-03-24 18:54 ` Nick Dokos
2012-03-25 12:36 ` FengShu
2012-03-26 6:07 ` [patch] Need test: New path " FengShu
2012-03-27 4:23 ` [patch] Need test: New method " FengShu
2012-03-27 8:16 ` Bastien
[not found] ` <87haxapcof.fsf@gmail.com>
[not found] ` <87limmqoyu.fsf@gnu.org>
[not found] ` <87k426xk5t.fsf@gmail.com>
[not found] ` <87vclq401w.fsf@gnu.org>
2012-03-27 23:48 ` Feng Shu
2012-04-23 13:10 ` Bastien
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
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874ntfyber.fsf@gmail.com \
--to=tumashu@gmail.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 public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).