In the org-mode documentation regarding export settings, it describes arch as follows.

Configure export of archived trees. Can be set to headline to only process the headline, skipping its contents (org-export-with-archived-trees).

That's almost what I want, but it skips all the contents, including the subheadings. I want those subheadings too (without their contents). Take this example:

#+OPTIONS: arch:headline

* I want to see this :ARCHIVE:
But not this.
** and also this.
And definitely not this.

If I export this file, I want to see this is the only thing that comes through. But I was expecting/hoping and also this to be exported underneath it as well.

How do I make that happen? I tried adding an extra :ARCHIVE: tag to the second level heading, but that does nothing.


You're right, the code that I posted over there can be modified to achieve the behavior you want:

(defun org-remove-contents (backend)
  "Remove contents of headlines with :ARCHIVE: tag."
  (org-map-entries (lambda () 
                     (let ((beg (point)))
                       (outline-next-visible-heading 1)
                       (delete-region beg (point))))
                   "ARCHIVE" tree))

(add-hook 'org-export-before-processing-hook #'org-remove-contents)

Note that you'll need to set arch to t in your per-file #+OPTIONS for this to work:

#+OPTIONS: arch:t
  • This is a problem for LaTeX which doesn't like empty sections and subsections (tex.stackexchange.com/questions/234321/…), but I can work around it. Thanks!
    – Brian Z
    Mar 21 '15 at 16:30
  • @BrianZ Huh. LaTeX export works without a hitch on my machine (with #+OPTIONS: arch:t and both headlines tagged with :ARCHIVE:)...
    – itsjeyd
    Mar 22 '15 at 8:21
  • Try it with something bigger, so that the output is more than one page. If you export that to a PDF via LaTeX, does it still work for you?
    – Brian Z
    Mar 22 '15 at 9:02
  • I got 'org-remove-contents: Symbol’s value as variable is void: tree'. How I can fix this?
    – slk500
    Apr 17 '19 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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