emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <n.goaziou@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [export] org-export-with-* bugs
Date: Tue, 17 Dec 2013 18:29:40 +0100	[thread overview]
Message-ID: <87wqj38jy3.fsf@gmail.com> (raw)
In-Reply-To: <87d2kxfou8.fsf@gmail.com> (Aaron Ecay's message of "Sun, 15 Dec 2013 22:37:35 -0500")

[-- Attachment #1: Type: text/plain, Size: 1189 bytes --]

Hello,

Aaron Ecay <aaronecay@gmail.com> 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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-Fix-export-of-uninterpreted-elements.patch --]
[-- Type: text/x-diff, Size: 6045 bytes --]

From f906c641d6dc0dce9314ac952e70f8c8ece93d26 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
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


  reply	other threads:[~2013-12-17 17:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-16  3:37 [export] org-export-with-* bugs Aaron Ecay
2013-12-17 17:29 ` Nicolas Goaziou [this message]
2013-12-17 19:36   ` Rasmus
2013-12-18  5:24   ` Aaron Ecay
2013-12-18 13:31     ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wqj38jy3.fsf@gmail.com \
    --to=n.goaziou@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).