0

In org-mode, I can exclude a code blocks from HTML export with something like this:

#+header: :eval (eval (if (string= org-export-current-backend "html") "no" "yes")))
#+begin_src R
  1+1
#+end_src

How can I achieve the same for a heading and its contents? Something like a conditional noexport tag. I have tried to use similar elisp code in the PROPERTY drawer but this and several variations did not work:

* Section
:PROPERTIES:
:EXPORT: (eval (if (string= org-export-current-backend "html") "no" "yes")))
:END:

I have also tried to set a TAGS property to noexport or :noexport:

tinlyx
  • 1,276
  • 1
  • 12
  • 27
Stefano
  • 131
  • 7
  • 1
    The (original) answer [here](https://emacs.stackexchange.com/a/75510/26163) might help you on your way... – dalanicolai Mar 23 '23 at 22:01
  • Thanks, following that link led me here: https://kitchingroup.cheme.cmu.edu/blog/2013/12/08/Selectively-exporting-headlines-in-org-mode/ and based on that I got my answer. – Stefano Mar 23 '23 at 23:01

2 Answers2

2

I found an answer based on dalanicolai's comment, which led me here. I tag the headings that I don't want to export to, say, latex with noexport_latex and I also define this hook to add to org-export-before-parsing-hook:

(defun exclude-from-latex-export-hook (backend)
  (setq org-export-exclude-tags (remove "noexport_latex" org-export-exclude-tags))
  (if (string= backend "latex")
  (push "noexport_latex" org-export-exclude-tags)))

This uses the standard selective export mechanism but modifies the list of excluded tags on the fly depending on the export backend.

Stefano
  • 131
  • 7
  • 1
    Ah great, I guess you peeked at @NickD's answer then also. I did not have much time to look into it, but I remembered that question/answer was very much related. Nice that it 'worked out well'! And thanks for sharing the solution, of course... – dalanicolai Mar 24 '23 at 03:12
1

Thanks! I did something similar for including/excluding sections in slides when using Org-Reveal. I thought it could be useful if I include my variant as an answer.

I put this in my .emacs for the effect that sections tagged :noslide: are not included in the Reveal.js presentation, while sections tagged :slide: are included only in the presentation (and not when the document is exported to HTML or LaTeX or whatever).

(defun exclude-slide-or-noslide (backend)
  (setq org-export-exclude-tags
        (cons (if (eq backend 'reveal) "noslide" "slide")
              (seq-remove (lambda (tag) (string-suffix-p "slide" tag)) org-export-exclude-tags))))

(add-hook 'org-export-before-parsing-functions #'exclude-slide-or-noslide)
njlarsson
  • 111
  • 4