When I have master pdflatex file which includes one or more child documents using something like \include{include/childdoc}, and I call pdflatex on it using pdflatex -output-directory=out parent.tex, I seem unable to find a way of calling bibtex on the resulting parent.aux file. I have tried both cd out; bibtex parent, and bibtex out/parent, to no avail.

I know there are various build-tools out there, but I'd like first to make it work just from the shell with no special build-tool dependencies.

6 Answers 6


Ok I finally figured it out (not sure if this is documented somewhere already):

I needed to explicitly create directories within out having the same name as the directories I include files from. Then, I need to be in the out directory when running bibtex. Furthermore, the bibtex file needs to be manually copied to the out directory. Finally, I run pdflatex a second time from the top-level directory, again with the -output-directory flag.

In summary (starting in the directory containing parent.tex):

  1. mkdir out/include
  2. pdflatex -output-directory=out parent.tex
  3. cp mybib.bib out
  4. cd out ; bibtex parent
  5. cd .. ; pdflatex -output-directory=out parent.tex

(and maybe you need to run pdflatex again, depending on what packages you're using...)

  • 2
    Is there no way to get around copying the file? Oct 11, 2012 at 7:02
  • 6
    There IS a way to get around copying the file, but it kind of sucks. When giving the \bibliography{...} command, give the paths to the .bib files relative to the output directory. So if are planning on running pdflatex -output-directory=out, say \bibliography{../mybib} instead of \bibliography{mybib}. (You still have to run bibtex from the output directory, unfortunately. If using a Unixy shell, you can say (cd out; bibtex parent) (parentheses included!) and avoid having to cd .. when you're done.)
    – EvanED
    Jan 16, 2013 at 18:45
  • There is a way around copying the .bib file. You just need to set the environment variable BIBINPUTS to the directory where your .bib file is located: export BIBINPUTS=/path/to/directory/of/bibfile Now you can just run bibtex without copying the file.
    – JorenV
    Mar 21, 2019 at 16:36

You can use environment variable TEXMFOUTPUT to specify output directory for bibtex files. In your case, you can create makefile like:

    mkdir out -p
    pdflatex -output-directory out parent.tex
    TEXMFOUTPUT="out:" bibtex out/parent
    pdflatex -output-directory out parent.tex
    pdflatex -output-directory out parent.tex

Consider a more complicated variant where you have placed your source files in subdirectory src. Then you will use also variable BIBINPUTS to specify locations of your *.bib files and BSTINPUTS to specify location of your *.bst files (bibliography style). Then the makefile could look like this:

    mkdir out -p
    TEXINPUTS="src:" pdflatex -output-directory out src/parent.tex
    BIBINPUTS="src:" BSTINPUTS="out:" TEXMFOUTPUT="out:" bibtex out/parent
    TEXINPUTS="src:" pdflatex -output-directory out src/parent.tex
    TEXINPUTS="src:" pdflatex -output-directory out src/parent.tex
  • 3
    bibtex only puts its output in TEXMFOUTPUT (if it can't do so in the current directory), but doesn't look for inputs (aux files) there. This didn't work for me with TeX Live 2013 (bibtex 0.99d)
    – Sameer
    Sep 15, 2014 at 22:54
  • See my answer for a fix :) Two years late, sorry
    – Three Diag
    Jan 25, 2016 at 16:33

If you are using TexStudio, there is a simple way to do it. In Preferences/Commands, you can add to the BibTeX line build/%.aux if your output folder for PdfLaTeX is named build.

This is working for me with my_bibliography.bib in the same folder as my LaTeX files and using the following at the end of my LaTeX file.


I guess you can find similar settings for other editors/compilers.

Hope this helps !

  • This doesn't seem to work if you \include files. I ended up using sh -c "cp references.bib build;cd build;bibtex %.aux". This copies the bib file to the build folder and runs bibtex with the build folder as current directory.
    – Wouter
    Jul 13, 2020 at 18:47

The procedure suggested by @framerius works, but requires a little hack. I will summarize his answer here as well, for completeness.

The issue is that bibtex ability to write to $TEXMFOUTPUT is restricted to avoid file overwriting and the bibtex command returns an error message

bibtex: Not writing to  $TEXMFOUTPUT/src.blg (openout_any = p).

Open the file texmf.cnf, dunno about windows, but on linux:

/usr/share/texlive/texmf/web2c/texmf.cnf (UBUNTU TEXLIVE)
/usr/share/texmf-dist/web2c/texmf.cnf (ARCH LINUX TEXLIVE)

find the openout_any = p line and change it either to a for always or r for restricted (p stands for paranoid fyi).

Now, running something like

mkdir OUT
pdflatex --output-directory OUT myfile
bibtex OUT/myfile
pdflatex --output-directory OUT myfile
pdflatex --output-directory OUT myfile

produces the expected results, and is fully scriptable. The hack comes from this page Bibtex going openout which I googled. Enjoy clean folders forever and ever =D

  • this does not work for me (Ubuntu 14.04)
    – mcExchange
    Jan 7, 2019 at 16:05

Did you check the location of the aux-files? The --output-directory doesn't affect auxiliary files (at least not in miktex. In miktex there is the --aux-directory switch to set the directory for auxiliary files). Also - as you use \include: Don't forget that they will be more than one aux-file.

  • 1
    Unlike miktex, pdflatex's -output-directory=xyz switch causes everything (including aux files) to be placed beneath xyz.
    – Mark
    Mar 5, 2011 at 15:09

The solution of Emilie Picard-Cantin works great as long as you (use TexStudio and) do not \include{} files into the file that you compile. The auxiliary file of the included file is placed next to the included file, instead of in the build directory. This results in bibtex not being able to find the generated .aux file. Using \input{} instead of \include{} makes everything work like a charm.

You must log in to answer this question.

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