chasberry / orgmode-accessories

Add ons for orgmode
78 stars 18 forks source link

export citations to rmarkdown-style citations #3

Closed jorainer closed 9 years ago

jorainer commented 9 years ago

dear develers! would it be possible to export citations (i.e. \cite...) to rmarkdown formatted citations (see http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html)? basically, that would just mean, if an org mode file is exported to Rmd with rmarkdown formatting a \cite{blabla} is rewritten into [@blabla].

cheers, jo

chasberry commented 9 years ago

The export to Rmd uses the md exporter as its parent. So any solution that produces the citation format you want in md should suffice. There are various intiatives among Org mode users/developers to improve citation handling, so there might soon be a seamless solution. Keep an eye on the Org mode help list for developments.


For now, I'd go with an export filter, see

http://orgmode.org/manual/Advanced-configuration.html http://orgmode.org/worg/exporters/filter-markup.html

\cite{blahblah} is a latex fragment, so a latex-fragment filter function should handle it.

Something like this filter ought to handle your case:

    (defun ox-md-filter-latex-fragment
        (text back-end info)
      (if (org-export-derived-backend-p
           back-end 'md)
          (replace-regexp-in-string
                 "\\\\cite{\\([^}]*\\)}"
                 "[@\\1]" text)))

    (eval-after-load 'ox-md
      '(add-to-list 'org-export-filter-latex-fragment-functions
                   'ox-md-filter-latex-fragment))

Put that code in your init file and give it a try.

Chuck

jorainer commented 9 years ago

I'll give that a try! thanks!