# Hiding particular output files: namely, .aux and .log files

Is it possible to hide .aux and .log files? If so, what would be the most low-maintenance/simple way of doing so? They create quite a bit of clutter. I have a folder where I'm tending to a bunch of tex files, and ideally I'd like it so that I just see the .tex and output .pdf files.

ADDENDUM: I am using Windows 7.

-
Sort them by type? :P –  percusse Jun 30 '12 at 21:35
Related (duplicate?) question: Need *.aux files in separate folder. –  Alan Munn Jun 30 '12 at 21:43
latexmk has three options that allow you to clean up as you go: -c, -C, -c1. This seems easier (and to a large degree safer) than fiddling with sending the various created files to non-standard places. –  jon Nov 16 '12 at 10:01

If you have a web2c based system you can experiment with TEXMFOUTPUT

My copy of texmf.cnf has

% Write .log/.dvi/etc. files here, if the current directory is unwritable.
%TEXMFOUTPUT = /tmp


However it's probably not a good idea to do this. .aux files for example need to be read back in by LaTeX so if you manage to move them you need to configure latex to find them in the non standard place. Similar considerations apply to other auxiliary files such as .bib, .bbl, bookmark files written by hyperref etc. Even log files which are not (usually) read back by latex are often parsed by editors and GUI etc so that they can report and step through errors etc.

-
if the comment is correct then using this var wouldn't help much as the job input dir is normally writable (for good reasons). –  Frank Mittelbach Jul 1 '12 at 15:23
yes true although it wouldn't be if you went chmod a-w . I was sure that I remembered TEXMFOUTPUT originally affecting all output, but perhaps it changed over the years, that's the only relevant one I could see now, but that's essentially why I left in that comment (from a TL2011 cygwin distribution texmf.cnf) –  David Carlisle Jul 1 '12 at 20:12

Here is a simple patch of the LaTeX kernel that moves most auxillary files to a sub directory (which needs to exist). The .log file stays on top and I do not gurantee that I patched everything necessary :-). Specify \DeclareAuxDir{directory/} if you want directory to hold your files.

\begin{filecontents}{aux-to-subdir.sty}

\RequirePackage{etoolbox}

\newcommand\DeclareAuxDir[1]{\gdef\AuxDir{#1}}

\let\AuxDir\@empty

% \document can't be patched using etoolbox so this is done manually here
% regexpatch would work but I have to run, so this is the direct version for now

\def\document{\endgroup
\ifx\@unusedoptionlist\@empty\else
\@latex@warning@no@line{Unused global option(s):^^J%
\@spaces[\@unusedoptionlist]}%
\fi
\@colht\textheight
\@colroom\textheight \vsize\textheight
\columnwidth\textwidth
\@clubpenalty\clubpenalty
\if@twocolumn
\divide\columnwidth\tw@ \hsize\columnwidth \@firstcolumntrue
\fi
\hsize\columnwidth \linewidth\hsize
\begingroup\@floatplacement\@dblfloatplacement
\makeatletter\let\@writefile\@gobbletwo
\global \let \@multiplelabels \relax
\@input{\AuxDir\jobname.aux}%
\endgroup
\if@filesw
\immediate\openout\@mainaux\AuxDir\jobname.aux
\immediate\write\@mainaux{\relax}%
\fi
\process@table
\let\glb@currsize\@empty  %% Force math initialization.
\normalsize
\everypar{}%
\ifx\normalsfcodes\@empty
\ifnum\sfcode\.=\@m
\let\normalsfcodes\frenchspacing
\else
\let\normalsfcodes\nonfrenchspacing
\fi
\fi
\@noskipsecfalse
\let \@refundefined \relax
\let\AtBeginDocument\@firstofone
\@begindocumenthook
\ifdim\topskip<1sp\global\topskip 1sp\relax\fi
\global\@maxdepth\maxdepth
\global\let\@begindocumenthook\@undefined
\ifx\@listfiles\@undefined
\global\let\@filelist\relax
\fi
\gdef\do##1{\global\let ##1\@notprerr}%
\@preamblecmds
\global\let \@nodocument \relax
\global\let\do\noexpand
\ignorespaces}

\patchcmd{\@include}
{#1.aux}
{\AuxDir#1.aux}
{\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}

\patchcmd{\@include}
{\@partaux #1.aux}
{\@partaux \AuxDir#1.aux}
{\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}

\patchcmd{\@starttoc}
{\jobname}
{\AuxDir\jobname}
{\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}

\patchcmd{\@starttoc}
{\endcsname \jobname}
{\endcsname \AuxDir\jobname}
{\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}

\patchcmd{\enddocument}
{\jobname}
{\AuxDir\jobname}
{\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}

\patchcmd{\makeindex}
{\jobname}
{\AuxDir\jobname}
{\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}

\patchcmd{\makeglossary}
{\jobname}
{\AuxDir\jobname}
{\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}

% one could also patch \bibliography to load the .bbl file from the dir but I consider a .bbl more as part of a doc
% so not done

\end{filecontents}

\begin{filecontents}{bar.tex}
\section{bar}

test for \ref{foo}
\end{filecontents}

\documentclass{article}

\usepackage{aux-to-subdir}

% declaring the subdir to be used for aux/toc/...
% need to exist

\DeclareAuxDir{./auxfiles/}

\begin{document}

\tableofcontents

\section{foo} \label{foo}

\include{bar}

\end{document}


Perhaps the .bbl file should be moved there too ... not done.

-
I'd never thought that this would be possible on the (La)TeX level... Having this as a "real" package (tested and working with all standard classes, up to beamer, which tends to create a ton of aux files) would be just ... great! –  Daniel Jul 1 '12 at 16:30
What about \edef\jobname{\AuxDir\jobname}? That could save you a bunch of redefinitions, I think. –  Bruno Le Floch Jul 1 '12 at 16:39
@Daniel I wouldn't see this being a big issue. The worst problem is the fact that for certain file operations LaTeX2e doesn't offer official interfaces so that some poackage might exist that add their own aux file handling for additional files types. –  Frank Mittelbach Jul 1 '12 at 16:41
@Bruno most likely true, would need some chekcing though, it could have side effects. And then you may not want all files be treated like this. For example I didn't move the bbl file because I consider this part of the document (I rather send my bbl file to somebody instead of my bib files) –  Frank Mittelbach Jul 1 '12 at 16:43
@Frank, Ah, you're right. For a package, I would personally go for brutally redefining \@@input to do a slow \futurelet-based parsing of the file name (see e.g., my morewrites package which parses file names for \openout`), then runs some regexes on that file name to decide where it should go. –  Bruno Le Floch Jul 1 '12 at 17:22