From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Tweaking the export Date: Sun, 29 Jan 2012 10:07:06 +0100 Message-ID: <87wr8akhc5.fsf@gmail.com> References: <87pqec4xua.fsf@gmail.com> <87obtvk6j0.fsf@gmail.com> <87obtrel2z.fsf@gmail.com> <4F20F779.2060803@gmail.com> <877h0ds39y.fsf@gmail.com> <8162fxjm02.fsf@gmail.com> <4F235BC2.2080903@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:48057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RrQl8-000766-0E for emacs-orgmode@gnu.org; Sun, 29 Jan 2012 04:09:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RrQl6-0003TR-Pw for emacs-orgmode@gnu.org; Sun, 29 Jan 2012 04:09:13 -0500 Received: from mail-ww0-f49.google.com ([74.125.82.49]:57381) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RrQl6-0003TN-Jl for emacs-orgmode@gnu.org; Sun, 29 Jan 2012 04:09:12 -0500 Received: by wgbds1 with SMTP id ds1so2741545wgb.30 for ; Sun, 29 Jan 2012 01:09:11 -0800 (PST) In-Reply-To: <4F235BC2.2080903@gmail.com> (Christian Wittern's message of "Sat, 28 Jan 2012 11:21:54 +0900") 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: Christian Wittern Cc: emacs-orgmode@gnu.org, Jambunathan K Hello, Christian Wittern writes: > Exactly. The reason for wanting to do this is that the above is my > setup for translating, but in some cases the publication will have > only the translation, for such cases, I want to extract just the > translation. This should then produce a new org file, that simple has > either everything before the tab (the original) or everything after > the tab (the translation), while leaving all lines that do not contain > a character as they are. > > I assume this would be an easy task with the new exporter -- but still > a bit at loss on where to start... >From here, I'll assume that: 1. you only split paragraphs (not tables, or lists, and so on); 2. your back-end is called `translator'; 3. you never use tabs in objects (links, latex-fragments). The first step would be to initialize a property that will allow to control the side of the paragraph being exported: #+begin_src emacs-lisp (defconst org-translator-option-alist '((:translator-side nil nil left))) #+end_src Another step will be to create the basis of `translator', that is an Org to Org back-end. 1. For each ELEMENT in `org-element-all-elements', you need to created an appropriate transcoder in the following shape: #+begin_src emacs-lisp (defun org-translator-ELEMENT (element contents info) "Convert ELEMENT from Org to Org syntax." (org-element-ELEMENT-interpreter element contents)) #+end_src This can be done quickly with a macro or some elisp. 2. You should do the same with each OBJECT in `org-element-all-successors': #+begin_src emacs-lisp (defun org-translator-OBJECT (object contents info) "Convert OBJECT from Org to Org syntax." (org-element-OBJECT-interpreter object contents)) #+end_src Though, you will need to duplicate and rename some functions created, as some objects share the same successor. Thus: - `org-translator-sub/superscript' will be split into `org-translator-subscript' and `org-translator-superscript'; - `org-translator-text-markup' will be split into `org-translator-emphasis' and `org-translator-verbatim'; - `org-translator-latex-or-entity' will be split into `org-translator-entity' and `org-translator-latex-fragment'. 3. If all went well, you now have an impressive Org to Org converter. You can even test it with: #+begin_src emacs-lisp (switch-to-buffer (org-export-to-buffer 'translator "*Translation*")) #+end_src Obviously, there is not much to see. Now, we're going to redefine `org-translator-paragraph' to properly ignore one language or the other, depending on `:translator-side' value. #+begin_src emacs-lisp (defun org-translator-paragraph (paragraph contents info) "Convert PARAGRAPH to Org, ignoring one language. Language kept is determined by `:translator-side' value." (let ((leftp (eq (plist-get info :translator-side) 'left))) (replace-regexp-in-string (if leftp "\t+.*$" "^.*\t+") "" contents))) #+end_src Eventually, you need to define two commands to respectively keep left and right parts and save the output in an appropriate file. #+begin_src emacs-lisp (defun org-translator-left (file) "Save buffer in FILE, with only left language in paragraphs." (interactive "FFile (left language): ") (org-export-to-file 'translator file)) (defun org-translator-right (file) "Save buffer in FILE, with only right language in paragraphs." (interactive "FFile (right language): ") (org-export-to-file 'translator file nil nil nil '(:translator-side right))) #+end_src This is completely untested. Regards, -- Nicolas Goaziou