Preamble: Setting the output directories
TeX distros have the useful command line option --output-directory
to create all output files in a specified directory.
MikTeX provides an even more convenient option to put only temporary material in a separate folder, which can be eventually deleted, that is:
pdflatex --aux-directory=auxdir mybook
--aux-directory
is particularly convenient for large projects with several TeX files, for example a book with several chapters, to reduce post-compilation clutter.
One can use together --aux-directory
and --output-directory
.
Below I will address --aux-directory
, but using --output-directory
or both produces the same issue.
Using bibliographies when output/aux directories are diverted
I haven't yet tried them, but I am aware of --input-directory
and --output_directory
option, which should do similar jobs in biber
.
As regards BibTeX, there are no such options. For a simple project, based on a single .tex
file (and therefore .aux
), depending on your path separator,
bibtex auxdir/mybook
bibtex auxdir\mybook
should work. If there are several .tex
files (when the aux dir is actually useful), bibtex
is unable to find the other aux files, which will still be searched in the project's root dir.
It is possible to cd to auxdir
, but in this case the .bib
and .bst
files will not be found.
A workaround consists in copying them in the auxdir
. That works, but it is against the purpose of such directory and also time-consuming, as the original .bib
file in the parent directory is likely to be updated often.
What is the correct workflow for bibtex and biber when the --aux-directory
(--output-directory
) option is employed?
Best Answer
So some suggestions:
1. Don't use
--output-directory
or--aux-directory
Really. They just add a whole layer of unnecessary complexity. In addition to issues with
bibtex
, if you have use multiple input files, you'll likely end up having to recreate the same folder hierarchy in the output directory as you have in the main directory. Especially for large, multi-part documents, this can be a hassle for no real added value. Similarly, if you use other external tools, you'll end up needing to configure them to use the output directory appropriately.2. Use
latexmk
This will handle
bibtex
in an appropriate way and handle the issue with the output hierarchy detailed above. This is probably the simplest way to deal with things, if you insist on using an output directory.3. A way to make things work
If you still want to use an output directory and don't want to use
latexmk
, you can do the same thing thatlatexmk
does. From the command prompt, you can runbibtex
like this (all one line):cd auxdir & set BIBINPUTS="C:\path\to\mybook;%BIBINPUTS%" & set BSTINPUTS="C:\path\to\mybook;%BSTINPUTS%" & bibtex mybook
Which runs
bibtex
in the auxdir, while adding the directory containing the source files to the bib / bst search path.