Last Updated: February 25, 2016
·
2.449K
· qubyte

Switch to select BibTeX or biber.

Originally discussed on TeX.sx: http://tex.stackexchange.com/questions/38348/in-texshop-is-there-a-directive-to-select-biber-or-bibtex-on-a-per-document-bas

Repo with code can be found at: https://github.com/qubyte/BibDirective

With TeXShop, TeXworks and some other TeX IDEs, the TeX engine to use can be selected near the top of the file with a directive like:

% !TEX TS-program = pdflatex

Bibliography management is shifting from BibTeX, which is showing its age, toward biber in the community. Unfortunately there is no similar directive in these IDEs for bibliography engine. I decided to code one myself in bash. By using the code below, and telling your IDE that it is the bibliography engine, you can use the usual hotkeys, and select the engine you want near the top of the file with:

% !BIB TS-program = bibtex

or

% !BIB TS-program = biber

The code:

#!/bin/sh

filestem=${1%.*}
bibtype=`head -n20 "${filestem}.tex" | sed -n 's/\%[ ]*![ ]*BIB[ ]*TS-program[ ]*=[ ]*\([a-z]*\)/\1/p'`

if [ -z $bibtype ]; then
    echo "No option detected in TeX file. Defaulting to BibTeX."
    bibtype="bibtex"
else
    echo "Option $bibtype detected in TeX file."
fi

eval $bibtype $filestem

1 Response
Add your response

Inspired by this tip, the TeXShop developers have integrated support for bibliography engine selection. See http://pages.uoregon.edu/koch/texshop/version.html

over 1 year ago ·