ox-latex: Better handling of sub/superscript within sub/superscript

* lisp/ox-latex.el (org-latex--script-size): Fix error when using
  sub/superscript within sub/superscript.
This commit is contained in:
Nicolas Goaziou 2013-04-17 20:57:21 +02:00
parent 79ecb6570b
commit d57b9e84e1
1 changed files with 19 additions and 4 deletions

View File

@ -2205,7 +2205,17 @@ holding contextual information."
"Transcode a subscript or superscript object. "Transcode a subscript or superscript object.
OBJECT is an Org object. INFO is a plist used as a communication OBJECT is an Org object. INFO is a plist used as a communication
channel." channel."
(let ((output "")) (let ((in-script-p
;; Non-nil if object is already in a sub/superscript.
(let ((parent object))
(catch 'exit
(while (setq parent (org-export-get-parent parent))
(let ((type (org-element-type parent)))
(cond ((memq type '(subscript superscript))
(throw 'exit t))
((memq type org-element-all-elements)
(throw 'exit nil))))))))
(output ""))
(org-element-map (org-element-contents object) (org-element-map (org-element-contents object)
(cons 'plain-text org-element-all-objects) (cons 'plain-text org-element-all-objects)
(lambda (obj) (lambda (obj)
@ -2235,10 +2245,15 @@ channel."
(let ((blank (org-element-property :post-blank obj))) (let ((blank (org-element-property :post-blank obj)))
(and blank (> blank 0) "\\ "))))))) (and blank (> blank 0) "\\ ")))))))
info nil org-element-recursive-objects) info nil org-element-recursive-objects)
;; Result. ;; Result. Do not wrap into math mode if already in a subscript
(format (if (= (length output) 1) "$%s%s$" "$%s{%s}$") ;; or superscript. Do not wrap into curly brackets if OUTPUT is
;; a single character.
(concat (and (not in-script-p) "$")
(if (eq (org-element-type object) 'subscript) "_" "^") (if (eq (org-element-type object) 'subscript) "_" "^")
output))) (and (> (length output) 1) "{")
output
(and (> (length output) 1) "}")
(and (not in-script-p) "$"))))
(defun org-latex-subscript (subscript contents info) (defun org-latex-subscript (subscript contents info)
"Transcode a SUBSCRIPT object from Org to LaTeX. "Transcode a SUBSCRIPT object from Org to LaTeX.