From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [patch, ox-latex] captions and latex-environments Date: Sat, 18 Mar 2017 10:44:39 +0100 Message-ID: <87a88kdtvz.fsf@nicolasgoaziou.fr> References: <87k27pv38z.fsf@gmx.us> <87bmt1v2xs.fsf@gmx.us> <87tw6se5a3.fsf@nicolasgoaziou.fr> <874lystfyh.fsf@gmx.us> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37401) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpAuh-0002dZ-Ev for emacs-orgmode@gnu.org; Sat, 18 Mar 2017 05:44:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cpAug-0004sh-GV for emacs-orgmode@gnu.org; Sat, 18 Mar 2017 05:44:43 -0400 Received: from relay4-d.mail.gandi.net ([2001:4b98:c:538::196]:60506) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cpAug-0004sT-A7 for emacs-orgmode@gnu.org; Sat, 18 Mar 2017 05:44:42 -0400 In-Reply-To: <874lystfyh.fsf@gmx.us> (rasmus@gmx.us's message of "Fri, 17 Mar 2017 10:23:02 +0100") 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" To: Rasmus Cc: emacs-orgmode@gnu.org Hello, Rasmus writes: >> Since environments do not necessary start with \begin{...}, I think the >> following is better >> >> (and (string-match ...) >> (match-string ...)) > > Don't the element `latex-environment' always start \begin{.}? > Cf. org-element--latex-begin-environment. At the moment, they do, but I have a patch somewhere to make "\[...\]" an element instead of an object (e.g., to avoid filling it). It was accepted, but it some similar change could happen. I'm just suggesting to make it more robust right from the start. > Another danger is that someone writes something like, > > \begin{center} > \begin{table} > ... You can start the regexp with "\\`[ \t]*..." > Longtable in an omission, but would have been matched. For some reason > I thought tabu was no longer supported. Browsing the tabu CTAN page > there=E2=80=99s links to all sorts of exotic table packages, like "stabul= ar", > "bigtabular", and "supertabular". I wonder if it=E2=80=99s enough to matc= h the > ones supported by Org by default, or whether it would be better to > have it as a defvar that could be hacked if necessary? tabu/longtabu are supported by Org by default. We could make the list a defconst anyway. > I have attached the patch with the changes again and added a changelog > entry. I am not sure this needs to be documented, but I=E2=80=99m happy = to > include a couple lines somewhere. I think the entry in ORG-NEWS is enough. > +(defun org-latex--environment-type (latex-environment) > + "Return the TYPE of LATEX-ENVIRONMENT. > + > +The TYPE is determined from the actual latex environment, and > +could be a member of `org-latex-caption-above' or `math'." > + (let* ((value (org-remove-indentation > + (org-element-property :value latex-environment))) > + (env (or (and (string-match "\\\\begin{\\([A-Za-z0-9*]+\\)}" value) > + (match-string 1 value)) ""))) For clarity, "" should be indented at the same level as (and ...). > + (cond > + ((string-match-p org-latex-math-environments-re value) 'math) > + ((string-match-p > + (regexp-opt '("table" "longtable" "tabular" "tabu" "longtabu")) e= nv) Nitpick: you could wrap the above into `eval-when-compile' for a small optimization. > + 'table) > + ((string-match-p "figure" env) 'image) > + ((or (string-match-p "\\(\\(lst\\)?listing\\|verbatim\\|minted\\)" = env) > + (string-match-p > + (regexp-opt > + (mapcar (lambda (str) > + (let ((s (cadr str))) > + (if (string-match latex-begin-re s) You removed `latex-begin-re' binding so this is going to fail. > + (match-string 2 s) > + s))) > + org-latex-custom-lang-environments)) I'm not sure it is necessary. AFAIU, `org-latex-custom-lang-environments' already provides a way to insert captions. The matching process above seems fragile. Thank you. Regards, --=20 Nicolas Goaziou