>From 762bffe1fc11d28502d6842c9b7d0049442ee2ef Mon Sep 17 00:00:00 2001 From: Jambunathan K
Date: Fri, 9 Sep 2011 00:14:59 +0530 Subject: [PATCH] org.el: Add support for LaTeX to MathML conversion * lisp/org.el (org-latex-to-mathml-jar-file) (org-latex-to-mathml-convert-command): New user-customizable variables. (org-format-latex-mathml-available-p, org-create-math-formula) (org-format-latex-as-mathml): New functions. (org-format-latex): Add a new local variable block-type that notes the nature of the equation - inline or display. Associate it's value to `org-latex-src-embed-type' property of dvipng links. Add mathml as new processing type. --- lisp/org.el | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 154 insertions(+), 5 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index d63b854..b907338 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16507,11 +16507,11 @@ Some of the options can be changed using the variable (plist-get (org-infile-export-plist) :latex-header-extra)) (cnt 0) txt hash link beg end re e checkdir executables-checked string - m n block linkfile movefile ov) + m n block-type block linkfile movefile ov) ;; Check the different regular expressions (while (setq e (pop re-list)) - (setq m (car e) re (nth 1 e) n (nth 2 e) - block (if (nth 3 e) "\n\n" "")) + (setq m (car e) re (nth 1 e) n (nth 2 e) block-type (nth 3 e) + block (if block-type "\n\n" "")) (when (member m matchers) (goto-char (point-min)) (while (re-search-forward re nil t) @@ -16540,7 +16540,7 @@ Some of the options can be changed using the variable '(org-protected t)))) (add-text-properties (match-beginning n) (match-end n) '(org-protected t)))) - ((or (eq processing-type 'dvipng) t) + ((eq processing-type 'dvipng) ;; Process to an image (setq txt (match-string n) beg (match-beginning n) end (match-end n) @@ -16596,7 +16596,156 @@ Some of the options can be changed using the variable (insert (org-add-props link (list 'org-latex-src (replace-regexp-in-string - "\"" "" txt))))))))))))) + "\"" "" txt) + 'org-latex-src-embed-type + (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)) + (setq txt (match-string n) + beg (match-beginning n) end (match-end n) + cnt (1+ cnt)) + (if msg (message msg cnt)) + (goto-char beg) + (delete-region beg end) + (insert (org-format-latex-as-mathml + txt block-type prefix dir))) + (t + (error "Unknown conversion type %s for latex fragments" + processing-type))))))))) + +(defcustom org-latex-to-mathml-jar-file nil + "Value of\"%j\" in `org-latex-to-mathml-convert-command'. +Use this to specify additional executable file say a jar file. + +When using MathToWeb as the converter, specify the full-path to +your mathtoweb.jar file." + :group 'org-latex + :type '(choice + (const :tag "None" nil) + (file :tag "JAR file" :must-match t))) + +(defcustom org-latex-to-mathml-convert-command nil + "Command to convert LaTeX fragments to MathML. +Replace format-specifiers in the command as noted below and use +`shell-command' to convert LaTeX to MathML. +%j: Executable file in fully expanded form as specified by + `org-latex-to-mathml-jar-file'. +%I: Input LaTeX file in fully expanded form +%o: Output MathML file +This command is used by `org-create-math-formula'. + +When using MathToWeb as the converter, set this to +\"java -jar %j -unicode -force -df %o %I\"." + :group 'org-latex + :type '(choice + (const :tag "None" nil) + (string :tag "\nShell command"))) + +(defun org-format-latex-mathml-available-p () + "Return t if `org-latex-to-mathml-convert-command' is usable." + (save-match-data + (when (and (boundp 'org-latex-to-mathml-convert-command) + org-latex-to-mathml-convert-command) + (let ((executable (car (split-string + org-latex-to-mathml-convert-command)))) + (when (executable-find executable) + (if (string-match + "%j" org-latex-to-mathml-convert-command) + (file-readable-p org-latex-to-mathml-jar-file) + t)))))) + +(defun org-create-math-formula (latex-frag &optional mathml-file) + "Convert LATEX-FRAG to MathML and store it in MATHML-FILE. +Use `org-latex-to-mathml-convert-command'. If the conversion is +sucessful, return the portion between \"