With
#+CAPTION: my-caption
[[file:image.png]]
I get a caption (with a number) both in LaTeX and in HTML. The same with tables and src blocks (which become listings in LaTeX)
But with a theorem, definition, ... and all other mathematical environments I cannot get a title and a number.
#+ATTR_LATEX: :options [my-theorem]
#+BEGIN_theorem
....
#+END_theorem
works for LaTeX, but in HTML I don't get the caption (and most importantly the number).
This instead breaks also LaTeX because inserts a \caption
macro inside the environment:
#+CAPTION: my-theorem
#+BEGIN_theorem
....
#+END_theorem
How can I create a new special block which takes care of numbering also for HTML (like for figures, tables and listings)?
For the caption the solution is very simple:
#+ATTR_LATEX: :options [my-theorem]
#+BEGIN_theorem
@@html:<span class="theorem-title">my-theorem</span>@@
....
#+END_theorem
so the difficult part is taking care of the numbering.
UPDATE
With org-special-block-extras I achieved this:
(defvar special-block-definition-counter 0)
(defblock definition (title nil) (label nil unnumbered nil)
"Definition special block."
(unless unnumbered (cl-incf special-block-definition-counter))
(format
(cond
((org-export-derived-backend-p org-export-current-backend 'latex)
(concat "\\begin{definition" (when unnumbered "*") "}{%s}{%s}\n"
"%s"
"\\end{definition" (when unnumbered "*") "}"))
((org-export-derived-backend-p org-export-current-backend 'html)
(concat "<p class=\"admonition-title definition\">Definizione" (unless unnumbered (format " %d" special-block-definition-counter)) (when title ": ") "%s</p>"
"<div id=\"%s\" class=\"special-block definition\">%s</div>")))
(or title "") (or label "") contents))
and
#+BEGIN_definition Definition title :label def:example
....
#+END_definition
To export correctly for ePub a patch is needed (for more info: https://github.com/alhassy/org-special-block-extras/issues/12):
(add-to-list 'org-export-filter-parse-tree-functions
(lambda (tree backend info)
(when (eq backend 'epub)
(org-element-map tree 'export-block
(lambda (el)
(when (string= (org-element-property :type el) "EPUB")
(org-element-put-property el :type "HTML")))))
tree))
Now I have only to manage the internal links (label/reference).
theorem
block). But I don't know enough about HTML/CSS to say definitively that you have to do it this way: it might be possible to do something outside of the exporter. If you do decide to go with a derived exporter, examples can be found in the Org mode sources. See Appendix A.4 of the manual (C-h i g(org)adding export TAB
will get you there) and the doc on Worg that ...