Hugo Touchette

Tips for scientific users of Mac OS

Setting a master BibTeX file

If you're tired of creating a BibTeX file for every paper you write, you should consider putting all your BibTeX entries in one big .bib file - a master bibfile. There are several advantages:
Here are a few tips for creating a master BibTeX file using BibDesk:

Creating sub-bibfiles with bibextract, citetags and citefind

bibextract, citetags and citefind are Unix shell programs created by N.H.F. Beebe for extracting bibentries from a BibTeX file. The syntax for each of them is:
bibextract[patterns] [bibfile] > [output-file]
This extracts bibentries containing the listed patterns.
citetags [.aux-file] > [output-tag-file]
This extracts the citation tags of all the references cited in a LaTeX document. The citation tags are extracted from the corresponding .aux file.
citefind [output-tag-file] [bibfile] > [output-file]
This extract from the bibfile the bibentries corresponding to the citation tags listed in the file created by citetags.
Here are few tips for installing and using these programs:

Vary your LaTeX fonts!

Donald E. Knuth designed the font 'Computer Modern' (cmr) as the default font for TeX. The advantage of cmr, apart from being a nice font to read, is that it offers math fonts (cmmi, cmsy, etc.) that match the text font (cmr). Other fonts can be loaded in TeX or LaTeX, but they don't always have matching math fonts. There are a few exceptions, however, and it's worth having a look at them if you're getting tired, as I am, of reading cmr. Here are a few links to start varying your fonts:

Using times math fonts with the mathtime package

Times is not my favourite font, but it can be useful sometimes - for example, to check the correct length of Physical Review papers prepared with REVTeX4. There are many options available for using the times font in your document.

diction and style: Two GNU programs to check your writing

diction and style are two old command-line GNU programs, found in Fink as an unstable package. The two programs are discussed in the book 'Mathematical Writing,' by Donald E. Knuth, Tracy Larrabee and Paul M. Roberts.
From the diction man page (style is included in diction):
The two programs won't teach you how to write, but can be useful in spotting obvious and less-obvious errors, such as 'wicked whiches' ('which' that should be 'that'), repeated and lookalike words, passive sentences, etc. Style is also useful in that it outputs a 'school year' index telling you that your text is at the level of a 'year N' student.

Running Mathematica remotely using X11

Here are some information for setting up Mac's X11 to properly display Mathematica sessions running on a remote server:
My own installation works more or less fine: it still crashes from time to time and has some problems displaying 3D plots, but it's reliable enough that I can use it.

Exporting Mathematica plots with transparency effects (filling)

Mathematica 6.0 now offers transparency effects in plots using the Filling option. The problem is that transparencies cannot be exported in eps. They can in pdf, but Illustrator CS doesn't display the pdf generated by Mathematica correctly. What to do?
Source: Jen Nöckel's tips page

Scheduled backup of your mac with rsync and launchd

Don't risk loosing your data, music and pictures - do regular backups! And don't trust yourself to do it manually - have your mac to do it with the unix command rsync and Apple's job scheduler launchd. Here's how:

Introduction to LaTeX

Useful material about LaTeX:
  1. Create a directory in your home directory, e.g.,
    mkdir latex
  2. Tell TeX where your directory is by adding the following command into your .cshrc file (that's your shell profile file):
    setenv TEXINPUTS ~/latex//:
  3. Reload your profile file by running the command 'rehash' or by re-opening a terminal window.

Using MetaPost to create eps and pdf figures

MetaPost is a powerful (and somewhat intuitive) programming language devised by John D. Hobby for creating postscript and pdf figures. It is based on Donald E. Knuth's MetaFont program and is much easier to use than postscript. For an example of the capabilities of MetaPost, see its wikipedia entry. The best thing about MetaPost is that figures can be generated algorithmically, as MetaPost is a programming language.

MetaPost is part of the TeXLive distribution of LaTeX. It is invoked to create eps figures with the command
To create pdf figures instead, type
Some remarks:
More information about MetaPost:
In addition to TikZ-PGF, there's a LaTeX package, called mfpic, that allows one to include metapost-like commands directly into a tex file to produce figures. (I say 'metapost-like' because the syntax of mfpic differs slightly from that of metapost.) The figures are rendered with this package by calling in sequence (pdf)latex, metapost, and then (pdf)latex again. An example of the use of mfpic can be found in TeXShop's help pages.

Personally, I prefer to use metapost as a standalone to produce pdf figures, which I then include in my latex documents using the standard \includegraphics macro. This way, I don't need to rely on the publishers of my papers to produce my figures.

Rendering of contour plots in Mathematica 7

For some reasons, Mathematica (v7) doesn't render contour plots very well with the 'Export' command or with the 'Copy as' selection. The problem is that the mesh of contour plots appears as fine white lines in the exported graphic. This bug is discussed by Jens Nockel.

The solution posted by Jens Nockel is to add the following code in the 'Export' command:
Export["plot.pdf", im1 /. {EdgeForm[], r_?(MemberQ[{RGBColor,
Hue,CMYKColor, GrayLevel}, Head[#]] &), i___} :>{EdgeForm[r], r, i}]
This assumes that the plot is contained in 'im1'; the exported plot will go in the file 'plot.pdf'.

Getting started with Mathematica

Things to change after installing OS X Mountain Lion

Annoyingly, there are many things to change and tweak after installing Mountain Lion:

Producing pdf files with PSfrag

The LaTeX package PSfrag is useful for producing figures with LaTeX font labels. The problem is: we're in the age of pdflatex and PSfrag is a postscript machine. How to use it to obtain pdf files? Here are two solutions - one that doesn't work (at least for me) and one that does:

Things to change after installing OS X Mavericks

Postscript generated by Mac not compatible with PSfrag

iDraw is a nice and cheap alternative to Illustrator, which I've started using with good results so far. Unfortunately, although iDraw imports native postscript, it doesn't export in ps or eps.

To go around this, I tried printing in a ps file with the usual printing panel of Mac. But then I realized the ps generated is not compatible with PSfrag - I can't seem to replace text labels with PSfrag, apparently because the ps generated doesn't use the standard 'show' command.

Here's a solution (after some fiddling):
With that, ciao Illustrator!

Bibtex style file (bst) for Birkhäuser journals

I submitted recently a paper to the Annales Henri Poincaré, managed by Birkhäuser and Springer, and was surprised to see that they don't have a customized bibtex .bst file for styling references. Springer has one for their svjour article style, but I couldn't find anything for Birkhäuser's birkjour article style, so I made one with
latex makebst
This is a nice script asking all sorts of questions about how you want to style your references and generating a bst style file according to your answers.

Looking at the Birkhäuser's style, I generated the following file


which comes close to what I see. Feel free to use and distribute.

Things to change after installing OS X Yosemite

This is becoming a classic after installing a new OS update:

Modifying auto-complete commands in TeXShop

TeXShop introduced at some point auto-completion of subscripts _{} and superscripts ^{} which I find annoying. To disable them, delete these items from the plist located in

Mathematica 10 uses fonts that dvips can't see

Another version of Mathematica - another font problem. For reasons I couldn't figure out, dvips (which I use for psfrag) can't see some of the fonts used in eps files generated by Mathematica. The problem seems to be that Mathematica has changed its font filenames, but I'm not sure.

Before I can find the culprit, here's a quick fix:
Not particularly nice, but that seems to clean the font calls and dvips works.

Update 10/08/2015: Do not change the fonts in Mathematica using Style or PlotTheme. This also conflicts with psfrag.

Update 31/01/2018: The font bug is fixed in version 11, except when using legends. I filed a bug report with Wolfram.

Filtered sync based on Mac tags

Mac users will have noticed (since Maverick I think) the appearance of colored tags in the Finder, which can be used to sort out files. This added information does not appear natively in the terminal window (using for example ls -la). But a neat add-on, called tag, can be used for that. To install
brew install tag
To list your files with the tags showing, just type
tag -l *
Alternatively, search for files matching a tag with
tag -m [tagname] *
I found tag after thinking of a way to copy the papers I download everyday from the physics arxiv to a dropbox folder, so I can read them wherever I am. I have the habit of color-tagging them with a yellow tag called ToRead, so I can use tag to sync them using
tag -m ToRead ~/Downloads/* | xargs -J % cp % ~/Dropbox/ipad/
Even better: I could rsync them.

Things to change after installing OS X El Capitan

The usual story:

Things to change after installing Mac OS Sierra

Surprisingly not many, but:
Update 08/11/2016: Aspell was updated for Sierra.

Things to change after installing Mac OS High Sierra

The new Mac OS High Sierra has been a real pain in the neck since its distribution. After a failed first installation and later updates (with frozen screens), here are the remaining bugs I'm trying to live with:

Bluetooth headset bug with Mac OS Catalina

Since upgrading to Mac OS Catalina, my Sony bluetooth headphones (WC500) give a screeching/cracking sound when switching between songs on iTunes (now Music). This seems to be a known bug. I fixed the problem following this Youtube video from Tony Cassara. In addition to checking the option 'Force use of AptX', you should select the option 'Disable AAC'. The AAC codex seems to be the culprit.

Hyperlinking titles in BibTeX using doi

In this age of internet, it makes no sense to provide a reference section printed in black on white without doi links to the papers we cite. Most journals provide links and the doi's themselves are provided by publishers so we should use them.

But how to generate the links? Most of the packages available on ctan (e.g., urlbst) print the link after a reference and hyperlink it with the hyperref package. But who wants to read a link? We only want to click a hyperlink, preferably over an article's title, as RevTeX does when using the longbibliography option. I tried to hack the RevTeX bib file to get similar results, but couldn't find the useful code.

Luckily, Andrew Comech worked out a nice solution consisting of a script he's written that transforms a bst file into a doi-link-enabled bst file. Genius. For an example, see the bst file produced by Nick Higham from the University of Manchester.

Technical point: Andrew Comech's script doesn't work with the sed shipped with Mac - it uses GNU's sed, which is slightly incompatible with Mac's sed. To fix this, install gnu-sed with
brew install gnu-sed
and override Mac's sed with
export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"
as explained on stackoverflow.

Things to change after installing Mac OS Big Sur

A few things, not surprisingly, given that Big Sur is a major update.

Conda and terminal settings

After installing Conda (miniconda to be precise), I realised that my terminal prompt was modified and that my exec paths weren't working. This is known side-effect of Conda, related to its environment localisation, that can disabled with the following command:
conda config --set changeps1 False
To revert back:
conda init --reverse

zsh shell on Mac

Mac OS Catalina introduced zsh as its default shell, although it is not enabled by default. To start using zsh, enter
chsh -s /bin/zsh
The settings file for zsh is .zshrc. I moved my own settings (latex and bin paths) from the .bashrc and .profile files to that file.
Copyright © HT 2020