Вопрос

I'm wondering I if there's any functionality in org-mode that can make me able to operate with secret structure, that is: structure that I can see when I'm editing but that is treated as if it wasn't there when exporting. It's mainly importing when I export to ascii.

Example:

I would like this in the .org file:

* Normal heading
** Secret heading 1
Some text 1
** Secret heading 2
Some text 2
** Secret heading 3
Some text 3

To be exported to this:

Normal heading
--------------
Some text 1
Some text 2
Some text 3

What makes the headings secret can be anything like a tag, a property or something else but the secret headings should be foldable.

Edit:

Found this solution (from here) (I'm using org-mode 7.9.3 f. It doesn't work. Headlines with the :ignoreheading: tag are still displayed:

;; backend aware export preprocess hook
(defun sa-org-export-preprocess-hook ()
  "My backend aware export preprocess hook."
  (save-excursion
    (when (eq org-export-current-backend 'latex)
      ;; ignoreheading tag for bibliographies and appendices
      (let* ((tag "ignoreheading"))
        (org-map-entries (lambda ()
                           (delete-region (point-at-bol) (point-at-eol)))
                         (concat ":" tag ":"))))))

(add-hook 'org-export-preprocess-hook 'sa-org-export-preprocess-hook)
Это было полезно?

Решение 3

I upgraded to org-mode 8.2.5h and with that this works:

(defun sa-ignore-headline (contents backend info)
  "Ignore headlines with tag `ignoreheading'."
  (when (and (org-export-derived-backend-p backend 'latex 'html 'ascii)
          (string-match "\\`.*ignoreheading.*\n"
                (downcase contents)))
    (replace-match "" nil nil contents)))

(add-to-list 'org-export-filter-headline-functions 'sa-ignore-headline)

But only if you don't have the options: #+OPTIONS: tags:nil. Guess it's sort of obvious that tags shouldn't be filtered away before a filtering that relies on a certain tag is invoked - but that bugged me for quite some time.

Note: when exporting to ascii the headline underlining will remain without the headline, so you need this setting too:

(setq org-ascii-underline (quote ((ascii) (latin1) (utf-8))))

... to remove headlines all together.

Другие советы

You can use the EXCLUDE_TAGS property and tag certain sections, then export with org-export-exclude-tags. E.g:

#+EXCLUDE_TAGS: noexport

* Public Section

* Secret Section :noexport:

Documentation here.

What you want is addressed here -- and here's the answer (repeated):

  1. Add the following to your .emacs file:

    (require 'ox-extra)
    (ox-extras-activate '(ignore-headlines))
    
  2. Use the ignore tag on headlines you'd like to have ignored (while not ignoring their content)

In the linked question about the ignoreheading tag I posted a working, simpler org-export-before-parsing-hook solution for Org 8.2.10 in Emacs 24.1.1.

It is based on the documentation of the org-map-entries function which also states that it wraps it in save-recursion automatically. It is simpler than using concat because the second argument to org-map-entries is an agenda-style match string.

While trying to solve the same problem I found this thread describing how to extend ox-extra.el using a notignore tag. This method does not export any headings unless explicitly tagged notignore. Content of the heading are exported normally.

For most of my documents the notignore approach is more useful than the 'ignore' approach because the majority of headings are 'secret structure' not intended for export.

Presently I have notignore-headlines activated in my init.el file. Can anyone suggest a way to activate this on a per document basis.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top