views:

123

answers:

4

When compiling latex documents the compiler emits a lot of "object" files. This clutters the directories I'm working on and it difficults the use of VCS like SVN. When I work with C++ code I have separate directories for the code and the objects, I can run make on the source directory but the .o files go to the build directory.

Is there a proper way to perform this separate compilation with Latex documents? Can it be done by using Makefiles or by passing options to the latex compiler?

Thanks

+2  A: 

I can't help much with LaTeX (having last user it seriously 20 years ago;-), but for Subversion, you should read up on the svn:ignore property -- it makes it easy to ignore files with extensions you do not want to version (object files, bytecode files as Python can often put in the same directory as the sources, backup files some text editors use, &c).

Alex Martelli
Subversion is one issue but not the important one. You can use the svn:ignore but you have to specify that property on each document and it's not optimal. Other issues that bother me is that you cannot autocomplete using the shell because all the files with the same name with different extension, or just rm the "object" files when Latex gets messed up.
ancechu
A: 

Latex generates the temporary files in the directory where the main document is located. If you want the contents to be placed in a different location, try with a main file like below.

\documentclass{article}
\input{src/maindocument.tex}

Using this method, you could maintain a directory structure like below

/
    main.tex
    /src
         maindocument.tex
midtiby
+2  A: 

You can use:

pdflatex --output-directory=tmp file.tex

and all the files will be stored in the folder tmp (pdf included).

Because this is not an optimal solution, I made my own tool, pydflatex, that compiles the LaTeX source by stashing away the auxilliary files (using the trick above), and brings the pdf back to the current directory, so after compiling you only have file.tex and file.pdf in your directory. This plays very well with version control.

Olivier
The latex command also has this --output-directory option, thanks
ancechu
To be precise, both `pdflatex` and `latex` are symbolic links to the main command `pdftex`, so they have the same options. By the way, I don't think there is much interest in using the `latex` command (vs `pdflatex`) nowadays, since pdf has now completely superseded dvi.
Olivier
A: 

Two options, besides the above.

  1. Use Lyx: it looks after the separate files. I think it copies the Latex file over to its own private directory and runs latex on it. In any case, nothing is created in the current directory.
  2. Use a makefile or one of the special Latex make programs, and have your regular targets run make clean.
Charles Stewart