17

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}

costrouc
  • 421
  • 3
  • 8
  • 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 '18 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 '18 at 13:30
  • 2
    Possible duplicate of [Is it possible to export content of subtrees without their headings?](https://emacs.stackexchange.com/questions/9492/is-it-possible-to-export-content-of-subtrees-without-their-headings) – legends2k Nov 20 '19 at 08:38

6 Answers6

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.

arvidj
  • 65
  • 12
EFLS
  • 1,532
  • 10
  • 13
  • You need the `titletoc` package mentioned in the manual at https://orgmode.org/manual/Table-of-contents.html. – serv-inc Nov 21 '18 at 09: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 https://github.com/jwiegley/use-package/issues/597#issuecomment-352898477 and then in `:config` put @elfs answer. – nmu Sep 08 '19 at 09: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 '23 at 15:09
  • This fails for me with error: `Wrong type argument: number-or-marker-p, nil` – shivams Jul 31 '23 at 22:17
12

Add this:

#+EXCLUDE_TAGS: noexport

Then add the tag you specify:

* Fake heading :noexport:
jdtonkin
  • 575
  • 5
  • 14
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
costrouc
  • 421
  • 3
  • 8
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.

yantar92
  • 146
  • 4
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.

  • 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 '19 at 17:10
0

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

Ajned
  • 672
  • 4
  • 19