How can I export to a single file using several backends for different parts of the org file? Specifically, when exporting an org file with a specific backend, I want to be able to export some specific elements using another backend.

Long description

I want to be able to export org to a specific text file format (let's call it amc), and for this I created a new export backend, derived from ascii, and that works well.

Such amc files can contain latex fragments, enclosed in [latex] and [/latex] tags. So I would like, when exporting to amc, to export some org elements (eg tables) using the latex backend and enclosing the result in amc [latex] tags.

I tried to do that this way:

(defun org-amc-table (table contents info)
  "Transcode table as latex code inside latex AMC-TXT construct"
  (setq info (plist-put info :latex-default-table-environment "tabular"))
  (format "[latex]\n%s[/latex]" (org-latex--org-table table contents info)))

where org-latex--org-table exports an org-table to a latex table. However, the contents of the table itself is exported through the amc backend, not latex. I can force the exporter to use latex export functions for table rows and cells by specifying them in amc backend's translate-alist:

(table . org-amc-table)
(table-row . org-latex-table-row)
(table-cell . org-latex-table-cell)

but the inner content of the cells is still translated by the amc exporter (eg in a cell *bold* is translated to amc's bold, not latex's \textbf{bold}.

How can I "call" the latex backend from the amc backend, for specific elements?

1 Answer 1


Here is how I finally did it. I first define a function org-export-as-latex-string to export any (org text) string to latex:

(defun org-export-as-latex-string (s)
  "Export org string as latex string."
    (insert s)
    (let ((org-export-show-temporary-export-buffer nil)) ;; much faster!
      (with-current-buffer (org-export-to-buffer 'latex "*latex*" nil nil nil t)
    (buffer-substring (point-min) (point-max))))))

Then I define org-amc-table to ignore its args, get the source of the table in the buffer and export it to a latex string with org-export-as-latex-string above.

(defun org-amc-table (table contents info)
  "Transcode table as latex code inside latex AMC-TXT construct"
  (let* ((org (buffer-substring (point-min) (point-max)))
     (info (plist-put info :latex-default-table-environment "tabular"))
     (str (org-export-as-latex-string org)))
    (format "[latex]\n%s[/latex]" str)))

I initially used the :beg and :end properties of the table element to get the buffer positions of the table, but I then realized that's not necessary since the buffer that the function sees only contains the source of the table (maybe narrowing is in effect?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.