org-mode: how to show header arguments when exporting to html

142 views Asked by At

The org mode doesn't export header arguments or block name to html. In the following example, it would be confusing to read the exported html page if the passing of variable bar is not shown up. Is there any setting or customization to enable the html export of header arguments and block name (eg call-example) here?

#+name: call-example
#+begin_src emacs-lisp :var bar="baz" :exports both
  (sit-for 1)
  (message "bar=%S" bar)
#+end_src

#+RESULTS: call-example
: bar="baz"
2

There are 2 answers

5
Tom Regner On BEST ANSWER

It is possible to modify org-babel-exp-code-template to include the name and passed variable. From the documentation of the template

This template may be customized to include additional information such as the code block name, or the values of particular header arguments.

A first try looks like this:

(setq org-babel-exp-code-template
         (concat "\n=%name(%var)=:\n"
              org-babel-exp-code-template)
               )

For this small example file

#+title: Test

#+name: example
#+label: Example
#+begin_src shell :var bar="baz" :exports both
    echo $bar
#+end_src

#+RESULTS: Example
: baz

The export to plain text ASCII looks like this:

                              ____________

                                  TEST

                              ____________


Table of Contents
_________________




`Example((bar . "baz"))':
,----
|     echo $bar
`----

,----
| baz
`----

In this manner only one variable passed is exported and displayed as cons-cell, that could be a deal breaker for you. Exports with other backends include the same information. I think it shouldn't be too hard to adapt this approach to reach a result that satisfies you.

3
NickD On

I don't know of any options specific to source block names (and a quick search has not uncovered any). Header args can be specified in property drawers instead of specifying them directly in the source block and there is an option to export property drawers. You can also annotate the output yourself of course:

#+OPTIONS: prop:t

* Some code
:PROPERTIES:
:header-args: :var bar="baz"
:END:

This source block is named =call-example=:
#+name: call-example
#+begin_src emacs-lisp :exports both
  (sit-for 1)
  (message "bar=%S" bar)
#+end_src

If you evaluate =call-example=, passing it the header ~:var bar="baz"~, the result is:

#+RESULTS: call-example