As suggested in the comments, you might well want to consider retaining the intermediate files associated with the latex conversion to PDF until you are happy that the PDF results are what you want.
Instead of deleting straight after compilation, I use a hook when I close a buffer on an org file to delete all the extraneous files that may be generated:
;; Hook to tidy latex process files when we close the buffer
(defun aff/tidy-latex-waste-products ()
"Clean up possible latex intermediate files when closing an org file."
(if (and (string-equal major-mode "org-mode")
(stringp buffer-file-name)
(file-exists-p (file-name-directory buffer-file-name))) ;; in case deleted
(dolist (file (directory-files
(file-name-directory buffer-file-name)
t
(concat (regexp-quote (file-name-base
buffer-file-name))
"\\(?:\\.[0-9]+\\)?"
"\\."
(regexp-opt org-latex-logfiles-extensions))))
(delete-file file) ) ) )
(add-hook 'kill-buffer-hook 'aff/tidy-latex-waste-products)
Note that this doesn't delete the .tex file as you wanted. I would consider the comments that suggest the .tex file is useful to keep around. If you do want to delete it, change the second last line of the function to:
(regexp-opt (cons "tex" org-latex-logfiles-extensions)))))
README.org
andREADME.tex
names differs from each other and I don't apply any save operation.org-export-as
,org-latex-export-to-pdf
,org-latex-compile
). 3) Piggyback on already existing cleanup code for log files and make it delete the.tex
file as well. This is the standard sequence of considerations that you have to make in many (more-or-less similar) situations..tex
file is often useful (either for debugging or for tweaking and compiling by hand or to just see what Org mode did exactly), so I never want it deleted automatically. I usually write a simple Makefile with aclean
action for all the bits and pieces that LaTeX produces (log files, aux files, etc) and averyclean
action that gets rid of all that plus the.tex
file and I run the make by hand.