Tuesday, May 25, 2010

Some Tools a Physicist Might Set Up on a Mac

This post is intended to remind myself of the tools I would want to set up on a new Mac, and also to serve as a resource for others who might be interested. A great resource that touches on many of these topics is "OS X Leopard for Physicists", which I will reference below.

Firefox


My browser of choice, primarily thanks to one particular plug-in. Zotero is a citation manager that sits inside Firefox. Most any source you navigate to on the web, be it a news article, a journal article, an abstract, an arXiv document, etc. will trigger an icon in the address bar, and you just need to click on it to import all the vital info into Zotero. It can save a snapshot of the page, or hold onto the full pdf document. It's made it much easier to keep track of the literature I've read.

emacs


Along with vi, this is one of the two heavy-hitter text editors that have been around for the long haul. There is a Carbon Emacs package available, but you can now easily install from source on OS X, getting the most up-to-date version, which I'd recommend. Instructions are available for Installing Emacs 23 on Mac OS X. It's a steep learning curve with simple things like opening files, saving, copying, etc. involving new key combinations you haven't used before, but I've found the end result is much more efficient editing. You can learn most everything you need to know about emacs by firing it up and spending some time running through the tutorial (press ctrl-h, then t).

As a random aside, Emacs installed this way doesn't inherit settings from your shell (or something like that), which means certain packages like AucTeX (for writing LaTeX documents) can't run terminal applications the way they'd like. To fix this, you have to create a ~/.MacOSX/environment.plist:

defaults write ${HOME}/.MacOSX/environment PATH "${HOME}/bin:/usr/bin:/bin:/usr/local/bin:/usr/texbin"


OpenAFS


In particle physics, AFS (Andrew File System) is the go-to standard for setting up computing systems for users. You can access all your files on AFS from your Mac by installing OpenAFS. This will mount /afs as a drive on your Mac. Further, you can create tokens that allow you direct write access to your home directories on AFS.

To access your Wisconsin HEP account, you'll need to make a few changes in /var/db/openafs/etc (you'll need administrative privileges, so preface any command with 'sudo'):

In ThisCell, add:
hep.wisc.edu
grand.central.org


In CellServDB, add any of these that don't exist:
>hep.wisc.edu           #University of Wisconsin -- High Energy Physics
128.104.28.219 #anise.hep.wisc.edu
144.92.180.7 #rosemary.hep.wisc.edu
144.92.180.30 #fennel.hep.wisc.edu


CMS Stuff


For those working on CMS, you can get the Fireworks event display software, which is a cinch to install and includes root along with the libraries needed to run FWLite analysis.

Enthought Python Distribution


The Enthough python distribution (academic) includes a modern version of python along with matplotlib (a fantastic plotting library) and a variety of other scientific tools for python. Comes packaged in an easy installer.

rootplot


If you've setup the Enthought distribution to give yourself matplotlib, you can get it to interface nicely with root through rootplot. The documentation page points to instructions for installing on OS X (requires building root).

LaTeX


You can start from an easy installation of MacTex, which will install LaTeX along with a bunch of fun tools like LaTeXiT, where you can write LaTeX snippets and drop the pdf or png image into a presentation (in Keynote, you can even drag it back out to LaTeXiT and it will remember the source!).

JaxoDraw


JaxoDraw is a Java application which provides a graphical interface for drawing Feynman diagrams based on the axodraw LaTeX module. "OS X Leopard for Physicists" provides some good advice for setting it up to work correctly in OS X, particularly the paths to dvips and LaTeX and choosing "open" for text editor and Postscript viewer.

VirtualBox


On occasion, I have found a few tasks where I wish I were working a native Linux environment. For this, I found it astonishingly easy to set up a virtual Ubuntu machine through VirtualBox. Once VirtualBox is installed, all you need is an Ubuntu disk image, and it will walk you through the steps to create your new virtual machine.

Wednesday, February 17, 2010

Random Setup Things for Mac

From BrainLog, instructions for getting Ctrl-left and Ctrl-right working like you expect in the terminal:

  • From the Terminal menu, select Window Settings..., then select "Keyboard" from the dropdown menu.
  • Click on "control cursor left" from the menu, then click the Edit button.
  • Click the little "delete" button until the text box is empty. Now press ESC, then "b"; the box should now contain "\033b". Click OK.
  • Do the same for "control cursor right," using ESC then "f" as the character sequence.

Monday, February 15, 2010

Changing Fonts in a PDF File

I tried an experiment this evening to see if a PDF can be successfully edited as a text-file, and the results are fairly promising. I wanted to achieve plots with all text in Minion Pro so they would match the body text in a LaTeX document I am preparing. I took the brute-force approach of performing replacing every instance of "Helvetica-Bold" with "MinionPro-Bold"; "Helvetica-BoldOblique" with "MinionPro-BoldItalic"; "Helvetica" with "MinionPro-Regular", etc. And it worked!

The only real problem with this method is that a PDF has the characters individually placed, so character spacing looks a little funky with the new font. Some characters take up more or less space between the two fonts. Even so, I thought this was a pretty neat trick.

On a related note, I was able to get ROOT to use an arbitrary font for internal display of plots. The program is supposed to be limited to the 14 fonts included in the font table (which is not modifiable), but you can game the system by simply replacing the font file with a different one. For example, you can navigate to $ROOTSYS/fonts/ and copy comic.ttf over all the arial*.ttf files. Now, whenever ROOT wants to use Arial (which is the default), it actually loads Comic Sans.

Now, the ideal would be for ROOT to magically gain the ability to export LaTeX files the way that some other programs like Matlab and gnuplot can, so that all the text is directly rendered by the pdflatex engine, giving the correct size and identical rendering. But I don't have my fingers crossed on that one. I think I can hack something pretty reasonable out of what I've found so far.

Wednesday, February 10, 2010

Installing the MinionPro Tex Package

I have recently gone through the somewhat difficult process of installing the MinionPro package for use with TeX / LaTeX on my Mac, but now it works. I followed the nice instructions on the nice instructions available through this blog:

http://carlo-hamalainen.net/blog/?p=8

But I found I needed a little fiddling. Here's what I did:


cd ~/Desktop

texmf_folder=~/Library/texmf/

curl http://mirror.ctan.org/fonts/mnsymbol.zip > mnsymbol.zip

unzip mnsymbol.zip
cd mnsymbol/tex
latex MnSymbol.ins
mkdir -p $texmf_folder/tex/latex/MnSymbol/
mkdir -p $texmf_folder/fonts/source/public/MnSymbol/
mkdir -p $texmf_folder/doc/latex/MnSymbol/
cp MnSymbol.sty $texmf_folder/tex/latex/MnSymbol/MnSymbol.sty
cd ..
cp source/* $texmf_folder/fonts/source/public/MnSymbol/
cp MnSymbol.pdf README $texmf_folder/doc/latex/MnSymbol/
mkdir -p $texmf_folder/fonts/map/dvips/MnSymbol
mkdir -p $texmf_folder/fonts/enc/dvips/MnSymbol
mkdir -p $texmf_folder/fonts/type1/public/MnSymbol
mkdir -p $texmf_folder/fonts/tfm/public/MnSymbol
cp enc/MnSymbol.map $texmf_folder/fonts/map/dvips/MnSymbol/
cp enc/*.enc $texmf_folder/fonts/enc/dvips/MnSymbol/
cp pfb/*.pfb $texmf_folder/fonts/type1/public/MnSymbol/
cp tfm/* $texmf_folder/fonts/tfm/public/MnSymbol/

sudo mktexlsr
sudo updmap-sys --enable MixedMap MnSymbol.map

curl http://mirror.ctan.org/fonts/minionpro/scripts.zip > scripts.zip
mkdir minionpro-scripts
cd minionpro-scripts
unzip ../scripts.zip

find /Library/Fonts/ -iname '*minion*pro*otf' -exec cp -v '{}' otf/ ';'
sudo apt-get install lcdf-typetools
./convert.sh

mkdir -p $texmf_folder/fonts/type1/adobe/MinionPro/
cp pfb/*.pfb $texmf_folder/fonts/type1/adobe/MinionPro/

# It turned out to be very important to get this 2.030 version; a mismatch gives missing characters!
curl https://lists.berlios.de/pipermail/minionpro-devel/attachments/20090814/4e956ea2/attachment.zip > enc-2.030-beta.zip
curl http://mirror.ctan.org/fonts/minionpro/metrics-full.zip > metrics-full.zip
curl http://mirror.ctan.org/fonts/minionpro/metrics-base.zip > metrics-base.zip
curl http://mirror.ctan.org/fonts/minionpro/metrics-opticals.zip > metrics-opticals.zip

cd $texmf_folder
unzip ~/Desktop/metrics-base.zip
unzip ~/Desktop/metrics-full.zip
unzip ~/Desktop/enc-2.030-beta.zip

sudo mktexlsr
sudo updmap-sys --enable MixedMap MnSymbol.map

Sunday, January 31, 2010

Setting Up CMS Tools on My Mac

I finally decided to install some CMS tools on my Mac today, and was surprised at how easy it was. With one download of the Fireworks event display package, you get not only Fireworks, but also ROOT and FWLite. An informal page on the TWiki gives instructions for setting up your Mac for FWLite using this Fireworks installation. What I did was to include the basic content of the root.sh script he creates in my .bashrc on my Mac:

export CMSSW_BASE=/Users/jeff/Work/cmsShow34
export ROOTSYS=$CMSSW_BASE/external/root
export LD_LIBRARY_PATH=${CMSSW_BASE}:${CMSSW_BASE}/external/lib:${ROOTSYS}/lib
export DYLD_LIBRARY_PATH=${CMSSW_BASE}:${CMSSW_BASE}/external/lib:${ROOTSYS}/lib
export PATH=${ROOTSYS}/bin:$PATH


Next, I wanted to get PyROOT (the Python interface to ROOT) working. Looking through the documentation on PyROOT, I was able to get the basic information needed, but it took a little fiddling. I added the necessary lines to my .bashrc,

export LD_LIBRARY_PATH=$(addto $LD_LIBRARY_PATH $ROOTSYS/lib)
export PYTHONPATH=$ROOTSYS/lib:$PYTHONPATH

but there was a mismatch of Python versions that gave me an error message. The solution was to force the use of Python 2.5.x by calling python2.5 rather than python, which can even be specified in the "shebang" of a script: #!/usr/bin/env python2.5.