From 77c5710de2256dd19a1b05ea8411e787f611a515 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 18 Apr 2013 00:06:06 +0200 Subject: [PATCH] ox-latex: Handle consecutive alterning sub and superscript * lisp/ox-latex.el (org-latex--script-size): Handle consecutive alterning sub and superscript. This patch fixes export of "a^b_c" constructs. --- lisp/ox-latex.el | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index c6fb9a0fe..2a315ef70 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -2215,6 +2215,7 @@ channel." (throw 'exit t)) ((memq type org-element-all-elements) (throw 'exit nil)))))))) + (type (org-element-type object)) (output "")) (org-element-map (org-element-contents object) (cons 'plain-text org-element-all-objects) @@ -2242,13 +2243,29 @@ channel." info nil org-element-recursive-objects) ;; Result. Do not wrap into math mode if already in a subscript ;; or superscript. Do not wrap into curly brackets if OUTPUT is - ;; a single character. - (concat (and (not in-script-p) "$") + ;; a single character. Also merge consecutive subscript and + ;; superscript into the same math snippet. + (concat (and (not in-script-p) + (let ((prev (org-export-get-previous-element object info))) + (or (not prev) + (not (eq (org-element-type prev) + (if (eq type 'subscript) 'superscript + 'subscript))) + (let ((blank (org-element-property :post-blank prev))) + (and blank (> blank 0))))) + "$") (if (eq (org-element-type object) 'subscript) "_" "^") (and (> (length output) 1) "{") output (and (> (length output) 1) "}") - (and (not in-script-p) "$")))) + (and (not in-script-p) + (or (let ((blank (org-element-property :post-blank object))) + (and blank (> blank 0))) + (not (eq (org-element-type + (org-export-get-next-element object info)) + (if (eq type 'subscript) 'superscript + 'subscript)))) + "$")))) (defun org-latex-subscript (subscript contents info) "Transcode a SUBSCRIPT object from Org to LaTeX. -- 2.11.4.GIT