Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

As in the title, I'd like to be able to select whether TeXShop uses biber or BibTeX in the document rather than using the command line or changing the default in the TeXShop preferences.

For TeX engines this is easy; i.e. you can put the following somewhere near the top of your TeX file

% !TEX TS-program = pdflatex

to tell TeXShop to compile with pdflatex, regardless of the default in the preferences. Does such a directive exist for bibliography passers? I want to be able to hit ++B for this. Latexmk provides the ability to do this, but I want to do compilations manually.

Final note

The solution involved a shell script. I've made this available on GitHub, so please feel free to use and improve it.

share|improve this question
add comment

3 Answers

Beginning with version 3.21, this feature is provided (by this very request!).

From the release notes:

The next feature was requested by Alan Munn about a year ago. Apologies for the delay. In the meantime, Mark Everitt wrote an ingenious script to provide this feature. The feature provided by that script is now built into TeXShop.

The command BibTeX in the TeXShop typeset menu runs BibTeX; notice that this command has a keyboard shortcut. In Japan, a different program is used instead, so Yusuke Terada provided an item in TeXShop Preferences under the Engine tab to select the program to be run when this menu item is selected. Examples are bibtex, biber, pbibtex, etc. The Preferences item can also be used to add flags to the command.

In TeXShop 3.21, the BibTeX engine can be selected on a file-by-file basis using the syntax

% !BIB TS-program = 

The alternate syntax

% !BIB program = 

will also be accepted. The item after the equal sign gives the name of the program (for instance biber) and any required flags. This line should be written within the first twenty lines of a source file.

The % !BIB TS-program = line takes precedence. If it is absent, the Preference item determines which command is run.

So, all you need to do is update your copy of TeXShop (it should have asked you to do so).

share|improve this answer
add comment
up vote 18 down vote accepted

I solved this is a mildly hacky way. First of all, I wrote a script called TeXShopBib.sh which looks like

#!/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

and placed it somewhere TeXShop will find it (just /usr/texbin for quick testing in my case). Make sure the script's executable bit is set. If you have saved the script in /usr/texbin then you need to issue the command:

sudo chmod +x /usr/texbin/TeXShopBib.sh 

Then I simply altered the preference to pick up this script as the BibTeX engine.

enter image description here

If the TeX file has a line that looks like

% !BIB TS-program = biber

or

% !BIB TS-program = bibtex

in the first 20 lines then it figures the rest out and works properly with the TeXShop console, in a similar way to how TeXShop handles TeX engines. This script crudely defaults to BibTeX when nothing is detected in the tex file, but is no more sophisticated than necessary for my purposes. If there is any interest in this then I can make it more robust.

share|improve this answer
1  
Thanks, Mark. This is much nicer than my hacky way. –  Alan Munn Dec 16 '11 at 16:06
1  
I should also note that this solution will work with other editors on both OS X and Linux; it's not actually TeXShop specific. –  Alan Munn Dec 16 '11 at 16:14
1  
Indeed. It seemed simpler than grappling with applescript. –  qubyte Dec 16 '11 at 16:17
    
Incidentally, are there any scripts for other platforms that read the % !TEX... line meant for TeXShop? –  qubyte Dec 16 '11 at 16:26
1  
TeXWorks can use TeXShop's lines @egreg and I were just discussing this in chat. –  Alan Munn Dec 16 '11 at 16:52
show 1 more comment

Unfortunately no. This would be a very useful thing to have, but it doesn't exist at the moment. There's been some discussion of it on the TeX on MacOS mailing list, but nothing came of it on the development side.

Here's a hacky kind of workaround:

  • Make a biber engine
  • At the top of your file put:

    %# !TEX TS-program = biber
    % !TEX TS-program = pdflatex (or whatever regular engine the file uses)

When you want run biber on the file, remove the # from the first line and hit +T; since the biber engine is the first line, it will be run first.

This isn't as convenient as having the engine run automatically with ++B, but it helps a bit.

share|improve this answer
    
Aye, that is unfortunate. Not really digging the engine option though, since it means working with a split panel and editing. Maybe it's possible to write a script that looks at the first 20 lines for something like % !BIB TS-program = ... and runs bibtex or biber based upon the extracted argument. Wrapping it in an applescript would allow it to be added to the TeXShop menus and a hotkey combination assigned... –  qubyte Dec 15 '11 at 5:56
    
I'll think about that. –  qubyte Dec 15 '11 at 5:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.