From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [export] org-export-with-* bugs Date: Tue, 17 Dec 2013 18:29:40 +0100 Message-ID: <87wqj38jy3.fsf@gmail.com> References: <87d2kxfou8.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42323) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsySZ-0000n4-Q9 for emacs-orgmode@gnu.org; Tue, 17 Dec 2013 12:29:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VsySR-0000sT-A6 for emacs-orgmode@gnu.org; Tue, 17 Dec 2013 12:29:31 -0500 Received: from mail-ea0-x230.google.com ([2a00:1450:4013:c01::230]:44958) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsySQ-0000re-Lo for emacs-orgmode@gnu.org; Tue, 17 Dec 2013 12:29:23 -0500 Received: by mail-ea0-f176.google.com with SMTP id h14so3007674eaj.21 for ; Tue, 17 Dec 2013 09:29:21 -0800 (PST) Received: from selenimh ([91.224.148.150]) by mx.google.com with ESMTPSA id 4sm54872246eed.14.2013.12.17.09.29.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Dec 2013 09:29:19 -0800 (PST) In-Reply-To: <87d2kxfou8.fsf@gmail.com> (Aaron Ecay's message of "Sun, 15 Dec 2013 22:37:35 -0500") 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: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hello, Aaron Ecay writes: > 1) In exporting the following org buffer to latex, I get the following > stack trace (at end of email because of length): > > ===== > #+options: |:nil > > | foo | bar | > ===== The more I look at it, the more I'm inclined to think that it's totally useless. I don't think anyone wants tables removed from Org syntax. Though, occasionally some line starting with "|" can be interpreted as a table. In this case, it's possible to use "\vert" entity anyway. I'm not sure it is worth fixing. I think we really should remove it, or change its meaning, like "|:nil means that all tables are ignored in export process" (which is probably almost as useless). The same goes for "::nil". > 2) When exporting the following buffer to latex: > > ===== > #+options: ^:nil > > foo_{*bar*} > ===== > > I get (ignoring document preamble): > > ===== > foo\_\{$\backslash$textbf\{bar\}\} > ===== > > Note the escaping of the backslash and inner pair of braces. I would > have expected: > > ===== > foo\_\{\textbf{bar}\} > ===== I attach a patch that should solve this (but doesn't handle tables or fixed-width areas). Regards, -- Nicolas Goaziou --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-ox-Fix-export-of-uninterpreted-elements.patch >From f906c641d6dc0dce9314ac952e70f8c8ece93d26 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 16 Dec 2013 22:01:59 +0100 Subject: [PATCH] ox: Fix export of uninterpreted elements * lisp/ox.el (org-export-data): Do not check for uninterpreted elements or objects. These are removed from parse tree anyway. (org-export--remove-uninterpreted): New function. (org-export--interpret-p): Removed function. (org-export-as): Handle uninterpreted elements and objects. --- lisp/ox.el | 107 ++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 40 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index ad6ee04..44f6241 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -2170,10 +2170,8 @@ a tree with a select tag." ;; Internally, three functions handle the filtering of objects and ;; elements during the export. In particular, ;; `org-export-ignore-element' marks an element or object so future -;; parse tree traversals skip it, `org-export--interpret-p' tells which -;; elements or objects should be seen as real Org syntax and -;; `org-export-expand' transforms the others back into their original -;; shape +;; parse tree traversals skip it and `org-export-expand' transforms +;; the others back into their original shape ;; ;; `org-export-transcoder' is an accessor returning appropriate ;; translator function for a given element or object. @@ -2208,16 +2206,6 @@ Return transcoded string." (let ((transcoder (org-export-transcoder data info))) (if transcoder (funcall transcoder data info) data)) info)) - ;; Uninterpreted element/object: change it back to Org - ;; syntax and export again resulting raw string. - ((not (org-export--interpret-p data info)) - (org-export-data - (org-export-expand - data - (mapconcat (lambda (blob) (org-export-data blob info)) - (org-element-contents data) - "")) - info)) ;; Secondary string. ((not type) (mapconcat (lambda (obj) (org-export-data obj info)) data "")) @@ -2315,31 +2303,68 @@ recursively convert DATA using BACKEND translation table." ;; will probably be used on small trees. :exported-data (make-hash-table :test 'eq :size 401))))) -(defun org-export--interpret-p (blob info) - "Non-nil if element or object BLOB should be interpreted during export. -If nil, BLOB will appear as raw Org syntax. Check is done -according to export options INFO, stored as a plist." - (case (org-element-type blob) - ;; ... entities... - (entity (plist-get info :with-entities)) - ;; ... emphasis... - ((bold italic strike-through underline) - (plist-get info :with-emphasize)) - ;; ... fixed-width areas. - (fixed-width (plist-get info :with-fixed-width)) - ;; ... LaTeX environments and fragments... - ((latex-environment latex-fragment) - (let ((with-latex-p (plist-get info :with-latex))) - (and with-latex-p (not (eq with-latex-p 'verbatim))))) - ;; ... sub/superscripts... - ((subscript superscript) - (let ((sub/super-p (plist-get info :with-sub-superscript))) - (if (eq sub/super-p '{}) - (org-element-property :use-brackets-p blob) - sub/super-p))) - ;; ... tables... - (table (plist-get info :with-tables)) - (otherwise t))) +(defun org-export--remove-uninterpreted (data info) + "Change uninterpreted elements back into Org syntax. +DATA is the parse tree. INFO is a plist containing export +options." + (org-element-map data + '(entity bold fixed-width italic latex-environment latex-fragment + strike-through subscript superscript underline) + (lambda (blob) + (let ((type (org-element-type blob)) + new) + (case type + ;; ... entities... + (entity + (unless (plist-get info :with-entities) + (setq new (list (org-export-expand blob nil))))) + ;; ... emphasis... + ((bold italic strike-through underline) + (unless (plist-get info :with-emphasize) + (let ((marker (case type + (bold "*") + (italic "/") + (strike-through "+") + (underline "_")))) + (setq new + (append + (list marker) + (org-element-contents blob) + (list (concat + marker + (make-string + (or (org-element-property :post-blank blob) 0) + ?\s)))))))) + ;; ... fixed-width areas. + (fixed-width + (unless (plist-get info :with-fixed-width) + (setq new (list (org-export-expand blob nil))))) + ;; ... LaTeX environments and fragments... + ((latex-environment latex-fragment) + (let ((with-latex-p (plist-get info :with-latex))) + (when (or (not with-latex-p) (eq with-latex-p 'verbatim)) + (setq new (list (org-export-expand blob nil)))))) + ;; ... sub/superscripts... + ((subscript superscript) + (let ((sub/super-p (plist-get info :with-sub-superscript)) + (bracketp (org-element-property :use-brackets-p blob))) + (unless (if (eq sub/super-p '{}) bracketp sub/super-p) + (setq new + (append + (list (concat (if (eq type 'subscript) "_" "^") + (and bracketp "{"))) + (org-element-contents blob) + (list (concat + (and bracketp "}") + (make-string + (or (org-element-property :post-blank blob) 0) + ?\s))))))))) + (when new + (dolist (e new) (org-element-insert-before e blob)) + (org-element-extract-element blob)))) + info) + ;; Return modified parse tree. + data) (defun org-export-expand (blob contents &optional with-affiliated) "Expand a parsed element or object to its original state. @@ -3086,7 +3111,9 @@ Return code as a string." (setq tree (org-export-filter-apply-functions (plist-get info :filter-parse-tree) - (org-element-parse-buffer nil visible-only) info)) + (org-export--remove-uninterpreted + (org-element-parse-buffer nil visible-only) info) + info)) ;; Now tree is complete, compute its properties and add them ;; to communication channel. (setq info -- 1.8.5.1 --=-=-=--