I wrote a code that clones the current org buffer, performs a transformation of the links (which are org-ref citations) and then exports that temporary buffer. The problem is that the links in the #INCLUDE-ed files are not transformed. I would like to perform expansion of the #+INCLUDE keywords before putting the text into the temporary buffer (without affecting the original buffer, of course). How can I do that?

(The alternative, i.e. performing the transformation during the export of the links would result in several complications, so I do not want to pursue that path unless I must.)

2 Answers 2


You could use the amusingly named function (org-org-export-as-org), which will export to a buffer named *Org ORG Export* with all the #+INCLUDE lines expanded. Then you could do your further processing and export from that buffer.

Full documentation for the function:

org-org-export-as-org is an interactive autoloaded compiled Lisp
function in ‘ox-org.el’.

(org-org-export-as-org &optional ASYNC SUBTREEP VISIBLE-ONLY BODY-ONLY

Export current buffer to an Org buffer.

If narrowing is active in the current buffer, only export its
narrowed part.

If a region is active, export that region.

A non-nil optional argument ASYNC means the process should happen
asynchronously.  The resulting buffer should be accessible
through the ‘org-export-stack’ interface.

When optional argument SUBTREEP is non-nil, export the sub-tree
at point, extracting information from the headline properties

When optional argument VISIBLE-ONLY is non-nil, don’t export
contents of hidden elements.

When optional argument BODY-ONLY is non-nil, strip document
keywords from output.

EXT-PLIST, when provided, is a property list with external
parameters overriding Org default settings, but still inferior to
file-local settings.

Export is done in a buffer named "*Org ORG Export*", which will
be displayed when ‘org-export-show-temporary-export-buffer’ is
  • Unfortunately, export to org does much more than what I need -- things like inserting #TITLE and #AUTHOR and transforming links of the form cite:something to links of the form [[#something][something]]... Jul 27, 2017 at 13:05
  • You could use the BODY-ONLY argument to solve the first problem, and there is probably something you could put in EXT-PLIST to solve the second. But your solution with org-export-expand-include-keyword looks better if you have already gone to the trouble of cloning the buffer.
    – deprecated
    Jul 27, 2017 at 14:05

I am beginning to suspect that, in Emacs, the best way to find out answers is to look though the source code... Looking through the code of org-export-as reveals the answer: org-export-expand-include-keyword.

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.