18

I have a problem where I want to structure my document visually with a heading but do not want it to actually execute a \section{Fake Heading} for the latex export. I imagine this would be customizable through an org mode property that I am unaware of.

 * Normal Heading
 ** Subheading 1
    baz
 * Fake Heading
   :PROPERTIES:
   :UNKNOWN_PROPERTY_NAME: t
   :END:
 ** Appendix A
    foo
 ** Appendix B
    bar

Desired result.

 \section{Normal Heading}
 \subsection{Subheading 1}
 baz

 \subsection{Appendix A}
 foo
 \subsection{Appendix B}
 bar

Bonus: it would be nice that it would only ignore the fake heading for latex export. The reason I need the fake heading in the first place is that there is a custom command in the latex \documentclass{...} I am using that generates an appendix \makeAppendix thus it is redundant to have a \section{Appendix}

3
  • There is a simple method that achieves something similar but not exactly what you want. If you select the region from Appendix A to the end of your example text Appendix A and B are exported as first-level headers. Don't know whether that bothers you. I know that this is not an answer, therefore I write this only as a comment.
    – Tobias
    Jan 19, 2018 at 11:07
  • Sadly that does not work for me because my document is much more complex than what have shown before. I have added to the question to show why that wouldn't work for me. Along that idea I think that using org sparse trees would be a possible workaround and then export.
    – costrouc
    Jan 19, 2018 at 13:30
  • 2

6 Answers 6

20

For others who stumble upon this question, the following is available. As hinted to by yantar92, this is included in ox-extra which is included in the org-plus-contrib elpa package.

Headers can take an :ignore: tag, which excludes the heading upon export while still including its contents.

To make it work, add the following to your emacs setup (having installed org-plus-contrib as described here):

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

How to make this only affect LaTeX export, I don't know.

4
  • You need the titletoc package mentioned in the manual at orgmode.org/manual/Table-of-contents.html.
    – serv-inc
    Nov 21, 2018 at 9:08
  • Just to add to this, you need to have the org mode repo added to your package lists for this to work. ox-extra is not included by default. If you're using use-package you basically do what this github issue says github.com/jwiegley/use-package/issues/… and then in :config put @elfs answer.
    – nmu
    Sep 8, 2019 at 9:18
  • 2
    org-plus-contrib is now outdated, use org-contrib instead: (use-package org-contrib :config (require 'ox-extra)(ox-extras-activate '(ignore-headlines)))
    – crocefisso
    Feb 12 at 15:09
  • This fails for me with error: Wrong type argument: number-or-marker-p, nil
    – shivams
    Jul 31 at 22:17
12

Add this:

#+EXCLUDE_TAGS: noexport

Then add the tag you specify:

* Fake heading :noexport:
4
  • 6
    This has the effect of commenting out the entire section under the :noexport:-tagged heading. Oct 28, 2018 at 14:25
  • 1
    @AlexShroyer indeed, but I also landed on this question wanting exactly that ;)
    – xeruf
    Nov 21, 2020 at 20:32
  • 1
    One person's bug is another person's feature! Nov 22, 2020 at 15:18
  • 2
    Note: I did not need to add an explicit #+EXCLUDE_TAGS. :noexport: seems to work by default. Dec 30, 2020 at 21:57
4

I have found a workaround that satisfies all my needs. It takes advantage of how org mode exports and that in latex you can have "multiline comments" or sections that it ignores https://tex.stackexchange.com/questions/87303/multi-line-block-comments-in-latex.

So I did the following and it works for me. Note that when exporting to other document formats (odt, html, markdown) it exports normally which is what I want.

#+BEGIN_EXPORT latex
\iffalse % multiline comment
#+END_EXPORT

* Fake Heading

#+BEGIN_EXPORT latex
\fi
#+END_EXPORT

** Appendix A
   foo
** Appendix B
   bar

This results in the following latex code with comments out the latex section command.

 \iffalse
 \section{Fake Heading}
 \fi
 \subsection{Appendix A}
 foo
 \subsection{Appendix B}
 bar
1
  • 4
    That's terrible. And by terrible I mean I'm going to use it right now. Oct 28, 2018 at 14:22
4

You can use org export filters for this purpose:

(defun yant/org-export-suppress-some-sections (data backend channel)
  "Do not put \\section for headlines with :NOSECEXPORT: tag."
 (when (eq backend 'latex)
  (let* ((parent (get-text-property (- (string-match "$" data) 2) :parent data))
     (headline (and parent (cadr parent)))
         (tags (and headline (plist-get headline :tags))))
    (when (member "NOSECEXPORT" tags)
      (replace-regexp-in-string "\\`.*$" "" data)))))

(add-to-list 'org-export-filter-headline-functions 'yant/org-export-suppress-some-sections)

EDIT: Just found that ox-extra from org-plus-contrib provides the similar functionality. My solution seems to fit your question better though.

0

You can retain folding by avoiding using a section at all and instead use a drawer. The contents of the drawer will still be exported but the drawer name will not.

1
  • If the content is after a section heading, org will assume that the drawer is part of that subtree, which may be unwanted.
    – T. Verron
    Oct 22, 2019 at 17:10
0

Why not to simply comment out the fake heading? https://orgmode.org/manual/Comment-Lines.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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