9
votes

When using Org-mode to create beamer presentation it is possible to set the property of a heading such that the exported heading is not shown but only its contents. For instance, the following

#+title: Test

#+options: toc:nil
#+latex_class: beamer
#+startup: beamer

#+BEAMER_FRAME_LEVEL: 2

* Ignored heading                                           :B_ignoreheading:
:PROPERTIES:
:BEAMER_env: ignoreheading
:END:
Text

Result in a frame with "Text" only and no heading. Is this kind of functionality available for non-beamer documents? That is, is it possible to tell Org-mode to not export a heading but only its contents? For instance, would it be possible to make Org-mode export the following

#+title: Test

* Ignored heading
Text

without exporting the heading "Ignored heading" but only "Text"?

If I export

#+title: Test

* 
Text

(note the space after *) to LaTeX I get the following (I only included the relevant part):

\section{}

Text

But this is not what I want. I want the heading to be completely ignored in the export so that I would get the following (again I only include the relevant part):

Text
3
It's not an answer to what you want, but you should be able to just use a heading asterisk and a blank space so that the there is no title to the heading, like * . I'm not sure of a way to get it to export and ignore the heading with default options. It will probably take some lisp hacking. - cm2
@cm2 Note that I want the heading to be completely ignored, e.g. I do not want the LaTeX export to contain a blank heading such as \section{} (which the * method results in). - N.N.
Ah, I see. I suggest editing the question by including the type of LaTeX output you would like to see. - cm2
you should be able to do this using the ox-extra.el contrib package -- this is discussed here in the "Ignoring headlines during export" section. - Mark

3 Answers

9
votes

There is no default support for what you are asking. However you can use a preprocess hook to get a similar output. Here is an example for LaTeX export:

;; 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)

This is a snippet from my org-mode setup. You can see the original on github. The above code will ignore headings tagged with ignoreheading, e.g.

* Heading 1
* Heading 2                           :ignoreheading:
+ Some text
+ an item

gets exported as:

\section{Heading 1}
\label{sec-1}

\begin{itemize}
\item Some text
\item an item
\end{itemize}

Caveat: There is a known issue with this solution. It does not work when you try this on the very first headline. I don't understand why that is the case, hopefully I'll have time someday to investigate.

Workaround to caveat: The above limitation can be circumvented for LaTeX export by using a line like this after the org file header:

\include{preamble.tex}

The preamble.tex file can include sections like an abstract or acknowledgements. However you should note this makes your org file very closely tied to the export backend. It would become non-trivial to export the same org file to HTML for example.

Note: For a similar setup with the new export framework (Org 8.0 or higher), use the following:

(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)
4
votes

Now you can do this easily with ox-extra. Add the following to your init file:

(require 'ox-extra)
(ox-extras-activate '(ignore-headlines))

Then any headings with ignore tag will be ignored, while their content will still be exported.

3
votes

I found a simple solution for Emacs 24.4.1 and Org-mode 8.2.10 on Debian Jessie that removes tagged headlines before processing, so it removes their structure nodes too, not only the text.

;; ignore_heading tag in Org mode, based on the manual and func docs
(defun ignored-headlines-removal (backend)
  "Remove all headlines with tag ignore_heading in the current buffer.
     BACKEND is the export back-end being used, as a symbol."
  (org-map-entries
   (lambda () (delete-region (point) (progn (forward-line) (point))))
   "ignore_heading"))

(add-hook 'org-export-before-parsing-hook 'ignored-headlines-removal)

I didn't make it export backend specific as it does not need to be. I also used the ignore_heading tag to make sure the ignoreheading tag in beamer export retains its function.

Here is how I discovered it:

  1. I looked at the hook documentation in the Advanced confuguration section in the Org manual. It contains a hook example that ignores all headlines, almost what I needed, but I had to find a way to delete only headlines with the ignore_heading tag.
  2. I had a look at the documentation of the org-map-entries function (by typing C-h f org-map-entries RET in Emacs) and found out its optional second argument MATCH is an agenda-style match string that can match tags too.

This experience once again showed me that Emacs truly is an extensible self-documenting editor. RTFM FTW!