Reputation: 1382
I am doing literate programming in Emacs org mode. When I do the Latex export to a pdf, I would like the name of the file the code gets tangled to to be displayed by each code block. I can't find a suitable header argument in the manual.
Here is my org file:
A piece of Python code:
#+BEGIN_SRC python :tangle pythontest.py
print("hello")
#+END_SRC
Here is my .emacs:
(org-babel-do-load-languages
'org-babel-load-languages
'((python . t)))
Here is a screenshot of the part of the pdf export with text on it:
Upvotes: 3
Views: 1650
Reputation: 2433
There are a couple of options that all require some hacking on your part. These two examples show how to use filters to modify export of src blocks.
http://kitchingroup.cheme.cmu.edu/blog/2013/09/30/Attaching-code-blocks-to-a-pdf-file-during-export/
They are a little clunky to me. An alternative approach is to use a preprocessing hook like this where you modify a temporary copy of the org-file prior to export:
(defun add-tangled-name (backend)
(let ((src-blocks (org-element-map (org-element-parse-buffer) 'src-block #'identity)))
(setq src-blocks (nreverse src-blocks))
(loop for src in src-blocks
do
(goto-char (org-element-property :begin src))
(let ((tangled-name (cdr (assoc :tangle (nth 2 (org-babel-get-src-block-info))))))
(insert (format "=Tangle: %s=\n" tangled-name))))))
(let ((org-export-before-processing-hook '(add-tangled-name))
(org-latex-pdf-process '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
"pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
"pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
(async nil)
(subtreep t)
(visible-only nil)
(body-only nil)
(ext-plist '()))
(org-open-file (org-latex-export-to-pdf nil t)))
This is what I would probably do these days.
Upvotes: 3