Created: April 2, 2023

Last modified: April 2, 2023

Exploring ox-org (aka org-org-publish-to-org)

I was exploring ox-org.el that defines the org export backend. This is a somewhat funny backend as it’s simply supposed to export an org file to another org file. Why not just copy the file? Well it behaves as any other export backend, operating at the level of the org AST which is read and manipulated using the org-element api. Thus, this backend lets you run babel code blocks and won’t export things marked as :noexport or which are only expected to be exported for a different backend. Furthermore, it can somewhat “normalize” your org document, ensuring what gets exported has consistent casing of keywords and whitespace between org elements.

In my case, I actually only wanted to hide subtrees marked as :no-export, which requires disabling org-export-use-babel, but I didn’t want to disable this for the other backends. Furthermore I wanted to keep around all export blocks. This turned out to be pretty easy by defining a derived backend.

(org-export-define-derived-backend 'my-org 'org
  :translate-alist '((export-block . org-org-identity)))

(defun my-org-org-publish-to-org (plist filename pub-dir)
  (let ((org-export-use-babel nil))
    (org-publish-org-to 'my-org filename ".org" plist pub-dir)))

(setq org-publish-project-alist
      `(
        ("org"
         :base-directory ,my-org-dir
         :publishing-directory ,my-org-publish-dir
         :publishing-function my-org-org-publish-to-org
         ;:cite-export nil
         :with-author nil
         :with-properties t
         :recursive t)
        ))

(org-publish "org" t)

However, I stopped once I realized that native org citations were also being processed so in order to preserve those, I would need to also figure out how to implement an “identity” org cite processor. Since all I wanted to do was hide some subtrees from appearing in a public facing git repo of my org files, I decided I could just move that content into a separate file and link appropriately.