2

I am looking for some way to have a tidy folder system.

My idea is, when I create a new file for latex to automatically create a new folder under the same name inside my working directory and put all files in that folder (.aux, .pdf, .tex, .loc etc). It might be the case that some package does that, but I am relatively new to this.

Do you know any way of achieving something like this?

korni
  • 21

2 Answers2

2

latex has the -output-directory option. In Linux with the bash shell you can use the shell script

#!/bin/sh
name=`basename $1 .tex`
if [ ! -d "$name" ]; then
    mkdir $name
fi
latex -output-directory $name $1

Save the above code to somewhere in your $PATH called newlatex.sh and remember to chmod it 700. Then from the directory in which you placed the .tex file call

$ newlatex.sh filename.tex

or

$ newlatex.sh filename
Willie Wong
  • 24,733
  • 8
  • 74
  • 106
  • Anything similar for (lame) Windows? – korni Jan 19 '13 at 19:10
  • I am not that familiar with Windows, but if MikTeX (or whatever LaTeX distribution you use) supports command line commands, and if your IDE allows you to change the command used to compile the document, then in principle you can write a batch file to do so. But if you want a more tailor-made solution, please edit your original post to include (1) Operating system [I assume Windows] (2) LaTeX distribution (3) Any software you use in the workflow to create your document: what editor you use, how you compile the TeX file into DVI/PDF etc. – Willie Wong Jan 21 '13 at 08:51
0

If you are working with TeXstudio, you can do it in the following manner. (I have tested it for windows, but it should work for Linux too.)

Using menu bar, go to -- Options -> Configure TeXstudio -> Commands

Here in the text-box placed in front of "PdfLaTeX" option, you would probably see --

pdflatex.exe -synctex=1 -interaction=nonstopmode %.tex

Replace it with-

pdflatex.exe -synctex=1 -interaction=nonstopmode -output-directory % %.tex

That's all! You are done. Now compile the document and you should find all the compilation related files, e.g., .aux, .pdf, .tex, .loc, etc. in a folder having the same name as your tex file.

Further, If you wish to keep the pdf file in the original directory that contains tex file, use the following -

pdflatex.exe -synctex=1 -interaction=nonstopmode -aux-directory % %.tex

The above command will move all the auxiliary file in a separate folder except synctex.gz file. For more details on it, you can see the answer by Allan Munn