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:

2

2 Answers 2

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.

1
  • 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... Mar 24, 2023 at 3: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)

Your Answer

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

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