EDIT
As mentioned in the comments, the 'original' solution does not exclude the 'HTML/LaTeX' headlines from the HTML TOC.
This can be fixed by filtering the arguments passed to the org-html--toc-text
function via an advice as follows.
(defun org-filter-toc (blabla)
(mapcar (lambda (e)
(seq-filter (lambda (s)
(let* ((positions (nth 1 (object-intervals (car s))))
(title (org-element-property
:title
(get-text-property (car positions) :parent (car s)))))
(not (member (car title) '("HTML" "LaTeX")))))
e))
blabla))
(advice-add 'org-html--toc-text :filter-args #'org-filter-toc)
It now is required that the headlines match the strings in the list passed to member
exactly (upper/lower cases should match).
Unfortunately, due to the 'complex' structure of the data passed to the org-html--toc-text
the filter code becomes quite cumbersome. Also, again, the code probably is not very robust, but if something is not working then it can probably get fixed via a small modification.
There is a significant chance that adding support for conditionally exporting side by side images directly to org would have been easier (it is just harder to find out where to start).
END EDIT
For this particular case, you could use an export filter to filter out the unwanted headlines for a specific backend, and subsequently only return the body of the exported headlines, e.g. as follows:
(defun my-org-exclude-headlines (text backend info)
"Filter out unwanted headlines on export."
;; filter unwanted headlines
(if (string-match-p (pcase backend
('latex "{html}")
('html "latex"))
text)
""
;;filter out headline titles
(let ((lines (string-split text "\n")))
(mapconcat #'identity (pcase backend
('latex (seq-subseq lines 3))
('html (seq-subseq lines 3 -3))
(_ lines))
"\n"))))
(add-to-list 'org-export-filter-headline-functions
'my-org-exclude-headlines)
You could evaluate this manually before export, but the link included above also explains how to define filters for individual files.
The code is quite self-explanatory, and you could wrap the text
in a print statement if you'd like to better understand the chosen 'match patterns'.
If you don't need to filter out the titles of the headlines, then you could as well use the solution provided here.
The code is not very robust (i.e. the filters), but it can be easily improved.
Of course, it would be nicer, if an export backend automatically exported the images using the with the backend 'corresponding' attributes. I guess you could just request such feature using M-x org-submit-bug-report
(you might even receive an answer, including explanation, that it already exists).