Ihor Radchenko <[email protected]> writes:
> Christian Moe <[email protected]> writes:
>
>>> #+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.
>
> That sounds like a bug that can be easily fixed.
It does, but the behavior for the empty :wrap is intentional.
It's documented in the manual:
If no string is specified, Org wraps the results in a
‘#+BEGIN_results’ ... ‘#+END_results’ block.
Probably it's meant as a fallback so that you can just add =:wrap= and
get a special block without needing to specify a special-block name.
`org-babel-insert-result' wraps results in a special block if `info',
the return value of `org-babel-get-src-block-info', has an alist item
with the key :wrap. The special-block type is taken from the cdr of the
item, or is "results" when the cdr is nil. This works out as follows:
| header arg | info | results |
|------------------------+---------------+-----------------|
| =:wrap <empty string>= | (:wrap) | #+begin_results |
| =:wrap 'nil= | (:wrap) | #+begin_results |
| =:wrap nil= | (:wrap "nil") | #+begin_nil |
I suppose the easiest way to go would be to change
`org-babel-insert-result' to do no wrapping if the cdr is the string
"nil" or "no". Then, to get captions in both latex and html with the Worg
by-backend example, we could use the string instead of nil:
#+header: :wrap (by-backend ('latex "figure") (_ "nil"))
I attach a draft patch (no ORG-NEWS change included in this version as
I'm not sure if it should go under Options or Miscellaneous).
Regards,
Christian
>From 41706e3adbf1e42b2e5fdbe861525a89b166d5be Mon Sep 17 00:00:00 2001
From: Christian Moe <[email protected]>
Date: Sun, 11 Jan 2026 14:06:37 +0100
Subject: [PATCH] ob-core.el: Respect no/nil value in :wrap header argument
* lisp/ob-core.el (org-babel-insert-result): Do not wrap results if
the value of the :wrap header argument is "no" or "nil".
* doc/org-manual.org (Results of Evaluation): Update documentation.
An empty :wrap header argument leads results to be wrapped in a
"results" special block. It may sometimes be useful to turn off
wrapping explicitly for a particular block, e.g. if the value of :wrap
is set programatically or in a file-level header.
Prompted by an issue with captioning results when using the by-backend
trick in
https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html.
Reported-by: Mathew Moore <[email protected]>
Link: https://list.orgmode.org/CAAur0QTNjLMPp=2twqrjlen3tk6e1a6ozbavexzvga6yid5...@mail.gmail.com
---
doc/org-manual.org | 8 ++++----
lisp/ob-core.el | 4 ++++
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index e5c8af781..0856520e5 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -19329,10 +19329,10 @@ follows from the type specified above.
#+cindex: @samp{wrap}, header argument
The =wrap= header argument unconditionally marks the results block by
-appending strings to =#+BEGIN_= and =#+END_=. If no string is
-specified, Org wraps the results in a =#+BEGIN_results=
-... =#+END_results= block. It takes precedent over the =results=
-value listed above. E.g.,
+appending strings to =#+BEGIN_= and =#+END_=, except if the value is
+=nil= or =no=. If no string is specified, Org wraps the results in a
+=#+BEGIN_results= ... =#+END_results= block. It takes precedent over
+the =results= value listed above. E.g.,
#+begin_example
,#+BEGIN_SRC emacs-lisp :results html :wrap EXPORT markdown
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 23cf4d451..6245ead77 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2725,6 +2725,10 @@ result:
(opening-line (concat "#+begin_" full))
(closing-line (concat "#+end_" type)))
(cond
+ ;; Do nothing if type is "no" or "nil"
+ ((or (org-string-equal-ignore-case type "nil")
+ (org-string-equal-ignore-case type "no"))
+ nil)
;; Escape contents from "export" wrap. Wrap
;; inline results within an export snippet with
;; appropriate value.
--
2.43.0