Ihor Radchenko <[email protected]> writes:
> Mathew Moore <[email protected]> writes:
(...)
> Use special block.
(...)
> #+header: :wrap (by-backend ('latex "figure") (_ nil))
(...)

Mathew's problem -- and the problem with the Worg trick -- is that,
while this works in LaTeX, it turns off captioning in HTML. I suppose
this is because even =:wrap 'nil= or an empty =:wrap= causes the results
to be wrapped in a =#+BEGIN_RESULTS= block.

One solution I can think of is to use an export hook to get rid of the
#+BEGIN_RESULTS bit (I include a rough attempt below). But this adds yet
another level of ad-hockery to what is already a complicated trick. Not
sure if it's better or worse than Mathew's solution of advising
org-babel-insert-result.

But perhaps Org should let :wrap take an value (e.g. 'none or 'nowrap)
that results in no wrapping? Yes, I know, 99% of the time, the way not
to wrap stuff is just to not write =:wrap= in the first place. But a
nowrap option would solve a couple of corner cases. One is Mathew's
problem (captions in backend-dependent TikZ export with Andreas Leha's
trick on Worg), which could then be solved by

  #+header: :wrap (by-backend ('latex "figure") (_ 'nowrap))

Another use case that I can think of is if you want to set :wrap for
most src blocks with a file-level babel header, but want to make an
exception for an individual src block.

Regards,
Christian

PS. A rough export-hook solution:

#+begin_src elisp
  (defun my-remove-results-wrap (backend)
    "Remove 'results' special blocks in non-latex export.
  BACKEND is the export backend being used, as a symbol."
    (unless (eq backend 'latex)
      (goto-char (point-min))
      (let ((case-fold-search t))
        (while (re-search-forward "#\\+\\(begin\\|end\\)_results" nil t)
        (beginning-of-line)
        (kill-line)
        (kill-line)))))

  (add-hook 'org-export-before-parsing-functions #'my-remove-results-wrap)
#+end_src

Reply via email to