Browse Source

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.
Nicolas Goaziou 4 years ago
parent
commit
77c5710de2
1 changed files with 20 additions and 3 deletions
  1. 20 3
      lisp/ox-latex.el

+ 20 - 3
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.