From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [patch][ox-latex] context-aware subscript Date: Sat, 31 Aug 2013 16:46:14 +0200 Message-ID: <87y57hncjt.fsf@gmail.com> 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> <87vc2oojnx.fsf@gmx.us> <87k3j2nusy.fsf@gmail.com> <87ioymj705.fsf@gmx.us> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60781) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VFmRD-0006JN-Um for emacs-orgmode@gnu.org; Sat, 31 Aug 2013 10:46:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VFmR8-0002RZ-5E for emacs-orgmode@gnu.org; Sat, 31 Aug 2013 10:46:07 -0400 Received: from mail-ee0-x22f.google.com ([2a00:1450:4013:c00::22f]:38155) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VFmR7-0002RV-UY for emacs-orgmode@gnu.org; Sat, 31 Aug 2013 10:46:02 -0400 Received: by mail-ee0-f47.google.com with SMTP id d49so1434950eek.20 for ; Sat, 31 Aug 2013 07:46:01 -0700 (PDT) In-Reply-To: <87ioymj705.fsf@gmx.us> (rasmus@gmx.us's message of "Sat, 31 Aug 2013 15:59:38 +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: Rasmus Cc: emacs-orgmode@gnu.org Rasmus writes: > What I do in the patch is that I apply the filters within the > function Why is that? `org-export-data' already takes care of filters. These calls are redundant. > Also, filters using a regexp with "\text{whatever}" wouldn't work. I don't get it. >>> + (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) ""))) >>> + "" "$"))))) >> >> I think this is problematic: if an entity needs to export both the >> previous and the next object, what happens when we have two consecutive >> entities? An infloop? > > I agree, but I haven't been able to cause any nasty behavior. I've > probably neglected some case. These works fine > > 1. \alpha\beta_t : \alpha is not a subscript > 2. \alpha\beta_\xi\nu : runs OK recursively. There's still some infloop smell around this code. Perhaps with something like the following (untested): A_b^c > On 2.: on my system I've tried with many entities (around 500). It > works, but obviously it's slow due to the recursiveness.This is very > nasty. I don't know if some other mechanism can be derived, tho. . . `org-export-data' caches its results, so calling it more than once on the same object/element isn't really costly. > + (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) 0) 0)) aka `zerop' (slightly easier to read). > + (no-pre-blanks-p (= (or (org-element-property :post-blank prev) 0) 0)) Ditto. > + (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) > + ;; check if nil > + (org-export-data prev info)) > + "" "$") > + ent > + (if (and no-post-blanks-p > + (memq (org-element-type next) scripts) > + ;; check if nil > + (org-export-data next info)) You don't need to check for nil. `org-export-data' returns nil when the element or object is ignored. But `org-export-get-previous-element' never returns ignored objects or elements. > + (let ((out (or (org-export-filter-apply-functions > + org-export-filter-subscript-functions > + (org-export-data obj info) > + info) ""))) See above. Thanks again. Regards, -- Nicolas Goaziou