I'm currently exporting a document to latex and HTML and there is some content that I have to create separately for each target. For the latex target, I add the latex code as

#+begin_export latex
// latex code

which is not included in HTML export.

However, for the HTML export, I'd like to add the content as org-mode syntax and have org-mode parse it as usual. Therefore, using #+begin_export html is not an option. Obviously, the parsed content should be included only in HTML export.

I have found this question that use drawers to selective export and the drawer content is parsed by org-mode according to the export target. However, it is necessary to manually specify which drawer should (not) be exported.

The reason I need this is because I want to include two figures side-by-side and I'm using org-ref for labels and references. I can directly include the latex code using the subfigure environment in a #+begin_export latex block and everyhting works in latex export (referencing as well as numbering).

In HTML export it's OK for the figures to be one below the other (although side-by-side would also be nice). If I directly add the HTML code in a #+begin_export html like the solution for the latex export, then the caption will not include the figure numbering, since org/org-ref doesn't touch it.

Current Solution

My current solution is to use a src block to return the org-mode code for the figures, which it the content I only want to be included in HTML export. The reason is that with an src block I can add :exports and pass lisp code that checks the value of org-export-current-backend. In the case of HTML export the lisp code results in :exports results, while in other backends it results in :exports none.

#+begin_src python :exports (if (org-export-derived-backend-p org-export-current-backend 'html) "results" "none") :results raw
  content = """
  ,#+NAME: fig1_label
  ,#+CAPTION: Fig1 caption.
  ,#+ATTR_HTML: :width 500 :height 500

  ,#+NAME: fig2_label
  ,#+CAPTION: Fig2 caption.
  ,#+ATTR_HTML: :width 500 :height 500
  return content

It works, but it is a bit cumbersome. It would be great if that was a flag I could pass to a #+begin_export html block to specify that it has org-mode markup and the content should be transformed with the regular html export. Even better if I could get actual subfigures working in HTML export (with a single org-mode code for both latex and html export).


Your Answer

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

Browse other questions tagged or ask your own question.