forked from mirrors/org-mode
ox-html: Update LaTeX export for images and mathml
* lisp/ox-html.el (org-html-latex-environment, org-html-format-latex, org-latex-to-html-convert-command, org-format-latex-as-html, org-html-latex-image-options): Introduce new functions and variables to work directly with the new org-latex-preview and ox-mathml API. * lisp/org-latex-preview.el (org-format-latex-as-html, org-latex-preview--tex-styled, org-latex-preview-replace-fragments, org-latex-to-html-convert-command, org-latex-preview-options, org-latex-preview-place-image-link): Move all of the HTML-specific processing out of org-latex-preview.el, and into ox-html.el, and remove now-obsolete code. * lisp/org-compat.el (org-place-formula-image, org-html-format-latex): Relocate a copy of `org-place-formula-image' and `org-html-format-latex' here, and mark them as obsolete.
This commit is contained in:
parent
7ce7e39650
commit
39e0faebd1
|
@ -699,7 +699,7 @@ This constant, for example, makes the below code not err:
|
|||
(define-obsolete-function-alias
|
||||
'org-clear-latex-preview 'org-latex-preview-clear-overlays "9.7")
|
||||
(make-obsolete
|
||||
'org-place-formula-image "replaced with org-latex-preview-place-image and org-latex-preview-place-image-link" "9.7")
|
||||
'org-place-formula-image "no longer used" "9.7")
|
||||
(define-obsolete-function-alias
|
||||
'org-latex-color-format 'org-latex-preview--format-color "9.7")
|
||||
(define-obsolete-function-alias
|
||||
|
@ -897,6 +897,37 @@ Some of the options can be changed using the variable
|
|||
(error "Unknown conversion process %s for LaTeX fragments"
|
||||
processing-type)))))))))))
|
||||
|
||||
;; FIXME: Unused; obsoleted; to be removed.
|
||||
(defun org-place-formula-image (link block-type beg end value overlays movefile imagetype)
|
||||
"Place an overlay from BEG to END showing MOVEFILE.
|
||||
The overlay will be above BEG if OVERLAYS is non-nil."
|
||||
(if overlays
|
||||
(progn
|
||||
(dolist (o (overlays-in beg end))
|
||||
(when (eq (overlay-get o 'org-overlay-type)
|
||||
'org-latex-overlay)
|
||||
(delete-overlay o)))
|
||||
(let ((ov (make-overlay beg end))
|
||||
(imagetype (or (intern imagetype) 'png)))
|
||||
(overlay-put ov 'org-overlay-type 'org-latex-overlay)
|
||||
(overlay-put ov 'evaporate t)
|
||||
(overlay-put ov
|
||||
'modification-hooks
|
||||
(list (lambda (o _flag _beg _end &optional _l)
|
||||
(delete-overlay o))))
|
||||
(overlay-put ov
|
||||
'display
|
||||
(list 'image :type imagetype :file movefile :ascent 'center)))
|
||||
(goto-char end))
|
||||
(delete-region beg end)
|
||||
(insert
|
||||
(org-add-props link
|
||||
(list 'org-latex-src
|
||||
(replace-regexp-in-string "\"" "" value)
|
||||
'org-latex-src-embed-type
|
||||
(if block-type 'paragraph 'character))))))
|
||||
|
||||
|
||||
;; FIXME: Unused; obsoleted; to be removed.
|
||||
(defun org-create-formula-image
|
||||
(string tofile options buffer &optional processing-type)
|
||||
|
@ -994,8 +1025,49 @@ a HTML file."
|
|||
(delete-file (concat texfilebase e))))
|
||||
image-output-file)))
|
||||
|
||||
;; FIXME: Unused; obsoleted; to be removed.
|
||||
(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 can
|
||||
be `mathjax', `verbatim', `html', nil, t or symbols in
|
||||
`org-preview-latex-process-alist', e.g., `dvipng', `dvisvgm' or
|
||||
`imagemagick'. See `org-html-with-latex' for more information.
|
||||
INFO is a plist containing export properties."
|
||||
(let ((cache-relpath "") (cache-dir ""))
|
||||
(unless (or (eq processing-type 'mathjax)
|
||||
(eq processing-type 'html))
|
||||
(let ((bfn (or (buffer-file-name)
|
||||
(make-temp-name
|
||||
(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 (file-name-as-directory org-preview-latex-image-directory)
|
||||
(file-name-sans-extension
|
||||
(file-name-nondirectory 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))))
|
||||
(org-export-with-buffer-copy
|
||||
:to-buffer (get-buffer-create " *Org HTML Export LaTeX*")
|
||||
:drop-visibility t :drop-narrowing t :drop-contents t
|
||||
(erase-buffer)
|
||||
(insert latex-frag)
|
||||
(org-format-latex cache-relpath nil nil cache-dir nil
|
||||
"Creating LaTeX Image..." nil processing-type)
|
||||
(buffer-string))))
|
||||
|
||||
(make-obsolete #'org-format-latex "to be removed" "9.7")
|
||||
(make-obsolete #'org-create-formula-image "to be removed" "9.7")
|
||||
(make-obsolete #'org-html-format-latex "to be removed" "9.7")
|
||||
|
||||
;; FIXME: Unused; obsoleted; to be removed.
|
||||
(defun org-let (list &rest body) ;FIXME: So many kittens are suffering here.
|
||||
|
|
|
@ -43,8 +43,7 @@
|
|||
;;;###autoload
|
||||
(defcustom org-latex-preview-options
|
||||
'(:foreground auto :background "Transparent" :scale 1.0
|
||||
:html-foreground "Black" :html-background "Transparent"
|
||||
:html-scale 1.0 :matchers ("begin" "$1" "$" "$$" "\\(" "\\[")
|
||||
:matchers ("begin" "$1" "$" "$$" "\\(" "\\[")
|
||||
:zoom 1.0)
|
||||
"Options for creating images from LaTeX fragments.
|
||||
This is a property list with the following properties:
|
||||
|
@ -55,8 +54,6 @@ This is a property list with the following properties:
|
|||
`default' means use the background of the default face.
|
||||
`auto' means use the background from the text face.
|
||||
:scale a scaling factor for the size of the images, to get more pixels
|
||||
:html-foreground, :html-background, :html-scale
|
||||
the same numbers for HTML export.
|
||||
:matchers a list indicating which matchers should be used to
|
||||
find LaTeX fragments. Valid members of this list are:
|
||||
\"begin\" find environments
|
||||
|
@ -71,24 +68,6 @@ This is a property list with the following properties:
|
|||
:package-version '(Org . "9.7")
|
||||
:type 'plist)
|
||||
|
||||
(defcustom org-latex-to-html-convert-command nil
|
||||
"Shell command to convert LaTeX fragments to HTML.
|
||||
This command is very open-ended: the output of the command will
|
||||
directly replace the LaTeX fragment in the resulting HTML.
|
||||
Replace format-specifiers in the command as noted below and use
|
||||
`shell-command' to convert LaTeX to HTML.
|
||||
%i: The LaTeX fragment to be converted (shell-escaped).
|
||||
It must not be used inside a quoted argument, the result of %i
|
||||
expansion inside a quoted argument is undefined.
|
||||
|
||||
For example, this could be used with LaTeXML as
|
||||
\"latexmlc literal:%i --profile=math --preload=siunitx.sty 2>/dev/null\"."
|
||||
:group 'org-latex
|
||||
:package-version '(Org . "9.4")
|
||||
:type '(choice
|
||||
(const :tag "None" nil)
|
||||
(string :tag "Shell command")))
|
||||
|
||||
(defcustom org-latex-preview-default-process
|
||||
(if (executable-find "dvisvgm") 'dvisvgm 'dvipng)
|
||||
"The default process to convert LaTeX fragments to image files.
|
||||
|
@ -890,67 +869,6 @@ should it be enabled."
|
|||
(push obj fragments)))))
|
||||
(nreverse fragments)))
|
||||
|
||||
(defun org-latex-preview-replace-fragments (prefix processing-type &optional dir msg)
|
||||
"Replace all LaTeX fragments in the buffer with export appropriate forms.
|
||||
The way this is done is set by PROCESSING-TYPE, which can be either:
|
||||
- verabtim, in which case nothing is done
|
||||
- mathjax, in which case the TeX-style delimeters are replaced with
|
||||
LaTeX-style delimeters.
|
||||
- html, in which case the math fragment is replaced by the result of
|
||||
`org-format-latex-as-html'.
|
||||
- mathml, in which case the math fragment is replace by the result of
|
||||
`org-format-latex-as-mathml'.
|
||||
- an entry in `org-latex-preview-process-alist', in which case the
|
||||
math fragment is replaced with `org-create-latex-export'.
|
||||
|
||||
Generated image files are placed in DIR with the prefix PREFIX.
|
||||
Note that PREFIX may itself contain a directory path component.
|
||||
|
||||
When generating output files, MSG will be `message'd if given."
|
||||
(let* ((cnt 0))
|
||||
(save-excursion
|
||||
(dolist (element (org-latex-preview-collect-fragments))
|
||||
(let ((block-type (eq (org-element-type element)
|
||||
'latex-environment))
|
||||
(value (org-element-property :value element))
|
||||
(beg (org-element-property :begin element))
|
||||
(end (save-excursion
|
||||
(goto-char (org-element-property :end element))
|
||||
(skip-chars-backward " \r\t\n")
|
||||
(point))))
|
||||
(cond
|
||||
((eq processing-type 'verbatim)) ; Do nothing.
|
||||
((eq processing-type 'mathjax)
|
||||
;; Prepare for MathJax processing.
|
||||
(if (not (string-match "\\`\\$\\$?" value))
|
||||
(goto-char end)
|
||||
(delete-region beg end)
|
||||
(if (string= (match-string 0 value) "$$")
|
||||
(insert "\\[" (substring value 2 -2) "\\]")
|
||||
(insert "\\(" (substring value 1 -1) "\\)"))))
|
||||
((eq processing-type 'html)
|
||||
(goto-char beg)
|
||||
(delete-region beg end)
|
||||
(insert (org-format-latex-as-html value)))
|
||||
((eq processing-type 'mathml)
|
||||
;; Process to MathML.
|
||||
(unless (org-format-latex-mathml-available-p)
|
||||
(user-error "LaTeX to MathML converter not configured"))
|
||||
(cl-incf cnt)
|
||||
(when msg (message msg cnt))
|
||||
(goto-char beg)
|
||||
(delete-region beg end)
|
||||
(insert (org-format-latex-as-mathml
|
||||
value block-type prefix dir)))
|
||||
((assq processing-type org-latex-preview-process-alist)
|
||||
(let ((image-dir (expand-file-name prefix dir)))
|
||||
(unless (file-exists-p image-dir)
|
||||
(make-directory image-dir t)))
|
||||
(org-create-latex-export
|
||||
processing-type element prefix dir block-type))
|
||||
(t (error "Unknown conversion process %s for LaTeX fragments"
|
||||
processing-type))))))))
|
||||
|
||||
(defun org-latex-preview-fragments (processing-type &optional beg end)
|
||||
"Produce image overlays of LaTeX math fragments between BEG and END.
|
||||
|
||||
|
@ -2135,7 +2053,7 @@ process."
|
|||
preamble
|
||||
tempfile-p))
|
||||
|
||||
(defun org-latex-preview--tex-styled (processing-type value options &optional html-p)
|
||||
(defun org-latex-preview--tex-styled (processing-type value options)
|
||||
"Apply LaTeX style commands to VALUE based on OPTIONS.
|
||||
If PROCESSING-TYPE is dvipng, the colours are set with DVI
|
||||
\"\\special\" commands instead of \"\\color\" and
|
||||
|
@ -2144,14 +2062,12 @@ If PROCESSING-TYPE is dvipng, the colours are set with DVI
|
|||
VALUE is the math fragment text to be previewed.
|
||||
|
||||
OPTIONS is the plist `org-latex-preview-options' with customized
|
||||
color information for this run.
|
||||
|
||||
HTML-P, if true, uses colors required for HTML processing."
|
||||
(let* ((fg (pcase (plist-get options (if html-p :html-foreground :foreground))
|
||||
color information for this run."
|
||||
(let* ((fg (pcase (plist-get options :foreground)
|
||||
('default (org-latex-preview--format-color (org-latex-preview--attr-color :foreground)))
|
||||
((pred null) (org-latex-preview--format-color "Black"))
|
||||
(color (org-latex-preview--format-color color))))
|
||||
(bg (pcase (plist-get options (if html-p :html-background :background))
|
||||
(bg (pcase (plist-get options :background)
|
||||
('default (org-latex-preview--attr-color :background))
|
||||
("Transparent" nil)
|
||||
(bg (org-latex-preview--format-color bg))))
|
||||
|
@ -2171,62 +2087,6 @@ HTML-P, if true, uses colors required for HTML processing."
|
|||
"%\n"
|
||||
value)))
|
||||
|
||||
(defun org-create-latex-export (processing-type element prefix dir &optional block-type)
|
||||
"Create a export of the LaTeX math fragment ELEMENT using PROCESSING-TYPE.
|
||||
|
||||
Generated image files are placed in DIR with the prefix PREFIX.
|
||||
Note that PREFIX may itself contain a directory path component.
|
||||
|
||||
BLOCK-TYPE determines whether the result is placed inline or as a paragraph."
|
||||
(let* ((processing-info
|
||||
(cdr (assq processing-type org-latex-preview-process-alist)))
|
||||
(beg (org-element-property :begin element))
|
||||
(end (save-excursion
|
||||
(goto-char (org-element-property :end element))
|
||||
(skip-chars-backward " \r\t\n")
|
||||
(point)))
|
||||
(value (org-element-property :value element))
|
||||
(fg (plist-get org-latex-preview-options :foreground))
|
||||
(bg (plist-get org-latex-preview-options :background))
|
||||
(hash (sha1 (prin1-to-string
|
||||
(list processing-type
|
||||
org-latex-preview-preamble
|
||||
org-latex-default-packages-alist
|
||||
org-latex-packages-alist
|
||||
org-latex-preview-options
|
||||
'export value fg bg))))
|
||||
(imagetype (or (plist-get processing-info :image-output-type) "png"))
|
||||
(absprefix (expand-file-name prefix dir))
|
||||
(linkfile (format "%s_%s.%s" prefix hash imagetype))
|
||||
(movefile (format "%s_%s.%s" absprefix hash imagetype))
|
||||
(sep (and block-type "\n\n"))
|
||||
(link (concat sep "[[file:" linkfile "]]" sep))
|
||||
(options (org-combine-plists
|
||||
org-latex-preview-options
|
||||
(list :foreground fg :background bg))))
|
||||
(unless (file-exists-p movefile)
|
||||
(org-latex-preview-create-image
|
||||
value movefile options nil processing-type))
|
||||
(org-latex-preview-place-image-link link block-type beg end value)))
|
||||
|
||||
(defun org-latex-preview-place-image-link (link block-type beg end value)
|
||||
"Place then link LINK at BEG END."
|
||||
(delete-region beg end)
|
||||
(insert
|
||||
(org-add-props link
|
||||
(list 'org-latex-src
|
||||
(replace-regexp-in-string "\"" "" value)
|
||||
'org-latex-src-embed-type
|
||||
(if block-type 'paragraph 'character)))))
|
||||
|
||||
(defun org-format-latex-as-html (latex-fragment)
|
||||
"Convert LATEX-FRAGMENT to HTML.
|
||||
This uses `org-latex-to-html-convert-command', which see."
|
||||
(let ((cmd (format-spec org-latex-to-html-convert-command
|
||||
`((?i . ,latex-fragment)))))
|
||||
(message "Running %s" cmd)
|
||||
(shell-command-to-string cmd)))
|
||||
|
||||
(defun org-latex-preview--get-display-dpi ()
|
||||
"Get the DPI of the display.
|
||||
The function assumes that the display has the same pixel width in
|
||||
|
|
266
lisp/ox-html.el
266
lisp/ox-html.el
|
@ -39,6 +39,8 @@
|
|||
(require 'ox)
|
||||
(require 'ox-publish)
|
||||
(require 'table)
|
||||
(require 'org-latex-preview)
|
||||
(require 'ox-mathml)
|
||||
|
||||
|
||||
;;; Function Declarations
|
||||
|
@ -107,7 +109,8 @@
|
|||
(verbatim . org-html-verbatim)
|
||||
(verse-block . org-html-verse-block))
|
||||
:filters-alist '((:filter-options . org-html-infojs-install-script)
|
||||
(:filter-parse-tree . org-html-image-link-filter)
|
||||
(:filter-parse-tree org-html-image-link-filter
|
||||
org-html-prepare-latex-images)
|
||||
(:filter-final-output . org-html-final-function))
|
||||
:menu-entry
|
||||
'(?h "Export to HTML"
|
||||
|
@ -155,6 +158,7 @@
|
|||
(:html-infojs-template nil nil org-html-infojs-template)
|
||||
(:html-inline-image-rules nil nil org-html-inline-image-rules)
|
||||
(:html-link-org-files-as-html nil nil org-html-link-org-files-as-html)
|
||||
(:html-latex-image-options nil nil org-html-latex-image-options)
|
||||
(:html-mathjax-options nil nil org-html-mathjax-options)
|
||||
(:html-mathjax-template nil nil org-html-mathjax-template)
|
||||
(:html-metadata-timestamp-format nil nil org-html-metadata-timestamp-format)
|
||||
|
@ -1168,6 +1172,14 @@ See `format-time-string' for more information on its components."
|
|||
:package-version '(Org . "8.0")
|
||||
:type 'string)
|
||||
|
||||
(defcustom org-html-latex-image-options
|
||||
'(:foreground "Black" :background "Transparent" :scale 1.0)
|
||||
"LaTeX preview options that apply to generated images.
|
||||
This is a HTML-specific counterpart to `org-latex-preview-options', which see."
|
||||
:group 'org-export-html
|
||||
:package-version '(Org . "9.7")
|
||||
:type 'plist)
|
||||
|
||||
;;;; Template :: Mathjax
|
||||
|
||||
(defcustom org-html-mathjax-options
|
||||
|
@ -1653,6 +1665,33 @@ https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag"
|
|||
:package-version '(Org . "9.1")
|
||||
:type 'string)
|
||||
|
||||
;;;; LaTeX Fragments
|
||||
|
||||
(defcustom org-latex-to-html-convert-command nil
|
||||
"Shell command to convert LaTeX fragments to HTML.
|
||||
This command is very open-ended: the output of the command will
|
||||
directly replace the LaTeX fragment in the resulting HTML.
|
||||
Replace format-specifiers in the command as noted below and use
|
||||
`shell-command' to convert LaTeX to HTML.
|
||||
%i: The LaTeX fragment to be converted (shell-escaped).
|
||||
It must not be used inside a quoted argument, the result of %i
|
||||
expansion inside a quoted argument is undefined.
|
||||
|
||||
For example, this could be used with LaTeXML as
|
||||
\"latexmlc literal:%i --profile=math --preload=siunitx.sty 2>/dev/null\"."
|
||||
:group 'org-latex
|
||||
:package-version '(Org . "9.4")
|
||||
:type '(choice
|
||||
(const :tag "None" nil)
|
||||
(string :tag "Shell command")))
|
||||
|
||||
(defun org-format-latex-as-html (latex-fragment)
|
||||
"Convert LATEX-FRAGMENT to HTML.
|
||||
This uses `org-latex-to-html-convert-command', which see."
|
||||
(let ((cmd (format-spec org-latex-to-html-convert-command
|
||||
`((?i . ,latex-fragment)))))
|
||||
(message "Running %s" cmd)
|
||||
(shell-command-to-string cmd)))
|
||||
|
||||
;;;; Todos
|
||||
|
||||
|
@ -1777,11 +1816,7 @@ a communication channel."
|
|||
(org-html--make-attribute-string
|
||||
(org-combine-plists
|
||||
(list :src source
|
||||
:alt (if (string-match-p
|
||||
(concat "^" org-preview-latex-image-directory) source)
|
||||
(org-html-encode-plain-text
|
||||
(org-find-text-property-in-string 'org-latex-src source))
|
||||
(file-name-nondirectory source)))
|
||||
:alt (file-name-nondirectory source))
|
||||
(if (string= "svg" (file-name-extension source))
|
||||
(org-combine-plists '(:class "org-svg") attributes '(:fallback nil))
|
||||
attributes)))
|
||||
|
@ -3003,58 +3038,98 @@ CONTENTS is nil. INFO is a plist holding contextual information."
|
|||
|
||||
;;;; LaTeX Environment
|
||||
|
||||
(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 can
|
||||
be `mathjax', `verbatim', `html', nil, t or symbols in
|
||||
`org-latex-preview-process-alist', e.g., `dvipng', `dvisvgm' or
|
||||
`imagemagick'. See `org-html-with-latex' for more information.
|
||||
INFO is a plist containing export properties."
|
||||
(let ((cache-relpath "") (cache-dir ""))
|
||||
(unless (or (eq processing-type 'mathjax)
|
||||
(eq processing-type 'html))
|
||||
(let ((bfn (or (buffer-file-name)
|
||||
(make-temp-name
|
||||
(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 (file-name-as-directory org-preview-latex-image-directory)
|
||||
(file-name-sans-extension
|
||||
(file-name-nondirectory 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))))
|
||||
(org-export-with-buffer-copy
|
||||
:to-buffer (get-buffer-create " *Org HTML Export LaTeX*")
|
||||
:drop-visibility t :drop-narrowing t :drop-contents t
|
||||
(erase-buffer)
|
||||
(insert latex-frag)
|
||||
(org-latex-preview-replace-fragments
|
||||
cache-relpath processing-type cache-dir "Creating LaTeX Image...")
|
||||
(buffer-string))))
|
||||
(defun org-html-prepare-latex-images (parse-tree _backend info)
|
||||
"Make sure that appropriate preview images exist for all LaTeX
|
||||
TODO."
|
||||
(when (assq (plist-get info :with-latex) org-latex-preview-process-alist)
|
||||
(let* ((elements
|
||||
(org-element-map parse-tree
|
||||
'(latex-fragment latex-environment)
|
||||
#'identity
|
||||
info))
|
||||
(entries-and-numbering
|
||||
(org-latex-preview--construct-entries
|
||||
elements t parse-tree))
|
||||
(processing-type (plist-get info :with-latex))
|
||||
(processing-info
|
||||
(cdr (assq processing-type org-latex-preview-process-alist)))
|
||||
(imagetype (or (plist-get processing-info :image-output-type) "png"))
|
||||
(numbering-offsets (cons nil (cadr entries-and-numbering)))
|
||||
(html-options (plist-get info :html-latex-image-options))
|
||||
(element-hash-table (make-hash-table :test #'eq :size (length elements)))
|
||||
fragment-info prev-fg prev-bg)
|
||||
(cl-loop
|
||||
for entry in (car entries-and-numbering)
|
||||
for element in elements
|
||||
do
|
||||
(pcase-let* ((`(,beg ,end ,provided-value) entry)
|
||||
(value (or provided-value
|
||||
(buffer-substring-no-properties beg end)))
|
||||
(fg (plist-get html-options :foreground))
|
||||
(bg (plist-get html-options :background))
|
||||
(number (car (setq numbering-offsets (cdr numbering-offsets))))
|
||||
(hash (org-latex-preview--hash
|
||||
processing-type value imagetype fg bg number))
|
||||
(options (org-combine-plists
|
||||
org-latex-preview-options
|
||||
html-options
|
||||
(list :number number
|
||||
:continue-color
|
||||
(and (equal prev-bg bg)
|
||||
(equal prev-fg fg))))))
|
||||
(puthash element hash element-hash-table)
|
||||
(unless (org-latex-preview--get-cached hash)
|
||||
(push (list :string (org-latex-preview--tex-styled
|
||||
processing-type value options)
|
||||
:overlay (org-latex-preview--ensure-overlay beg end)
|
||||
:key hash)
|
||||
fragment-info))
|
||||
(setq prev-fg fg prev-bg bg)))
|
||||
(let ((org-latex-preview-options
|
||||
(list (plist-member html-options :scale))))
|
||||
(when fragment-info
|
||||
(apply #'org-async-wait-for
|
||||
(org-latex-preview--create-image-async
|
||||
processing-type
|
||||
(nreverse fragment-info)))))
|
||||
(plist-put info :html-latex-preview-hash-table element-hash-table)
|
||||
nil)))
|
||||
|
||||
(defun org-html--wrap-latex-environment (contents _ &optional caption label)
|
||||
(defun org-html--as-latex (element info &optional content)
|
||||
(let ((content (or content (org-element-property :value element))))
|
||||
(pcase (plist-get info :with-latex)
|
||||
('verbatim ; Do nothing.
|
||||
content)
|
||||
((or 't 'mathjax)
|
||||
(cond ; Prepare for MathJax processing.
|
||||
((string-match-p "\\`\\$\\$" content)
|
||||
(concat "\\[" (substring content 2 -2) "\\]"))
|
||||
((string-match-p "\\`\\$" content)
|
||||
(concat "\\(" (substring content 1 -1) "\\)"))
|
||||
(t content)))
|
||||
('html
|
||||
(org-format-latex-as-html content))
|
||||
('mathml
|
||||
(if-let ((path (org-mathml-convert-latex-cached content)))
|
||||
(with-temp-buffer
|
||||
(insert-file-contents path)
|
||||
(buffer-string))
|
||||
content))
|
||||
((and ptype (guard (assq ptype org-latex-preview-process-alist)))
|
||||
(org-html-latex-image element info))
|
||||
(processing-type
|
||||
(warn "LaTeX fragment processor `%s' is unknown" processing-type)
|
||||
content))))
|
||||
|
||||
(defun org-html--wrap-latex-environment (contents &optional label)
|
||||
"Wrap CONTENTS string within appropriate environment for equations.
|
||||
When optional arguments CAPTION and LABEL are given, use them for
|
||||
caption and \"id\" attribute."
|
||||
(format "\n<div%s class=\"equation-container\">\n%s%s\n</div>"
|
||||
(format "\n<div%s class=\"equation-container\">\n%s\n</div>"
|
||||
;; ID.
|
||||
(if (org-string-nw-p label) (format " id=\"%s\"" label) "")
|
||||
;; Contents.
|
||||
(format "<span class=\"equation\">\n%s\n</span>" contents)
|
||||
;; Caption.
|
||||
(if (not (org-string-nw-p caption)) ""
|
||||
(format "\n<span class=\"equation-label\">\n%s\n</span>"
|
||||
caption))))
|
||||
(format "<span class=\"equation\">\n%s\n</span>" contents)))
|
||||
|
||||
(defun org-html--math-environment-p (element &optional _)
|
||||
"Non-nil when ELEMENT is a LaTeX math environment.
|
||||
|
@ -3086,57 +3161,56 @@ For instance, change an `equation' environment to `equation*'."
|
|||
"Transcode a LATEX-ENVIRONMENT element from Org to HTML.
|
||||
CONTENTS is nil. INFO is a plist holding contextual information."
|
||||
(let ((processing-type (plist-get info :with-latex))
|
||||
(latex-frag (org-remove-indentation
|
||||
(org-element-property :value latex-environment)))
|
||||
(attributes (org-export-read-attribute :attr_html latex-environment))
|
||||
(label (org-html--reference latex-environment info t))
|
||||
(caption (and (org-html--latex-environment-numbered-p latex-environment)
|
||||
(number-to-string
|
||||
(org-export-get-ordinal
|
||||
latex-environment info nil
|
||||
(lambda (l _)
|
||||
(and (org-html--math-environment-p l)
|
||||
(org-html--latex-environment-numbered-p l))))))))
|
||||
(cond
|
||||
((memq processing-type '(t mathjax))
|
||||
(org-html-format-latex
|
||||
(if (org-string-nw-p label)
|
||||
(replace-regexp-in-string "\\`.*"
|
||||
(format "\\&\n\\\\label{%s}" label)
|
||||
latex-frag)
|
||||
latex-frag)
|
||||
'mathjax info))
|
||||
((assq processing-type org-latex-preview-process-alist)
|
||||
(let ((formula-link
|
||||
(org-html-format-latex
|
||||
(org-html--unlabel-latex-environment latex-frag)
|
||||
processing-type info)))
|
||||
(when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
|
||||
(let ((source (org-export-file-uri (match-string 1 formula-link))))
|
||||
(org-html--wrap-latex-environment
|
||||
(org-html--format-image source attributes info)
|
||||
info caption label)))))
|
||||
(t (org-html--wrap-latex-environment latex-frag info caption label)))))
|
||||
(latex-frag (org-remove-indentation
|
||||
(org-element-property :value latex-environment)))
|
||||
(label (org-html--reference latex-environment info t)))
|
||||
(if (memq processing-type '(t mathjax))
|
||||
(org-html--as-latex
|
||||
latex-environment info
|
||||
(if (org-string-nw-p label)
|
||||
(replace-regexp-in-string "\\`.*"
|
||||
(format "\\&\n\\\\label{%s}" label)
|
||||
latex-frag)
|
||||
latex-frag))
|
||||
(org-html--wrap-latex-environment
|
||||
(org-html--as-latex latex-environment info latex-frag)
|
||||
label))))
|
||||
|
||||
;;;; LaTeX Fragment
|
||||
|
||||
(defun org-html-latex-fragment (latex-fragment _contents info)
|
||||
"Transcode a LATEX-FRAGMENT object from Org to HTML.
|
||||
CONTENTS is nil. INFO is a plist holding contextual information."
|
||||
(let ((latex-frag (org-element-property :value latex-fragment))
|
||||
(processing-type (plist-get info :with-latex)))
|
||||
(cond
|
||||
((memq processing-type '(t mathjax))
|
||||
(org-html-format-latex latex-frag 'mathjax info))
|
||||
((memq processing-type '(t html))
|
||||
(org-html-format-latex latex-frag 'html info))
|
||||
((assq processing-type org-latex-preview-process-alist)
|
||||
(let ((formula-link
|
||||
(org-html-format-latex latex-frag processing-type info)))
|
||||
(when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
|
||||
(let ((source (org-export-file-uri (match-string 1 formula-link))))
|
||||
(org-html--format-image source nil info)))))
|
||||
(t latex-frag))))
|
||||
(org-html--as-latex latex-fragment info))
|
||||
|
||||
(defun org-html-latex-image (element info)
|
||||
"TODO"
|
||||
(let* ((hash (gethash element (plist-get info :html-latex-preview-hash-table)))
|
||||
(path-info (org-latex-preview--get-cached hash)))
|
||||
(unless hash
|
||||
(error "Expected LaTeX preview hash to exist for element, but none found"))
|
||||
(unless path-info
|
||||
(error "Expected LaTeX preview %S to exist in the cache" hash))
|
||||
(unless (car path-info)
|
||||
(error "LaTeX preview image path is nil"))
|
||||
(unless (file-exists-p (car path-info))
|
||||
(error "Expected LaTeX preview file for %S to exist" hash))
|
||||
(org-html-close-tag
|
||||
"img"
|
||||
(org-html--make-attribute-string
|
||||
(list :src (car path-info)
|
||||
:alt (org-html-encode-plain-text
|
||||
(org-element-property :value element))
|
||||
:style (if (eq (org-element-type element) 'latex-environment)
|
||||
(format "height: %.4fem"
|
||||
(plist-get (cdr path-info) :height))
|
||||
(format "height: %.4fem; vertical-align: -%.4fem; display: inline-block"
|
||||
(plist-get (cdr path-info) :height)
|
||||
(plist-get (cdr path-info) :depth)))
|
||||
:class (if (eq (org-element-type element) 'latex-environment)
|
||||
"org-latex org-latex-environment"
|
||||
"org-latex org-latex-fragment")))
|
||||
info)))
|
||||
|
||||
;;;; Line Break
|
||||
|
||||
|
|
Loading…
Reference in New Issue