8

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.

Brian Z
  • 2,863
  • 16
  • 22
  • This is kind of the reverse of a similar question that I asked: http://emacs.stackexchange.com/questions/9492/is-it-possible-to-export-content-of-subtrees-without-their-headings I imagine a very similar answer would also work here, but my elisp skills are close to `nil`. – Brian Z Mar 20 '15 at 13:54

1 Answers1

3

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 () 
                     (forward-line)
                     (let ((beg (point)))
                       (outline-next-visible-heading 1)
                       (backward-char)
                       (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
itsjeyd
  • 14,586
  • 3
  • 58
  • 87
  • This is a problem for LaTeX which doesn't like empty sections and subsections (http://tex.stackexchange.com/questions/234321/how-to-export-a-document-as-an-empty-skeleton-with-no-content/), 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 08: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 09: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