4

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:

#!/bin/sh

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

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.

Stefan Kottwitz
  • 231,401
Grieverheart
  • 143
  • 1
  • 5

2 Answers2

5

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
John Collins
  • 11,183
  • 3
  • 32
  • 33
0

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");
$ENV{'TEXINPUTS'}='../src:../lib:../img:';
$ENV{'BIBINPUTS'}='../src:';

@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.

Michaël
  • 1,384
  • 11
  • 22
  • A universal solution (that works also with Windows) uses ; instead of : to join paths in TEXINPUTS and BIBINPUTS... – Paul Gaborit Dec 16 '17 at 06:39
  • Do symbolic links work in Windows nowadays? – Michaël Dec 16 '17 at 10:10
  • When modifying TEXINPUTS, better use ensure_path. https://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! – Sebastian Graf Jan 28 '22 at 09:06