Note: this is building on the solutions to putting images side-by-side in HTML and LaTeX:
orgmode image export side by side to both latex and html
Given the following org-mode document:
#+TITLE: Side-by-Side Test
* Export Configuration :noexport:
#+begin_src emacs-lisp :results output :session :exports both
(defun my-org-backend-config (backend)
"Set specific settings depending on which org-mode backend is used."
(pcase backend
((or 'latex 'beamer)
(setq org-export-with-tags nil)
(setq my-remove-headlines-re (regexp-opt '(":latex:")))
(setq my-remove-sections-re (regexp-opt '(":html:"))))
('html
(setq org-export-with-tags nil)
(setq my-remove-headlines-re (regexp-opt '(":html:")))
(setq my-remove-sections-re (regexp-opt '(":latex:"))))
(_
(setq org-export-with-tags nil)
(setq my-remove-headlines-re "")
(setq my-remove-sections-re (regexp-opt '(":latex:" ":html:")))))
;; Remove sections marked by 'my-remove-sections-re'.
(org-map-entries
(lambda ()
(when (save-excursion (re-search-forward my-remove-sections-re
(line-end-position) :noerror 1))
(delete-region (point) (save-excursion (org-end-of-subtree t t))))))
;; Remove headlines marked by 'my-remove-headlines-re'.
(org-map-entries
(lambda ()
(when (save-excursion (re-search-forward my-remove-headlines-re
(line-end-position) :noerror 1))
(delete-region (point) (line-end-position)))))
)
(add-hook 'org-export-before-processing-hook #'my-org-backend-config)
#+end_src
#+RESULTS:
* Regular Header 1
This is just some regular test content.
#+NAME: a
#+BEGIN_SRC dot :file /tmp/a.png
digraph {
1 -> 2;
2 -> 3;
}
#+END_SRC
#+NAME: b
#+BEGIN_SRC dot :file /tmp/b.png
digraph {
1 -> 3;
2 -> 3;
}
#+END_SRC
* HTML :html:
#+ATTR_HTML: :align center :height 300
[[/tmp/a.png]]
[[/tmp/b.png]]
* LaTeX :latex:
#+BEGIN_CENTER
#+ATTR_LATEX: :height 0.4\textwidth :center
#+RESULTS: a
[[file:/tmp/a.png]]
#+ATTR_LATEX: :height 0.4\textwidth :center
#+RESULTS: b
[[file:/tmp/b.png]]
#+END_CENTER
* Regular Header 2
Testing a regular header, again.
Essentially, I want to strip out the sections marked with :html:
when
exporting to LaTeX
and remove the headlines marked with :latex:
. Vice versa
for HTML-exports.
As written, this works fine for LaTeX, however I cannot remove the whole
:latex:
section when exporting as HTML; the headline is removed, but the
content remains. I assume there's something wrong with the elisp
code, but I
cannot figure out exactly what it is.
(Note that this requires you to C-c C-c
on the export configuration source
block.)
match
argument oforg-map-entries
to select the appropriate headlines:(org-map-entries (lambda () ...) (format tag))
wheretag
is set to eitherlatex
orhtml
. I think that would simplify thelambda
s and it also would allow for easier testing.org-map-entries
's accounting. DoC-h v org-map-continue-from
and read the Mapping API section of the manual.