emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Tweaking the export


From: Nicolas Goaziou
Subject: Re: [O] Tweaking the export
Date: Sun, 29 Jan 2012 10:07:06 +0100

Hello,

Christian Wittern <address@hidden> 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 <tab> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]