Function: org-latex--wrap-latex-math-block
org-latex--wrap-latex-math-block is a byte-compiled function defined
in ox-latex.el.gz.
Signature
(org-latex--wrap-latex-math-block DATA INFO)
Documentation
Merge contiguous math objects in a pseudo-object container.
DATA is a parse tree or a secondary string. INFO is a plist containing export options. Modify DATA by side-effect and return it.
Source Code
;; Defined in /usr/src/emacs/lisp/org/ox-latex.el.gz
;;;; Pseudo Object: LaTeX Math Block
;; `latex-math-block' objects have the following property:
;; `:post-blank'.
(defun org-latex--wrap-latex-math-block (data info)
"Merge contiguous math objects in a pseudo-object container.
DATA is a parse tree or a secondary string. INFO is a plist
containing export options. Modify DATA by side-effect and return it."
(let ((valid-object-p
;; Non-nil when OBJECT can be added to a latex math block.
(lambda (object)
(pcase (org-element-type object)
(`entity (org-element-property :latex-math-p object))
(`latex-fragment
(let ((value (org-element-property :value object)))
(or (string-prefix-p "\\(" value)
(string-match-p "\\`\\$[^$]" value))))))))
(org-element-map data '(entity latex-fragment)
(lambda (object)
;; Skip objects already wrapped.
(when (and (not (org-element-type-p
(org-element-parent object) 'latex-math-block))
(funcall valid-object-p object))
(let ((math-block (list 'latex-math-block nil))
(next-elements (org-export-get-next-element object info t))
(last object))
;; Wrap MATH-BLOCK around OBJECT in DATA.
(org-element-insert-before math-block object)
(org-element-extract object)
(org-element-adopt math-block object)
(when (zerop (or (org-element-property :post-blank object) 0))
;; MATH-BLOCK swallows consecutive math objects.
(catch 'exit
(dolist (next next-elements)
(unless (funcall valid-object-p next) (throw 'exit nil))
(org-element-extract next)
(org-element-adopt math-block next)
;; Eschew the case: \beta$x$ -> \(\betax\).
(org-element-put-property last :post-blank 1)
(setq last next)
(when (> (or (org-element-property :post-blank next) 0) 0)
(throw 'exit nil)))))
(org-element-put-property
math-block :post-blank (org-element-property :post-blank last)))))
info nil '(latex-math-block) t)
;; Return updated DATA.
data))