You can use tags to differentiate the sections:
* Section one
This section will be exported always.
* Section two :export_latex:
This section should only be exported with the LaTeX/PDF exporter.
* Section three :export_odt:
This section should only be exported with the ODT exporter.
The trick is to then define the appropriate set of noexport
tags: you basically want to define the equivalent of
#+EXCLUDE_TAGS: export_latex
when you export to ODT and
#+EXCLUDE_TAGS: export_odt
when you export to LaTeX/PDF.
So instead of fiddling around with adding and removing tags, you can add the above tags permanently, add both #+EXCLUDE_TAGS
lines to the file and then comment/uncomment appropriately:
# #+EXCLUDE_TAGS: export_latex
#+EXCLUDE_TAGS: export_odt
for LaTeX/PDF export and
#+EXCLUDE_TAGS: export_latex
# #+EXCLUDE_TAGS: export_odt
for ODT export.
That should work better than your current method but it still involves fiddling every time you export, so the next step would be to do these settings through two different functions exporting to the two different formats. Here's an implementation with the two functions bound to C-<f11>
and C-<f12>
resp. (which only works in GUI Emacs AFAIK, so you should probably decide your own key bindings):
#+OPTIONS: tags:nil
* foo
** Section one
This section will be exported always.
** Section two :export_latex:
This section should only be exported with the LaTeX/PDF exporter.
** Section three :export_odt:
This section should only be exported with the ODT exporter.
* Code :noexport:
#+begin_src emacs-lisp
(defun ndk/org-export-as-latex ()
(interactive)
(let ((org-export-exclude-tags '("export_odt" "noexport")))
(org-open-file (org-latex-export-to-pdf))))
(defun ndk/org-export-as-odt ()
(interactive)
(let ((org-export-exclude-tags '("export_latex" "noexport")))
(org-open-file (org-odt-export-to-odt))))
(define-key org-mode-map (kbd "C-<f11>") #'ndk/org-export-as-odt)
(define-key org-mode-map (kbd "C-<f12>") #'ndk/org-export-as-latex)
#+end_src
With that, you should be able to export in either of the two formats with the press of a key.