I use org-babel-tangle to generate latex documents from org files.
These org files have the following first line:
#+PROPERTY: header-args :latex :comments org :tangle PATH/FILE_NAME.tex
I built a function to tangle to tex, compile the tex, and open the generated PDF:
(defun mda/tangle-tex-compile-open-pdf()
"Generate and open a PDF from an org file containing tex blocks."
(interactive)
(org-babel-tangle)
(setq full-path-tex (cdr (assq :tangle (caddr (org-babel-get-src-block-info)))))
(current-buffer)
(cd (file-name-directory full-path-tex))
(shell-command (concat "xelatex -interaction=nonstopmode " (file-name-nondirectory full-path-tex)))
(shell-command (concat "evince " (file-name-base full-path-tex) ".pdf")))
I put this function in my init. When I execute it, it produces the following error :
cd: Wrong type argument: stringp, nil
What I don't understand is that when I run
(setq full-path-tex (cdr (assq :tangle (caddr (org-babel-get-src-block-info)))))
(current-buffer)
(cd (file-name-directory full-path-tex))
(shell-command (concat "xelatex -interaction=nonstopmode " (file-name-nondirectory full-path-tex)))
(shell-command (concat "evince " (file-name-base full-path-tex) ".pdf"))
from org files, I have no errors and everything works fine...
(cdr (assq :tangle (caddr (org-babel-get-src-block-info))))returnnil, not an absolute file name. Why this is the case when you call the function and not when you eval the code from an Org buffer, I don't know. A guess is that in the context of Ords(org-babel-get-src-block-info)gives you something useful and outside that context it doesn't. TryM-x debug-on-entry RET mda/tangle-tex-compile-open-pdf RET, and walk through the debugger withd, to see what goes wrong.debug-on-entry RET mda/tangle-tex-compile-open-pdf RETdoesn't do anything. I don't even have an error message. And when I pressd, I just see the letter d wirrtten down in the buffer.*Backtrace*doesn't open after you've doneM-x debug-on-entry...and retried your code, thenmda/tangle-tex-compile-open-pdfisn't getting called, for some reason (?). If the debugger does open, thedin the debugger window steps through the evaluation of that function call.*Backtrace*buffer. After doingM-x debug-on-entry RET mda/tangle-tex-compile-open-pdf RETonce, the debugger appears each time I doM-x mda/tangle-tex-compile-open-pdf RET. I now have to understand how the debugger works, I'll try to find some tutorial.cdin a function: it is meant for interactively changing the currenct directory of a buffer. You are better off let-bindingdefault-directory. See my answer to your related question which indirectly also answers this question.