I'm trying to use latexmk for the first time in Ubuntu. My project directory is the following:

  • Project
    • src
    • build
    • images

In the src directory are the .tex and .bib files. I want the .aux, .bbl, .log etc. files to go into the build directory.

In the root directory I have the following script:


if [ $# -gt 0 ];then
    if [ $1 = "-c" ];then
        cd build
        latexmk -c ../src/poly-paper.tex
    cd build
    latexmk -pdf ../src/poly-paper.tex
    mv poly-paper.pdf ..

The problem is that using this script causes it to not find the bibliography. My latexmk is v4.24 and doesn't support the -auxdir commands and I have to do without it so that someone else can compile it too.

Could someone suggest a solution please?

EDIT: I didn't know latexmk is a simple script, so I installed the newest version but I have problems using the -auxdir and -outdir commands. The problems is that Ubuntu comes with TexLive 2009 which does not support the -output-directory for pdflatex.

  • Welcome to TeX.sx! The current version of latexmk is 4.35. Maybe an update will help. Mar 3, 2013 at 10:56
  • Thank you. Unfortunately, some other people besides me will want to build the project and I can't force all of them to update. Mar 3, 2013 at 10:59
  • 1
    latexmk is a single selfcontained script, so you could even include a copy of it in your project.
    – daleif
    Mar 3, 2013 at 18:14

2 Answers 2


If the underlying latex command doesn't support the -output-directory option, then latexmk's -outdir option won't work.

A simple solution with the scripts you are using would be to set the BIBINPUTS environment variable to include the source directory, e.g.,

export BIBINPUTS=:../src

To add to John's answer, it could be noted that you don't need to have a separate script. I use the following latexmkrc to compile everything in _build; this is greatly simplified by the fact that I have a single target.

system ("mkdir -p _build; ln -f -s ../src/main.tex _build/main.tex");

@default_files = ('_build/main.tex');
$do_cd = 1

This works even with TeXlive, since it doesn't rely on additional options of the LaTeX binary.

  • A universal solution (that works also with Windows) uses ; instead of : to join paths in TEXINPUTS and BIBINPUTS... Dec 16, 2017 at 6:39
  • Do symbolic links work in Windows nowadays?
    – Michaël
    Dec 16, 2017 at 10:10
  • When modifying TEXINPUTS, better use ensure_path. tex.stackexchange.com/a/474915/52414 Even then, setting TEXINPUT in this way didn't work for me. I got rid of the TEXINPUTS and $do_cd = 1; lines (the latter of which misses a ;) and now it works! Jan 28, 2022 at 9:06

You must log in to answer this question.

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