forked from mirrors/org-mode
ox-latex: Improve subscript and superscript
* lisp/ox-latex.el (org-latex--wrap-latex-math-block): Ignore superscript and subscript. (org-latex--script-size): Remove function. (org-latex-subscript): Use \textsubscript. (org-latex-superscript): Use \textsuperscript. Reported-by: Ken Mankoff <mankoff@gmail.com> <http://lists.gnu.org/r/emacs-orgmode/2018-12/msg00221.html>
This commit is contained in:
parent
c024844e56
commit
0811af50b4
|
@ -2768,24 +2768,21 @@ channel."
|
||||||
DATA is a parse tree or a secondary string. INFO is a plist
|
DATA is a parse tree or a secondary string. INFO is a plist
|
||||||
containing export options. Modify DATA by side-effect and return it."
|
containing export options. Modify DATA by side-effect and return it."
|
||||||
(let ((valid-object-p
|
(let ((valid-object-p
|
||||||
;; Non-nil when OBJ can be added to the latex math block B.
|
;; Non-nil when OBJECT can be added to a latex math block.
|
||||||
(lambda (obj b)
|
(lambda (object)
|
||||||
(pcase (org-element-type obj)
|
(pcase (org-element-type object)
|
||||||
(`entity (org-element-property :latex-math-p obj))
|
(`entity (org-element-property :latex-math-p object))
|
||||||
(`latex-fragment
|
(`latex-fragment
|
||||||
(let ((value (org-element-property :value obj)))
|
(let ((value (org-element-property :value object)))
|
||||||
(or (string-prefix-p "\\(" value)
|
(or (string-prefix-p "\\(" value)
|
||||||
(string-match-p "\\`\\$[^$]" value))))
|
(string-match-p "\\`\\$[^$]" value))))))))
|
||||||
((and type (or `subscript `superscript))
|
(org-element-map data '(entity latex-fragment)
|
||||||
(not (memq type (mapcar #'org-element-type
|
|
||||||
(org-element-contents b)))))))))
|
|
||||||
(org-element-map data '(entity latex-fragment subscript superscript)
|
|
||||||
(lambda (object)
|
(lambda (object)
|
||||||
;; Skip objects already wrapped.
|
;; Skip objects already wrapped.
|
||||||
(when (and (not (eq (org-element-type
|
(when (and (not (eq (org-element-type
|
||||||
(org-element-property :parent object))
|
(org-element-property :parent object))
|
||||||
'latex-math-block))
|
'latex-math-block))
|
||||||
(funcall valid-object-p object nil))
|
(funcall valid-object-p object))
|
||||||
(let ((math-block (list 'latex-math-block nil))
|
(let ((math-block (list 'latex-math-block nil))
|
||||||
(next-elements (org-export-get-next-element object info t))
|
(next-elements (org-export-get-next-element object info t))
|
||||||
(last object))
|
(last object))
|
||||||
|
@ -2797,20 +2794,17 @@ containing export options. Modify DATA by side-effect and return it."
|
||||||
;; MATH-BLOCK swallows consecutive math objects.
|
;; MATH-BLOCK swallows consecutive math objects.
|
||||||
(catch 'exit
|
(catch 'exit
|
||||||
(dolist (next next-elements)
|
(dolist (next next-elements)
|
||||||
(unless (funcall valid-object-p next math-block)
|
(unless (funcall valid-object-p next) (throw 'exit nil))
|
||||||
(throw 'exit nil))
|
|
||||||
(org-element-extract-element next)
|
(org-element-extract-element next)
|
||||||
(org-element-adopt-elements math-block next)
|
(org-element-adopt-elements math-block next)
|
||||||
;; Eschew the case: \beta$x$ -> \(\betax\).
|
;; Eschew the case: \beta$x$ -> \(\betax\).
|
||||||
(unless (memq (org-element-type next)
|
(org-element-put-property last :post-blank 1)
|
||||||
'(subscript superscript))
|
|
||||||
(org-element-put-property last :post-blank 1))
|
|
||||||
(setq last next)
|
(setq last next)
|
||||||
(when (> (or (org-element-property :post-blank next) 0) 0)
|
(when (> (or (org-element-property :post-blank next) 0) 0)
|
||||||
(throw 'exit nil)))))
|
(throw 'exit nil)))))
|
||||||
(org-element-put-property
|
(org-element-put-property
|
||||||
math-block :post-blank (org-element-property :post-blank last)))))
|
math-block :post-blank (org-element-property :post-blank last)))))
|
||||||
info nil '(subscript superscript latex-math-block) t)
|
info nil '(latex-math-block) t)
|
||||||
;; Return updated DATA.
|
;; Return updated DATA.
|
||||||
data))
|
data))
|
||||||
|
|
||||||
|
@ -3065,56 +3059,18 @@ holding contextual information."
|
||||||
|
|
||||||
;;;; Subscript
|
;;;; Subscript
|
||||||
|
|
||||||
(defun org-latex--script-size (object info)
|
(defun org-latex-subscript (_subscript contents _info)
|
||||||
"Transcode a subscript or superscript object.
|
|
||||||
OBJECT is an Org object. INFO is a plist used as a communication
|
|
||||||
channel."
|
|
||||||
(let ((output ""))
|
|
||||||
(org-element-map (org-element-contents object)
|
|
||||||
(cons 'plain-text org-element-all-objects)
|
|
||||||
(lambda (obj)
|
|
||||||
(cl-case (org-element-type obj)
|
|
||||||
((entity latex-fragment)
|
|
||||||
(let ((data (org-trim (org-export-data obj info))))
|
|
||||||
(string-match
|
|
||||||
"\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
|
|
||||||
data)
|
|
||||||
(setq output
|
|
||||||
(concat output
|
|
||||||
(match-string 1 data)
|
|
||||||
(let ((blank (org-element-property :post-blank obj)))
|
|
||||||
(and blank (> blank 0) "\\ "))))))
|
|
||||||
(plain-text
|
|
||||||
(setq output
|
|
||||||
(format "%s\\text{%s}" output (org-export-data obj info))))
|
|
||||||
(otherwise
|
|
||||||
(setq output
|
|
||||||
(concat output
|
|
||||||
(org-export-data obj info)
|
|
||||||
(let ((blank (org-element-property :post-blank obj)))
|
|
||||||
(and blank (> blank 0) "\\ ")))))))
|
|
||||||
info nil org-element-recursive-objects)
|
|
||||||
;; Result. Do not wrap into curly brackets if OUTPUT is a single
|
|
||||||
;; character.
|
|
||||||
(concat (if (eq (org-element-type object) 'subscript) "_" "^")
|
|
||||||
(and (> (length output) 1) "{")
|
|
||||||
output
|
|
||||||
(and (> (length output) 1) "}"))))
|
|
||||||
|
|
||||||
(defun org-latex-subscript (subscript _contents info)
|
|
||||||
"Transcode a SUBSCRIPT object from Org to LaTeX.
|
"Transcode a SUBSCRIPT object from Org to LaTeX.
|
||||||
CONTENTS is the contents of the object. INFO is a plist holding
|
CONTENTS is the contents of the object."
|
||||||
contextual information."
|
(format "\\textsubscript{%s}" contents))
|
||||||
(org-latex--script-size subscript info))
|
|
||||||
|
|
||||||
|
|
||||||
;;;; Superscript
|
;;;; Superscript
|
||||||
|
|
||||||
(defun org-latex-superscript (superscript _contents info)
|
(defun org-latex-superscript (_superscript contents _info)
|
||||||
"Transcode a SUPERSCRIPT object from Org to LaTeX.
|
"Transcode a SUPERSCRIPT object from Org to LaTeX.
|
||||||
CONTENTS is the contents of the object. INFO is a plist holding
|
CONTENTS is the contents of the object."
|
||||||
contextual information."
|
(format "\\textsuperscript{%s}" contents))
|
||||||
(org-latex--script-size superscript info))
|
|
||||||
|
|
||||||
|
|
||||||
;;;; Table
|
;;;; Table
|
||||||
|
|
Loading…
Reference in a new issue