Thanks for the tip.

Today what I tried for this worked fine. This will export an org file to
an org file, but transform all the cite type links into pandoc format,
including pre/post text if you put that in the link description with ::
as a separator. Then you could run that org file through pandoc. It
looks like this would work for any export that can use pandoc citations,
with a simple redefinition of the derived backend.

#+BEGIN_SRC emacs-lisp
(defun pandoc-cite-format (link contents info)
  (if (-contains? org-ref-cite-types  (org-element-property :type link))
      (cond
       ;; link with description
       ((org-element-property :contents-begin link)
        (let* ((contents (buffer-substring
                          (org-element-property :contents-begin link)
                          (org-element-property :contents-end link)))
               (split (split-string contents "::"))
               (pre-text (nth 0 split))
               (post-text (nth 1 split)))
          (concat
           "[@" (org-element-property :path link)
           (when pre-text (concat ", " pre-text))
           (when post-text (concat ", " post-text))
           "]"
           )
          ))
       ;; plain citations
       (t
        (concat "["
              (mapconcat (lambda (key) (concat "@" key))
                         (split-string (org-element-property :path link) ",")
                         "; ")
              "]")))
    ;; not a cite link. just return the original link
    (org-org-identity link contents info)))

(org-export-define-derived-backend 'pandoc-org 'org
  :translate-alist '((link . pandoc-cite-format)))

(find-file (org-export-to-file 'pandoc-org "org-to-org.org"))
#+END_SRC


Nick Dokos writes:

> John Kitchin <johnrkitc...@gmail.com> writes:
>
>> All the discussion about citations has gotten me thinking. It is easy
>> enough to export cite links to the pandoc format, including pre and post
>> text. I have done a proof of concept of this in a markdown export.
>>
>> I would like to do an org export to org, with the goal of the exported
>> org document to no longer have cite:KEY1,KEY2 but rather [@KEY1; @KEY2]. So 
>> far my
>> investigations of exporting org to org have not led anywhere; the links are
>> untouched, even with an org format option in the link definition.
>>
>> Are links ignored in an org export to org? If not, is there some trick
>> to converting them to another format?
>>
>
> ox-org.el defines the org backend with  (link . org-org-identity) -
> actually just about everything is tied to org-org-identity (with a few
> exceptions of course). Maybe you can derive a backend which munges links
> appropriately (for some value of "appropriately")?

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

Reply via email to