From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: [patch][ox-latex] context-aware subscript Date: Thu, 29 Aug 2013 12:50:26 +0200 Message-ID: <87vc2oojnx.fsf@gmx.us> References: <877gfjqq6w.fsf@pank.eu> <87tximt7bb.fsf@gmail.com> <87r4deqbav.fsf@gmx.us> <874naaorz1.fsf@gmail.com> <8761uqorlr.fsf@gmx.us> <87sixty63g.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VEzoE-00088z-AP for emacs-orgmode@gnu.org; Thu, 29 Aug 2013 06:50:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VEzo7-0001o9-8x for emacs-orgmode@gnu.org; Thu, 29 Aug 2013 06:50:37 -0400 Received: from mout.gmx.net ([212.227.17.20]:60370) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VEzo6-0001o1-GW for emacs-orgmode@gnu.org; Thu, 29 Aug 2013 06:50:30 -0400 Received: from dhcppc1 ([94.34.148.81]) by mail.gmx.com (mrgmx003) with ESMTPSA (Nemesis) id 0MXqaN-1VZ74u3djD-00WlYr for ; Thu, 29 Aug 2013 12:50:28 +0200 In-Reply-To: <87sixty63g.fsf@gmail.com> (Nicolas Goaziou's message of "Wed, 28 Aug 2013 21:21:07 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: n.goaziou@gmail.com Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Nicolas Goaziou writes: > Rasmus writes: > >>> Correct. Then, fixing it is more important than caring about some user >>> filter. >> >> OK, can I help? > > Sure, please go ahead. I've just enclosed a quick patch (as in doesn't contain proper commit msg), but it's basically the previous patch minus the removal of \text in math plus some quick checks towards potential nasty filters. It works with the following test file, but let me know about more hair-pulling test cases, and/or filters. #+BEGIN_SRC Org * filters :noexport: #+begin_src emacs-lisp (defun test-filter (script backend info) (when (org-export-derived-backend-p backend 'latex) (if (string-match "a" script) "" script))) (defun test-filter2 (script backend info) (when (org-export-derived-backend-p backend 'latex) (replace-regexp-in-string "zz" "" script))) (add-to-list 'org-export-filter-subscript-functions 'test-filter) (add-to-list 'org-export-filter-subscript-functions 'test-filter2) #+end_src * test | | mathp | text | |----------------------+-------+------| | merge maybe | \beta_t | \times_t | | long merge maybe | \beta_tb | \times_tb | | filter drop | \beta_abc | \times_abc | | filter replace all | \beta_zz | \times_zz | | filter replace parts | \beta_zzx | \times_zzx | #+END_SRC The output is something like this (hline removed) & mathp & text \\ %%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%% merge maybe & $\beta_{\text{t}}$ & \texttimes{}$_{\text{t}}$ \\ long merge maybe & $\beta_{\text{tb}}$ & \texttimes{}$_{\text{tb}}$ \\ filter drop & $\beta$ & \texttimes{} \\ filter replace all & $\beta_{\text{}}$ & \texttimes{}$_{\text{}}$ \\ filter replace parts & $\beta_{\text{x}}$ & \texttimes{}$_{\text{x}}$ \\ --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-maybe-merge-subscript-and-mathp-entity-with-some-che.patch >From b59c60eb7df5b1ff927aff9f4442b1d226d24ceb Mon Sep 17 00:00:00 2001 From: rasmus Date: Thu, 29 Aug 2013 12:18:00 +0200 Subject: [PATCH] maybe merge subscript and mathp entity with some checks --- lisp/ox-latex.el | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 1fe918a..91ab912 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -1234,8 +1234,25 @@ holding contextual information. See `org-export-data'." "Transcode an ENTITY object from Org to LaTeX. CONTENTS are the definition itself. INFO is a plist holding contextual information." - (let ((ent (org-element-property :latex entity))) - (if (org-element-property :latex-math-p entity) (format "$%s$" ent) ent))) + (let ((ent (org-element-property :latex entity)) + (prev (org-export-get-previous-element entity info)) + (next (org-export-get-next-element entity info)) + (no-post-blanks-p (= (or (org-element-property :post-blank entity) 1) 0)) + (no-pre-blanks-p (= (or (org-element-property :post-blank + (org-export-get-previous-element + entity info)) 1) 0)) + (scripts '(subscript superscript))) + (if (not (org-element-property :latex-math-p entity)) ent + (concat + (if (and no-pre-blanks-p + (memq (org-element-type prev) scripts) + (not (eq (org-export-data prev info) ""))) + "" "$") + ent + (if (and no-post-blanks-p + (memq (org-element-type next) scripts) + (not (eq (org-export-data next info) ""))) + "" "$"))))) ;;;; Example Block @@ -2232,12 +2249,14 @@ channel." ;; 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))))) + (and + (not (org-element-property :latex-math-p prev)) + (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) "{") -- 1.8.4 --=-=-= Content-Type: text/plain -- When in doubt, do it! --=-=-=--