2

I'm exporting org files to PDF. In some cases, I would like to include a heading without any of its children or contents.

There are currently two ways of hiding (part of) a headline. One is to use :ARCHIVE:, which behaves exactly as I want for the purposes of export, but also makes the tree archived in sparse trees, searches, etc. The second is to use :noexport: or exclude_tags, but this hides the entry completely.

Is it possible to customize which tags behave like :ARCHIVE: for the purposes of export only, maybe with a variable?

If not, would something like modifying this solution [1] work. I can see that I wouldn't need arch:t, and the lambda function would be different, but I'm not familiar enough with org-mode's API to know which function to use instead. How would I have to modify it?

[1] How to export headlines, including subheadings, without other contents in org-mode?

Ivan Perez
  • 400
  • 2
  • 15

1 Answers1

4

You can try the following orgmode export filter to remove the content of headlines with the tag :exportHeadlineOnly:.

If you would like to test the code copy it to the *scratch* buffer and run M-x eval-buffer.

If it is working for you copy it to your init file and restart emacs.

(require 'ox)
(defun org+-export-header-only (tree _back-end _channel)
  "Remove the content of headlines with the :exportHeadlineOnly: tag in TREE.
This function can be used in `org-export-filter-parse-tree-functions'."
  ;; We modify the tree by side-effect and ignore the return value.
  (org-element-map
      tree
      'headline
    (lambda (el)
      (when (assoc-string 'exportHeadlineOnly (org-element-property :tags el))
        (org-element-set-contents el nil)
        )))
  tree)

(add-to-list 'org-export-filter-parse-tree-functions #'org+-export-header-only)

BUGFIX 2018-07-07,13:47: Manipulate the tree by side-effect and ignore the return-value of org-element-map. That avoids spurious heading copies through element contents and map-recursion.

Tobias
  • 32,569
  • 1
  • 34
  • 75
  • Great! Another question, which I can open separately: is it possible to make it so that a headline's children are not shown in the TOC, but its contents and the children are included in the document? Or, alternatively, to make a subtree have a different `H:` headline depth in the TOC from another subtree's? – Ivan Perez Jul 10 '18 at 08:48
  • @IvanPerez Yes, that is a separate question. By creating a new question you get higher attention. Maybe someone knows a simple solution. Almost everything is doable via the [org element api](https://orgmode.org/worg/dev/org-element-api.html) but org also has a lot regexp based functions that sometimes are faster and simpler. – Tobias Jul 10 '18 at 11:02