From 27101a3e0ee77550f6e45f898e50be5c9b7847b6 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sun, 9 Sep 2012 13:30:32 -0600 Subject: [PATCH] resurrect org-create-formula-image This commit resurrects the `org-create-formula-image' function which was removed in commit a9d3ce. This function is still called elsewhere, and provides a simpler interface to the two backend-specific image creation functions. This also simplifies `org-format-latex', which still has some serious problems such as optional arguments such as PROCESSING-TYPE which are never assigned a default value, and extraneous variables. At some point the `org-create-formula-image-with-imagemagick' and `org-create-formula-image-with-dvipng' functions should be combined as a great deal of code and logic is duplicated between the two functions. * lisp/org.el (org-format-latex): Simplified and now makes use of the new `org-create-formula-image' function. (org-create-formula-image): Provides a simpler interface to the two backend-specific functions. --- lisp/org.el | 54 +++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 4d0cd9a33..74ca1ff42 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -17365,7 +17365,7 @@ Some of the options can be changed using the variable (org-format-latex-header-extra (plist-get (org-infile-export-plist) :latex-header-extra)) (cnt 0) txt hash link beg end re e checkdir - executables-checked string + string m n block-type block linkfile movefile ov) ;; Check the different regular expressions (while (setq e (pop re-list)) @@ -17421,25 +17421,8 @@ Some of the options can be changed using the variable (unless checkdir ; make sure the directory exists (setq checkdir t) (or (file-directory-p todir) (make-directory todir t))) - (cond - ((eq processing-type 'dvipng) - (unless executables-checked - (org-check-external-command - "latex" "needed to convert LaTeX fragments to images") - (org-check-external-command - "dvipng" "needed to convert LaTeX fragments to images") - (setq executables-checked t)) - (unless (file-exists-p movefile) - (org-create-formula-image-with-dvipng - txt movefile opt forbuffer))) - ((eq processing-type 'imagemagick) - (unless executables-checked - (org-check-external-command - "convert" "you need to install imagemagick") - (setq executables-checked t)) - (unless (file-exists-p movefile) - (org-create-formula-image-with-imagemagick - txt movefile opt forbuffer)))) + (org-create-formula-image + txt movefile opt forbuffer processing-type) (if overlays (progn (mapc (lambda (o) @@ -17469,10 +17452,8 @@ Some of the options can be changed using the variable (if block-type 'paragraph 'character)))))) ((eq processing-type 'mathml) ;; Process to MathML - (unless executables-checked - (unless (save-match-data (org-format-latex-mathml-available-p)) - (error "LaTeX to MathML converter not configured")) - (setq executables-checked t)) + (unless (save-match-data (org-format-latex-mathml-available-p)) + (error "LaTeX to MathML converter not configured")) (setq txt (match-string n) beg (match-beginning n) end (match-end n) cnt (1+ cnt)) @@ -17574,6 +17555,31 @@ inspection." 0 (1- (length latex-frag)) '(org-protected t) latex-frag) latex-frag))) +(defun org-create-formula-image (string tofile options buffer &optional type) + "Create an image from LaTeX source using dvipng or convert. +This function calls either `org-create-formula-image-with-dvipng' +or `org-create-formula-image-with-imagemagick' depending on the +value of `org-latex-create-formula-image-program' or on the value +of the optional TYPE variable. + +Note: ultimately these two function should be combined as they +share a good deal of logic." + (org-check-external-command + "latex" "needed to convert LaTeX fragments to images") + (funcall + (case (or type org-latex-create-formula-image-program) + ('dvipng + (org-check-external-command + "dvipng" "needed to convert LaTeX fragments to images") + #'org-create-formula-image-with-dvipng) + ('imagemagick + (org-check-external-command + "convert" "you need to install imagemagick") + #'org-create-formula-image-with-imagemagick) + (t (error + "invalid value of `org-latex-create-formula-image-program'"))) + string tofile options buffer)) + ;; This function borrows from Ganesh Swami's latex2png.el (defun org-create-formula-image-with-dvipng (string tofile options buffer) "This calls dvipng."