emacslatexelispauctex

How to remove the directory .t2d on C-c C-c Clean / M-x TeX-clean?


I use the following code in .emacs to clean the working directory from unwanted files.

(eval-after-load 'latex
  '(progn
     (setq LaTeX-clean-intermediate-suffixes (delete "\\.synctex\\.gz" LaTeX-clean-intermediate-suffixes))
     (setq LaTeX-clean-intermediate-suffixes (append
                          LaTeX-clean-intermediate-suffixes
                          (list "\\.bcf" "\\.synctex\\.gz(busy)" "-blx\\.bib" "\\.run\\.xml" "\\.fdb_latexmk" "\\.fls" "\\.ptc")))
     (setq LaTeX-clean-output-suffixes (append LaTeX-clean-output-suffixes (list "\\.synctex\\.gz")))
))

If my LaTeX document contains an error, the current directory contains a folder .t2d (I compile with texi2dvi -p from within Emacs/AUCTeX). I have to manually switch to the working directory to remove this folder as, otherwise, the document would not compile (in fact, compilation would stop with the same error [in most of the cases]). The idea is therefore to include \\.t2d in the above list of files being removed on C-c C-c Clean. However, if I do so, C-c C-c Clean says TeX-clean: Removing old name: is a directory: qrm.t2d. How can directories be removed on C-c C-c Clean?


Solution

  • The hint from lawlist's comment brought the solution. I first discovered that texi2dvi --mostly-clean already cleans a lot (including the unwanted directory .t2d). I then simply used a rm to remove further unwanted files -- everything wrapped so that I can call it via C-c C-c tidy:

    (add-hook 'LaTeX-mode-hook
       (lambda ()
         ;; texi2dvi
         (add-to-list 'TeX-command-list
              '("texi2dvi" "PDFLATEX='pdflatex --shell-escape -synctex=1 -file-line-error' texi2dvi --max-iterations=5 -p %s.tex" TeX-run-command nil t :help "Run texi2dvi") t)
         ;; clean
         (add-to-list 'TeX-command-list
              '("tidy" "texi2dvi --mostly-clean %s.tex; rm %s.pdf \"%s.synctex.gz(busy)\"" TeX-run-command nil t :help "Run clean") t)
         ;; default
         (setq TeX-command-default "texi2dvi")))