summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2013-04-17 18:43:01 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2013-04-17 18:43:01 +0200
commitb335a4fa34dd33850c9c077943f3bd88eb6894b7 (patch)
tree4843825f6ebdade60362d7a6e54c8ac1af4d8cc4
parent2ba19bb803000123e2c095a6c2515e601da00f45 (diff)
downloadorg-mode-b335a4fa34dd33850c9c077943f3bd88eb6894b7.tar.gz
ox-latex: Improve subscript/superscript export
* lisp/ox-latex.el (org-latex--script-size): New function. (org-latex-subscript, org-latex-superscript): Use new function.
-rw-r--r--lisp/ox-latex.el91
1 files changed, 41 insertions, 50 deletions
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 4d09579..dafb991 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2201,35 +2201,50 @@ holding contextual information."
;;;; Subscript
+(defun org-latex--script-size (object 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)
+ (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\\mathrm{%s}"
+ output
+ ;; \mathrm command doesn't handle spaces, so
+ ;; we have to enforce them.
+ (replace-regexp-in-string
+ " " "\\\\ " (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.
+ (format (if (= (length output) 1) "$%s%s$" "$%s{%s}$")
+ (if (eq (org-element-type object) 'subscript) "_" "^")
+ output)))
+
(defun org-latex-subscript (subscript contents info)
"Transcode a SUBSCRIPT object from Org to LaTeX.
CONTENTS is the contents of the object. INFO is a plist holding
contextual information."
- (if (= (length contents) 1) (format "$_%s$" contents)
- ;; Handle multiple objects in SUBSCRIPT by creating a subscript
- ;; command for each of them.
- (let ((prev-blanks 0))
- (mapconcat
- (lambda (obj)
- (case (org-element-type obj)
- ((entity latex-fragment)
- (setq prev-blanks (org-element-property :post-blank obj))
- (let ((data (org-trim (org-export-data obj info))))
- (string-match
- "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
- data)
- (format "$_{%s}$" (match-string 1 data))))
- (plain-text
- (format "$_\\mathrm{%s}$"
- (concat (make-string prev-blanks ? )
- ;; mathrm command doesn't handle spaces,
- ;; so we have to enforce them.
- (replace-regexp-in-string
- " " "\\\\ " (org-export-data obj info)))))
- (otherwise
- (setq prev-blanks (org-element-property :post-blank obj))
- (format "$_{%s}$" (org-export-data obj info)))))
- (org-element-contents subscript) ""))))
+ (org-latex--script-size subscript info))
;;;; Superscript
@@ -2238,31 +2253,7 @@ contextual information."
"Transcode a SUPERSCRIPT object from Org to LaTeX.
CONTENTS is the contents of the object. INFO is a plist holding
contextual information."
- (if (= (length contents) 1) (format "$^%s$" contents)
- ;; Handle multiple objects in SUPERSCRIPT by creating
- ;; a superscript command for each of them.
- (let ((prev-blanks 0))
- (mapconcat
- (lambda (obj)
- (case (org-element-type obj)
- ((entity latex-fragment)
- (setq prev-blanks (org-element-property :post-blank obj))
- (let ((data (org-trim (org-export-data obj info))))
- (string-match
- "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
- data)
- (format "$^{%s}$" (match-string 1 data))))
- (plain-text
- (format "$^\\mathrm{%s}$"
- (concat (make-string prev-blanks ? )
- ;; mathrm command doesn't handle spaces,
- ;; so we have to enforce them.
- (replace-regexp-in-string
- " " "\\\\ " (org-export-data obj info)))))
- (otherwise
- (setq prev-blanks (org-element-property :post-blank obj))
- (format "$^{%s}$" (org-export-data obj info)))))
- (org-element-contents superscript) ""))))
+ (org-latex--script-size superscript info))
;;;; Table