diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2013-12-03 20:52:22 +0100 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2013-12-03 20:57:08 +0100 |
commit | 8953b417f205752aa4548a74518e16b2b54330ca (patch) | |
tree | 2aa6db61d393418514d7c28e8a1941f5e211ac58 | |
parent | 0b3657e8d3526eefec953673b04abaaf203eae4d (diff) | |
download | org-mode-8953b417f205752aa4548a74518e16b2b54330ca.tar.gz |
ox-html: Fix LaTeX fragments export
* lisp/ox-html.el (org-html-format-latex): Add an argument. Ensure
latex header is the same as specified in the original buffer when
exporting a LaTeX fragment or environment.
(org-html-latex-environment, org-html-latex-fragment): Apply signature
change.
-rw-r--r-- | lisp/ox-html.el | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 12e6bbc..44962a5 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -130,7 +130,9 @@ (:infojs-opt "INFOJS_OPT" nil nil) ;; Redefine regular options. (:creator "CREATOR" nil org-html-creator-string) - (:with-latex nil "tex" org-html-with-latex))) + (:with-latex nil "tex" org-html-with-latex) + ;; Retrieve LaTeX header for fragments. + (:latex-header "LATEX_HEADER" nil nil newline))) ;;; Internal Variables @@ -2488,18 +2490,34 @@ CONTENTS is nil. INFO is a plist holding contextual information." ;;;; Latex Environment -(defun org-html-format-latex (latex-frag processing-type) - "Format a LaTeX fragment LATEX-FRAG into HTML." +(defun org-html-format-latex (latex-frag processing-type info) + "Format a LaTeX fragment LATEX-FRAG into HTML. +PROCESSING-TYPE designates the tool used for conversion. It is +a symbol among `mathjax', `dvipng', `imagemagick', `verbatim' nil +and t. See `org-html-with-latex' for more information. INFO is +a plist containing export properties." (let ((cache-relpath "") (cache-dir "")) (unless (eq processing-type 'mathjax) (let ((bfn (or (buffer-file-name) (make-temp-name - (expand-file-name "latex" temporary-file-directory))))) + (expand-file-name "latex" temporary-file-directory)))) + (latex-header + (let ((header (plist-get info :latex-header))) + (and header + (concat (mapconcat + (lambda (line) (concat "#+LATEX_HEADER: " line)) + (org-split-string header "\n") + "\n") + "\n"))))) (setq cache-relpath (concat "ltxpng/" (file-name-sans-extension (file-name-nondirectory bfn))) - cache-dir (file-name-directory bfn)))) + cache-dir (file-name-directory bfn)) + ;; Re-create LaTeX environment from original buffer in + ;; temporary buffer so that dvipng/imagemagick can properly + ;; turn the fragment into an image. + (setq latex-frag (concat latex-header latex-frag)))) (with-temp-buffer (insert latex-frag) (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..." @@ -2515,9 +2533,10 @@ CONTENTS is nil. INFO is a plist holding contextual information." (attributes (org-export-read-attribute :attr_html latex-environment))) (case processing-type ((t mathjax) - (org-html-format-latex latex-frag 'mathjax)) + (org-html-format-latex latex-frag 'mathjax info)) ((dvipng imagemagick) - (let ((formula-link (org-html-format-latex latex-frag processing-type))) + (let ((formula-link + (org-html-format-latex latex-frag processing-type info))) (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link)) ;; Do not provide a caption or a name to be consistent with ;; `mathjax' handling. @@ -2535,9 +2554,10 @@ CONTENTS is nil. INFO is a plist holding contextual information." (processing-type (plist-get info :with-latex))) (case processing-type ((t mathjax) - (org-html-format-latex latex-frag 'mathjax)) + (org-html-format-latex latex-frag 'mathjax info)) ((dvipng imagemagick) - (let ((formula-link (org-html-format-latex latex-frag processing-type))) + (let ((formula-link + (org-html-format-latex latex-frag processing-type info))) (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link)) (org-html--format-image (match-string 1 formula-link) nil info)))) (t latex-frag)))) |