4

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}

  • 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
4

For others who stumble upon this question, the following is available (as hinted to by yantar92, this is included in ox-extra):

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:

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

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

3

Add this:

#+EXCLUDE_TAGS: noexport

Then add the tag you specify:

* Fake heading :noexport:
  • 2
    This has the effect of commenting out the entire section under the :noexport:-tagged heading. – hoosierEE Oct 28 '18 at 14:25
1

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
  • That's terrible. And by terrible I mean I'm going to use it right now. – hoosierEE Oct 28 '18 at 14:22
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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