3

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

Instead of the standard

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

Is there a straightforward way to get this?

3

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
  (org-babel-do-load-languages 'org-babel-load-languages 
               '((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
2

Based on this answer: https://stackoverflow.com/questions/20194347/org-mode-with-code-example-as-html

* 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.