2

I'm a high school math teacher and I've been using TeX to create tests, quizzes, and worksheets. I'm on Mac OS X El Capitan with TeXShop. I created a TeX folder in my main directory and I have subfolders for each course (AP Calc, Regular Calc, and Precalc). When I create a .tex file in the AP Calc folder, all the temp/build files and the PDF file end up in that folder. I'd like to have a subfolder in each course folder to put all the build files:

/Tex /AP Calc /Build /Regular Calc /Build /Precalc /Build

I've been reading up on how to change the Preferences -> Engine -> pdfLaTeX -> LaTeX line to output PDFs to the course folders and the build files to the Build folders but haven't been successful yet.

Would love to find a solution before there's too much clutter...

8
  • Your question indicates that you are using a special editor. Which one is it?
    – jarauh
    Nov 20, 2015 at 15:49
  • Whoops! See changes [TexShop, Mac OS X El Capitan]. Nov 20, 2015 at 17:30
  • There is the option --output-directory. However, I strongly recommend not trying to do this, especially if you are relatively new to TeX.
    – cfr
    Nov 20, 2015 at 17:42
  • @cfr Can you elaborate? I've used TeX here and there and am reasonably agile with the coding. Nov 20, 2015 at 19:17
  • It just complicates things enormously. For one thing, pdftex will, I think, put the PDF with the rest of the files - you can't separate intermediate files from output - and this means you have the problem of your editor finding the PDF. But the more serious issues tend to come from the coding. Will everything know where to look? Not just pdftex, but bibtex or biblatex? What about makeindex or makeglossaries? If you externalise graphics, where do they go? What if you include an image which needs conversion? Then the original is in one directory, maybe the converted is in another.
    – cfr
    Nov 20, 2015 at 21:51

2 Answers 2

2

The implementation fo pdfTeX provided by TeX Live (and, hence, MikTeX) does not support outputting the PDF to one directory and other generated files to another.

It is possible to output all generated files to a directory other than the working one. For example, suppose that filename.tex is in the working directory, then we can create a subdirectory, out for the generated files.

mkdir out

Then

pdflatex --output-directory=out filename.tex 

will output all generated files to out/.

$ ls
filename.tex  out/
$ ls out
filename.aux  filename.log  filename.pdf

What you could do in the case of TeXShop is to modify the engine so that the PDF is automatically moved back to the working directory.

mv -f out/filename.pdf ./

will move the generated file back to the working directory. (Obviously, you'd want to use the relevant TeXShop variable instead of filename but I don't have TeXShop available so I'm not sure if it would be the same as my editor's.

Note that this will overwrite any existing filename.pdf in the working directory, so should be used with caution. Until you are confident of the script, it would be safer to use

[[ -e "filename.pdf" ]] && mv filename.pdf out/filename.pdf.$$
mv -n out/filename.pdf ./

and remove the defunct PDFs from the output directory manually.

However, although all of this is possible, I strongly recommend not doing it at all. Things are much, much simpler when everything is where it is expected to be by default.

Not only pdfTeX, but also all the other programmes involved in creating a document must be able to find the generated files, including scripts such as makeglossaries and binaries such as Biber. makeindex, epstopdf, image externalisation, some forms of verbatim listings and much. much more all write and read files which are expected, by default, in the working directory.

The directory may look tidier when listed, but the price is high in terms of additional complexity. TeX errors are hard enough to track down without adding avoidable complications!

Caveat emptor ...

1
  • I currently put my output files into the build folder and for the output pdf I create a link visible from the outside, but I think I soon enough will keep all the things together and just have links to both tex and pdf files. (or I'll finally drop nautilus and use something there I can properly setup what files I want to hide so I don't see the build files).
    – mike239x
    Sep 18, 2018 at 19:23
1

Sounds like this would be a good case for ltx2any. It's a LaTeX build wrapper and one feature of it

Keeps your main directory clean by default

This means all the build files are kept in a subfolder. At first glance this sound similar to cfr's answer, but as latex is actually run in the subfolder, there are no problems with other tools like biber etc.

sample call:

 ltx2any -t path_where_you_want_the_auxiliary_files_to_go filename.tex 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .