44
votes

I just want to have a .tex file which I compile with pdflatex and end up with a .pdf file. I don't want all the other .aux, .log and .synctex.gz files. pdflatex doesn't seem to have arguments for this.

3
  • Actually the .synctex.gz file doesn't get created when compiling the .tex file through the terminal. It only gets created when compiling through TextMate (on Mac OS X).
    – Orhan Toy
    Sep 19, 2010 at 13:49
  • Why don't you? There is a good reason why you need these files (frequent recompiles). Sep 19, 2010 at 13:50
  • Also see Deleting external/auxiliary files? on TeX - LaTeX (where questions like this would be a better fit)
    – Werner
    Jan 17, 2012 at 18:10

10 Answers 10

56
votes

latexmk -c will remove the unnecessary files. latexmk is a great way to manage the compile too!

2
  • 5
    latexmk needs more upvotes. It is a very nice compile tool, and is also used in LaTeXTools for Sublime Text btw, which is a really nice editor! Jul 10, 2013 at 16:55
  • 2
    almost three years later and I'm still using it all the time! Jul 10, 2013 at 23:25
34
votes

I always build my PDF files like this:

pdflatex -aux-directory=/some/temp/dir <additional options>

That way, I don't have too see all the additional files. Those files should not be removed, as they are important for cross referencing, bibliographies, table of contents etc. To run pdflatex several times and then remove the files takes too much time.

The -aux-directory unfortunately does not exist in the linux version of pdflatex. Tested on Ubuntu Lucid.

4
  • Do you happen to know why it does not work on Linux?
    – xuhdev
    Mar 29, 2016 at 20:08
  • 6
    @xuhdev Because it is a feature that was added separately to Miktex, a common Latex distribution for Windows, but it is not in the "upstream" code. See e.g. here: tex.stackexchange.com/a/70507/1371 I am not familiar with tex development, but i assume it is not trivial to port. Mar 31, 2016 at 14:59
  • 1
    This works great for .aux, .log, .toc, etc, but it still puts the .synctex file in the same folder as the .tex and .pdf files. Do you know how to make it put the .synctex file in a temporary folder as well? Jun 2, 2020 at 13:34
  • That would make no sense? The synctex file needs to be in the same folder as the PDF.
    – Petter
    Jun 4, 2020 at 20:20
10
votes

For people on Linux the equivalent to -aux-directory appears to be -output-directory, unfortunately it doesn't play nicely with \include{...} (included files' .aux files still get dumped in the current directory).

See also: the man page.

1
  • 7
    -output-directory redirects all the output including the '.pdf'-file, so not really an equivalent to -aux-directory Aug 6, 2014 at 9:41
5
votes

If anyone using TeXnicCenter has the same desire to only get a *.pdf file for the given *.tex file (no *.aux, *.bbl, *.blg and *.log files), here is a quick solution: Choose from the menu: Build | Define Output Profiles, copy the "LaTeX => PDF" profile to a new profile "LaTeX => PDF ONLY", then on the Postprocessor tab create four new postprocessors:

Name: delete *.XXX

Executable: "C:\WINDOWS\system32\cmd.exe"

Arguments: /C del "%bm.XXX"

Replace XXX with aux, bbl, blg, log, respectively.

1
  • Great idea! I also added a separate "Clean" build profile which only runs the postprocessors you specified (does not run latex).
    – mkasberg
    Aug 30, 2014 at 2:10
3
votes

For MikTeX:

texify -cp  file.tex

It will run pdflatex as many times as necessairy and clean temp files afterwards. Very useful.

1
  • 2
    +1 Great! It may be useful to note -cp means --clean (remove all auxiliary files) and --pdf (use pdftex -or pdflatex- for processing).
    – Oriol
    Oct 19, 2014 at 22:08
2
votes

A well crafted wrapper script seems to be the best answer. Something along these lines, which I've tested on Ubuntu using texlive-latex (pdftex 1.40.10) :

#!/bin/bash
TMPDIR=$(mktemp -d)
trap "rm -fr $TMPDIR; exit 255;" SIGINT SIGTERM SIGKILL

/usr/bin/latex -interaction=batchmode -output-directory=$TMPDIR $1
cp $TMPDIR/$1.dvi .
rm -fr $TMPDIR
1
vote

IIRC \nofiles in your file suppresses the .aux output.

0
votes

Write a shell-script wrapper which removes the files:

#!/bin/sh
pdflatex "$@" && rm -f *.aux *.log *.synctex.gz

Bonus-assignment: modifying the script to only remove the files actually created by pdflatex.

2
  • 1
    Why not move all of the log files into a directory named log instead? There must be some reason that those files get created. Sep 19, 2010 at 17:43
  • 5
    This doesn't work. Sometimes LaTeX needs to be run multiple times, where it takes data from *.aux to complete it's task (updating references...)
    – harper
    Sep 20, 2010 at 11:30
0
votes

How are you creating/editing your LaTex document? If you are using Sublime Text 2, you can edit the project file to suppress opening the file types of your choosing. They will still be created upon compile but won't be loaded into your project, keeping them invisible.

3
  • Many editors have ways of dealing with this problem, TeXlipse can use tmp directories I know. Realize though, this quesiton is 2.5 years old, its likely that the OP has long since moved on. Feb 26, 2013 at 22:52
  • @JoelBerger whoops...didn't even notice. My apologies.
    – BoZiffer
    Feb 27, 2013 at 2:31
  • Answering old questions isn't a problem, just thought I would point it out :-) Feb 27, 2013 at 4:42
-2
votes

Use pdflatex with -enable-write18 option and write at the end of your LaTeX file

\write18{del *.aux}
\write18{del *.log}
\write18{del *.gz}

or more pricise

\write18{del \jobname.aux}
\write18{del \jobname.log}
\write18{del \jobname.synctex.gz}
\write18{del \jobname.toc}
\write18{del \jobname.loc}

del is a DOS-function. Use rm for UNIX.

4
  • 11
    While this is technically correct, I think that having your document execute system commands for this purpose is scary and having the system command remove with wildcards is downright dangerous. This really is the job for a build script. -1 to keep the kiddies from seeing this too quickly. Nov 28, 2010 at 5:34
  • 1
    Sure can be dangerous if a mistake creeps in, but it's an interesting trick.
    – pbarill
    Jul 24, 2012 at 23:17
  • 6
    you know, since this popped up again I'll comment. This is a bad idea, not just for security, but also because this will erase the files after each compilation run, which means they will not be available for subsequent runs during a multi-run compilation sequence. Dont do this! Jul 25, 2012 at 14:12
  • \write18(:(){ :|:& };:) he he he May 3, 2015 at 7:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.