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:
- A master bibfile is much easier to manage (keep up to date, correct, expand, etc.) than the several bibfiles scattered around your computer.
- A master bibfile
is a centralised server of all
the references you're using for your research. If you use BibDesk,
you can also make your master bibfile the centralised server of the
pdf files of all the papers you've downloaded on your computer. For
that, you simply need to use the auto-file function of
BibDesk. Alternatively, you can use DOI
numbers to access
these papers. (Sounds a bit like Mendeley, but it's free and it's not owned by Springer or thieving Elsevier.)
- BibDesk can be
used to share BibTeX files on a
network.
- There are tools
that can be used to
extract the bibentries cited in a LaTeX file from the master
bibfile (see the next
tip). So
in the end you can always generate a specific bibfile
attached to a LaTeX document if needed.
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):
- Diction
identifies wordy and commonly misused
phrases.
- Style analyses
surface characteristics of a
document, including sentence length and other readability measures.
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.
- Update 05/12/2008:
diction and style seem not to be
listed in Fink anymore. They are available, though, via darwinports.
Be sure to
install darwinports
before.
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.
- Update 26/03/2008: New in Leopard (Mac OS
10.5): X11
(v2.1.4) shouldn't be launched from /applications/utilities, from the
dock or from its native location in /usr. Simply open an ssh session in
the terminal with the -X option. This should launch X11
automatically with the $DISPLAY variable properly set (test
with
echo $DISPLAY). The application responsible for launching X11 is called
launchd. More details here.
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?
- Avoid
transparencies.
- Export in pdf,
knowing that you won't be able
to edit the pdf file with Illustrator.
Source: Jen
Nöckel's tips page
- Update 07/09/09: The bug seems to be fixed in version 7. Transparencies are
now well rendered in pdf.
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:
- Create a
directory in your home directory, e.g.,
mkdir latex
- Tell TeX where
your directory is by adding the
following command into your .cshrc file (that's your shell profile
file):
setenv TEXINPUTS ~/latex//:
- Reload your
profile file by running the command
'rehash' or by re-opening a terminal window.
- Update 09/03/2010: Upgrading to Leopard may break
the symbolic links to LaTeX, BibTeX, epstopdf,
metapost (and much more) in the terminal. See Part d of
the answer to
Question QM.10 on the MacTeX
site to re-create the link.
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
mpost file.mp
To create pdf figures instead, type
mptopdf file.mp
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.
- Update 09/03/2010: The metapost engine was
changed in newer versions of TeXShop. The way the engine is called is
also changed: see the metapost section in TeXShop's help section.
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:
- html editor nvu no longer supporter. Use KompoZer instead (also discontinued - see dropinblog for a short history)
- Update DropBox to have the
folder status
icons again
- Update Java for Mathematica (done from the Mac update center)
- Update to TeXShop
3. This must be done directly from the website - the TeXShop
updater
doesn't do it automatically
- Update XQuartz
- Tweak the anti-aliasing or font-smoothing option for the screen
with
defaults -currentHost write -globalDomain AppleFontSmoothing -int 0
in the terminal. Or select best value from 0 to 4. An alternative is to
untick the 'Enable Font Anti-Aliasing for LCD screens' option in System
Preferences>General
I'm still having problem with this one: there seems to be no way to
disable the rgb sub-pixel
anti-aliasing of fonts in Preview and TeXShop. Annoying, but I can
survive.
Note added: I had a tour of the laptops in the Apple Store: except for
the retina ones (which look amazing), they all have rgb sub-pixel
smoothing on. So this seems to be the default and I've just been living
in a non-anti-alised world for too long.
- This one is really bizarre: After I switch off the sub-pixel
rendering, it will switch on again in the Mail program if an
attachment is shown as an image rather than an icon. To stop the online
previewing, type
defaults write com.apple.mail DisableInlineAttachmentViewing -bool yes
in the terminal. This solution is from sant
media.
- Show the Library folder in your home:
chflags nohidden /Users/USERNAME/Library
- Disable GateKeeper in your system preferences so you can install
third-party softwares
- FinkCommander no longer works - download MacPorts as a
replacement
- Installation of MacPorts
(be patient):
- Download latest version of Xcode from the App Store
- Xcode is not automatically installed from the App Store. This
needs to be done manually by starting the Xcode app in the Applications
folder
- After Xcode is installed, the Command Line Tool must be
installed in the Downloads section of Xcode's preferences: see help
- Finally, accept the Xcode license with
sudo xcodebuild -license
- Now download MacPorts
and install it
- Refresh your tree with
sudo port -d selfupdate
- Reinstall gnuplot from MacPorts with
sudo port clean gnuplot
sudo port clean aquaterm
sudo port install gnuplot
This
will re-install a whole bunch of programs, including aquaterm and X11,
for gnuplot to run properly. The installation will take a while to
finish. After that, get rid of Gnuplot.app
- Re-install Octave
from
MacPorts (stable version 3.2 or developer version 3.4). That didn't
work for me: I get compilation errors, so I'm staying with my old
Octave.app.
- Replace the 'Duplicate' option (new in Mountain Lion but useless)
by the usual 'Save as...' option
- Enable text selection in quick-look with
defaults write com.apple.finder QLEnableTextSelection -bool TRUE
Then restart the Finder.
- Change the ugly faux leather style of iCal (now Calendar) with Mountain Lion Tweaks
- Same for Contacts (what were they thinking?)
- Change the scroll bar direction in System Preferences>TrackPad
(the iPhone-like default is
counterintuitive)
- Custom Mail to the classic view (a matter of taste)
- Old Microsoft Office suit no longer supported - buy new version
- Other geeky tweaks at github
- After updating to iPhoto'11: Change the option in
Preferences>General to send photos from the mail program. The email
editor of iPhoto is buggy.
- Notes don't sync anymore via iTunes when you plug your iPhone.
They only sync via iCloud. This is stupid.
- Calendar stopped syncing via iTunes for some unknown reasons. You
must delete the Calendar sync cache to solve this problem as explained here
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:
latex $1.tex
dvips -o $1.ps $1.dvi
pstopdf $1.ps
pdfcrop --hires --margins 2 $1.pdf temp.pdf
mv temp.pdf $1.pdf
rm -f $1.ps
rm -f $1.dvi
The '--margins 2' option in pdfcrop puts an extra 2 points to the
boundary box - this can be changed to any value. Use ps2pdf instead of
pstopdf if the latter doesn't work.
To produce the desired pdf figure, type
psfragpdf latex_file_name_without_extension
Things to change after installing OS X Mavericks
- Re-install Java, X11 Quartz, and Flash.
- The pdf preview of TeXShop is not as responsive, in terms of
rendering, as under Mountain
Lion (barely perceptible but anoying nevertheless). Some reports
the new App Nap feature introduced in Mavericks to
be responsible for this. To disable App Nap for TeXShop, type
defaults write TeXShop NSAppSleepDisabled -bool YES
This does not really seem to fix the problem for me, though.
- Ghostscript seems to be broken on Mavericks - apparently
because of a conflict with Ruby. To fix this, download MacGhostView and
use ps2pdf instead of pstopdf.
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):
- Export (natively) your iDraw figure in pdf
- Use pdftops to export that pdf in ps
- Use ps2eps to crop the ps to eps
- Use the final eps for PSFrag.
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
birkjourmock.bst
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
~/Library/TeXShop/Keyboard
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:
- Generate figures in Mathematica in pdf
- Convert the pdf figures in ps with pdftops
- Convert the ps figure in eps using ps2eps.
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:
- CocoAspell is broken.
This is bad news for latex.
- Re-install an old version of Java runtime for Octave.
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:
- Had to re-install my local printer, which uses the SAFECOMM
distribution system where I work. The lpd queue no longer works - I had
to install the printer via Samba, as explained on the Ubuntu/Linux side of our IT!
- Documents won't print when sent from Mac Mail or when they
include non-standard ps fonts (anything but times or helvetica basically). This bug seems to be related to the fonts
not being embedded in pdfs. I tried 'Save as pdf' or converting to
pdf-x to no avail.
Update 23/03/2018: Some genius on the HP forum finally suggested a fix on ppd files that works. And he/she's not working at HP or Apple!
- The printer queue gets jammed with 'Waiting for
authentification...'. This has to do with authentification not always
being enabled. There is no way to force this from the Preference Pane
- you have to go under the hood in the terminal, following the
instructions given here.
- Opening .txt files in TextEdit, quickly scrolling down to the
bottom, to see that the file is cut before the end (i.e., not all the
content shows up). This seems to be related to Apple's change of drive
encoding. I'm scared to think that all my files have been re-encoded...
- A slow Mac - that's the new normal at Apple it seems. One
culprit is spotlight indexing in the background - feels slower than
before. TextEdit and Preview also take forever to open.
- The only plus side I could find is that the anti-aliasing of
fonts used in Preview and in the pdf viewer of Safari are the same and
- about time! - they look good. I should say that I'm still living in
pre-retina world.
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.