# Wrap org src block results

I'd like to include a custom latex wrapper around src blocks result. For example, given:

#+BEGIN_SRC sh :results latex
which awk
#+END_SRC


I'd like to generate

#+RESULTS:
#+BEGIN_LaTeX
\begin{myverbatim}
/usr/bin/awk
\end{myverbatim}
#+END_LaTeX


#+RESULTS:
#+BEGIN_LaTeX
/usr/bin/awk
#+END_LaTeX


Is there a straightforward way to get this?

Unless you want to restrict your output to LaTeX there is no reason to wrap in #+begin_latex . #+end_latex. As such, you could simply use the wrap keyword.

emacs -q example:

(with-temp-buffer
'((shell .  t)))
(insert "
#+BEGIN_SRC sh :wrap myverbatim :exports results
which awk
#+END_SRC")
(org-latex-export-as-latex nil nil nil t))


=>

\begin{myverbatim}
/usr/bin/awk
\end{myverbatim}

• Great - much simpler than defining a custom wrapper. Is there a header argument analogous to wrap that can wrap the src block itself when using :exports both? – jake May 19 '15 at 13:55
• No. You should make request for org-latex-listings to accept a formatting string. minted and listings is supported out of the box. Or you could send a patch on org-latex-inline-src-block. Alternatively, if myverbatim is a fixed string I'd just use a filter to org-export-filter-src-block-functions using replace-regexp-in-string to change verbatim to myverbatim. – rasmus May 19 '15 at 14:08
• I just discovered org-latex-custom-lang-environments, which seems like it should do the trick, but haven't figured it out. Is there a reason that setting it to ((sh "myverbatim")) wouldn't affect export? – jake May 19 '15 at 14:23
• Turns out I needed to also set org-latex-listings to t. With that done, org-latex-custom-lang-environments does what I need. – jake May 19 '15 at 14:31
• Of course. I didn't think of that. – rasmus May 19 '15 at 14:39

* test using post-wrap
#+name: wrap-myverbatim
#+begin_src emacs-lisp :var text="" :exports none
(concat "\\begin{myverbatim}\n"
text "\n\\end{myverbatim}\n")
#+end_src

#+BEGIN_SRC sh :results latex :post wrap-myverbatim(text=*this*)
which awk
#+END_SRC

#+RESULTS:
#+BEGIN_LaTeX
\begin{myverbatim}
/usr/bin/awk
\end{myverbatim}
#+END_LaTeX

• (i) The results header in wrap-myverbatim is redundant. (ii) you can combine post and results which would allow you move out #+begin_latex . #+end_latex of wrap-myverbatim. – rasmus May 19 '15 at 13:47
• @rasmus yeh, right, updated the answer. – wvxvw May 19 '15 at 14:43