33

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.

3 Answers 3

24

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.

8
  • 2
    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, 2011 at 16:14
  • 1
    Indeed. It seemed simpler than grappling with applescript.
    – qubyte
    Dec 16, 2011 at 16:17
  • Incidentally, are there any scripts for other platforms that read the % !TEX... line meant for TeXShop?
    – qubyte
    Dec 16, 2011 at 16:26
  • 1
    TeXWorks can use TeXShop's lines @egreg and I were just discussing this in chat.
    – Alan Munn
    Dec 16, 2011 at 16:52
  • 1
    It's been some time since I've used TeX, but the last time I looked this script had inspired a feature within the editor. See the 3.21 release notes here (also for usage): pages.uoregon.edu/koch/texshop/version.html
    – qubyte
    Jun 24, 2015 at 21:46
20

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

4
  • Awesome! Can you cite this or point to the documentation for more information? Thanks!
    – jvriesem
    Jun 24, 2015 at 17:28
  • 2
    @jvriesem I'm not sure how much more official you can get than the release notes, which are linked :) Jun 24, 2015 at 18:48
  • Wow, my bad. I totally missed the link. I thought that was all your own writing. Thanks, and sorry for causing trouble! :-)
    – jvriesem
    Jun 26, 2015 at 16:41
  • @jvriesem Not at all! The links can be hard to spot :) Jun 26, 2015 at 16:44
7

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.

2
  • 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, 2011 at 5:56
  • I'll think about that.
    – qubyte
    Dec 15, 2011 at 5:56

You must log in to answer this question.

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