Using BibLaTeX in Texmaker

Just the other day I was trying to use BibLaTeX over BibTeX, because I heard good things about it. My primary motivation to give it a try was, that citing web-resources seemed much easier.

The way it is supposed to work is quite straight forward: You include the BibLaTex package, tell it which bibliography backend to use (i.e. Biber or BibTex) and it creates an auxiliary bibliography, which is referenced then in the aux file of your master document.

There were however two things I really wanted to hold on to: I love Texmaker so obviously I want the quick build button to work as usual. Furthermore I hate clutter in my working directory, so a separate build directory is key.

Assume the following example files: The master.tex where all my packages are loaded and usually a lot of other stuff is happening. Usually the actual content of my work will be scattered across separate tex files. Additionally there’s the trusty bibliography file, in this case called bib.bib.

Using the default quick build (set to use pdflatex + bibtex + pdflatex + pdflatex + view) did not work. After some troubleshooting I figured out where the problem lies. Remember I mentioned biblatex references to the auxiliary bibliography file (master-blx.bib) from the master.aux? Those lines look something like that:

\bibstyle{biblatex}
\bibdata{master-blx,bib}
\citation{biblatex-control}

The bibliography data, which bibtex will look for are the original bibliography and the auxiliary bibliography generated by BibLaTeX. However, the master-blx.bib sits nicely in the build directory as it should, but bibtex looks for both files in the same directory. After skimming over a bunch of pages of the package documentation I found no solution, which enabled me to have this reference manipulated. Neither did bibtex have a command line option to indicate different file locations to look for. Part of the solution is to look at placed we can touch: It’s possible to use \bibliography{../bib.bib} over \bibliography{bib}. Doing that, you need to run the bibtex step from within the build directory.

Problem solved, right? Not quite. Texmaker did not accept any attempts to customize the bibtex command in a way to accept either environment variables or cd commands or any other stuff I tried. What did end up working though, was writing a shell script that does what I want and put it into a random custom command and choosing the quick build setting to execute it and viewing the resulting PDF as shown in the screenshots.

screen2 screen1

The shell script (make.sh):

pdflatex -output-directory=build -synctex=1 -interaction=nonstopmode master.tex
cd build/; bibtex master.aux; cd ..
pdflatex -output-directory=build -synctex=1 -interaction=nonstopmode master.tex
pdflatex -output-directory=build -synctex=1 -interaction=nonstopmode master.tex

The latex document (master.tex):

\documentclass[a4paper]{article}

\usepackage[backend=bibtex]{biblatex}
\bibliography{../bib.bib}

\begin{document}

\section{Introduction}
LaTeX is a high-quality typesetting system \cite{latex}.

\printbibliography
\end{document}

The bibliography file with a web reference (bib.bib):

@online{latex,
    author = {LaTeX project team},
    title  = {LaTeX - A document preparation system},
    publisher={Frank Mittelbach},
    date={2015-04-03},
    urldate   = {2016-02-13},
    url    = {https://latex-project.org/}
}

That’s it! Additional thoughts might be to place the make.sh somewhere else and point the command to an absolute path to that file, which would then be project independent. The script would have to take parameters (the master file name and the absolute path to the project directory), which you could achieve with Texmakers special characters.

I hope that helps, thanks for reading!

Leave a Reply

Your email address will not be published. Required fields are marked *

go away! *