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.
This commit is contained in:
parent
faa2be8d57
commit
27101a3e0e
54
lisp/org.el
54
lisp/org.el
|
@ -17365,7 +17365,7 @@ Some of the options can be changed using the variable
|
||||||
(org-format-latex-header-extra
|
(org-format-latex-header-extra
|
||||||
(plist-get (org-infile-export-plist) :latex-header-extra))
|
(plist-get (org-infile-export-plist) :latex-header-extra))
|
||||||
(cnt 0) txt hash link beg end re e checkdir
|
(cnt 0) txt hash link beg end re e checkdir
|
||||||
executables-checked string
|
string
|
||||||
m n block-type block linkfile movefile ov)
|
m n block-type block linkfile movefile ov)
|
||||||
;; Check the different regular expressions
|
;; Check the different regular expressions
|
||||||
(while (setq e (pop re-list))
|
(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
|
(unless checkdir ; make sure the directory exists
|
||||||
(setq checkdir t)
|
(setq checkdir t)
|
||||||
(or (file-directory-p todir) (make-directory todir t)))
|
(or (file-directory-p todir) (make-directory todir t)))
|
||||||
(cond
|
(org-create-formula-image
|
||||||
((eq processing-type 'dvipng)
|
txt movefile opt forbuffer processing-type)
|
||||||
(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))))
|
|
||||||
(if overlays
|
(if overlays
|
||||||
(progn
|
(progn
|
||||||
(mapc (lambda (o)
|
(mapc (lambda (o)
|
||||||
|
@ -17469,10 +17452,8 @@ Some of the options can be changed using the variable
|
||||||
(if block-type 'paragraph 'character))))))
|
(if block-type 'paragraph 'character))))))
|
||||||
((eq processing-type 'mathml)
|
((eq processing-type 'mathml)
|
||||||
;; Process to MathML
|
;; Process to MathML
|
||||||
(unless executables-checked
|
(unless (save-match-data (org-format-latex-mathml-available-p))
|
||||||
(unless (save-match-data (org-format-latex-mathml-available-p))
|
(error "LaTeX to MathML converter not configured"))
|
||||||
(error "LaTeX to MathML converter not configured"))
|
|
||||||
(setq executables-checked t))
|
|
||||||
(setq txt (match-string n)
|
(setq txt (match-string n)
|
||||||
beg (match-beginning n) end (match-end n)
|
beg (match-beginning n) end (match-end n)
|
||||||
cnt (1+ cnt))
|
cnt (1+ cnt))
|
||||||
|
@ -17574,6 +17555,31 @@ inspection."
|
||||||
0 (1- (length latex-frag)) '(org-protected t) latex-frag)
|
0 (1- (length latex-frag)) '(org-protected t) latex-frag)
|
||||||
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
|
;; This function borrows from Ganesh Swami's latex2png.el
|
||||||
(defun org-create-formula-image-with-dvipng (string tofile options buffer)
|
(defun org-create-formula-image-with-dvipng (string tofile options buffer)
|
||||||
"This calls dvipng."
|
"This calls dvipng."
|
||||||
|
|
Loading…
Reference in New Issue