TeXShop automatic completion of quotation marks and other things

Go to Preferences and check the selection called “key bindings” in the source panel. Enjoy.

OS X Computer Modern Roman and other CM fonts

If you open a document/figure in Adobe Illustrator that has some LaTeX associated with it, you often run into a problem where Illustrator does not recognize the font (can’t remember what the error says, but it’s obvious and it complains you are missing CMR fonts or something along those lines). Download these fonts and install them to fix this issue: http://mactex-wiki.tug.org/wiki/index.php/Typefaces#TeX.2FIllustrator_Fonts

Notes: I don’t think you need to install them in the specified directory, try opening up “Font Book” and installing them directly there and give Illustrator a go. If you want to avoid this issue altogether, I think you can also tell Illustrator to not interpret the fonts in a postscript figure.

Really neat website for OS X command line tweaks

This website has a great list of all the things you can change in OS X through command line:

https://github.com/mathiasbynens/dotfiles/blob/master/.osx

It gets updated often. Some useful ones that I found:

# Disable shadow in screenshots
 defaults write com.apple.screencapture disable-shadow -bool true

# Allow text selection in Quick Look 
 defaults write com.apple.finder QLEnableTextSelection -bool true

# Expand save panel by default 
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true

# Expand print panel by default
 defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true

# Show item info below desktop icons 
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:showItemInfo true" ~/Library/Preferences/com.apple.finder.plist

# Enable snap-to-grid for desktop icons
 /usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist

Ah… and yes, if you see emoticons, you win.

Useful scripts for capitalizing and down casing fields in BibDesk

Sometimes, when you get references, the fields are all uppercased and you can’t do anything about it (see below). Sometimes this translates to screwing up your bibliography depending on the style you choose, especially when you’re dealing with author names.

One option is to go in and manually field capitalize every first letter and down case everything else individually. The smart choice is to automate it and that’s what this fine fellow has done. Check out

http://people.reed.edu/~ahm/
http://people.reed.edu/~ahm/Projects/Citation/BibDesk/

and download FieldScripts.zip. Unzip and drag to the appropriate place and then you can use the scripts by hitting the AppleScript menu and then selecting “Field Capitalize.”

What is nice about the script is that you can select multiple files and field capitalize all of the in one shot. Useful if you have to format a ton of articles to put in a bibliography/reference list.

Note you have to install a suite of scripts available on sourceforge. You can find those at http://sourceforge.net/apps/mediawiki/bibdesk/index.php?title=BibDesk_Applescripts.

Adding system paths to/using external UNIX tools from the MATLAB command line

Sometimes you try to run a command in MATLAB and you get this

>> !unixtooltorun
 /bin/bash: unixtooltorun: command not found

To fix this we need to add the appropriate bash paths to the initialization script in MATLAB. I’m doing this in OS X but I assume it’s not much different in other operating systems. Go to where your MATLAB package is located.

Right click and “Show Package Contents.” Then navigate to “bin/matlab” and right click and open it up with the text editor of your choice (i use TextMate).

Edit right below where the comments end by adding whatever paths you want to include.

For example, to add the paths to use ImageMagick and some common image/format conversion tools in OS X (installed through TeXLive, check to make sure whether you have 20xx installed on your system) add the following two paths:

export PATH="$PATH:/usr/local/bin/"
export PATH="$PATH:/usr/local/texlive/2011/bin/universal-darwin/"

In MATLAB, to use ImageMagick’s convert tool, we can type either

>> !convert blah.eps blah.jpg

or

>> system('convert blah.eps blah.jpg');

I find this particular package extremely helpful when creating figures in formats other than EPS. Usually, MATLAB does a terrible job in handling raster type formats (PNG, TIFF, etc.). What I end up doing is printing to EPS format and then converting using them to a raster format using ImageMagick’s convert command. This has been the most reliable way for me to control, in some sense, my figure quality in MATLAB. I’ll make a post later on creating images, converting images, and creating animations in MATLAB by dumping EPS files.

Hope that helps!

All the LaTeX packages, macros, and fonts that you will ever need in one file

So this is it. It’s everything that I can think of. I use this as the start of all my TeX documents. I’ll update it if I can think of anything.

%\documentclass[a4paper,11pt]{amsart}
\documentclass[a4paper,10pt]{article}
%% PREAMBLE -------------------------------------------------------------------
\usepackage{geometry} % See geometry.pdf to learn the layout options. There are lots. This sometimes screws up the the placement of text.
%\geometry{letterpaper} % ... or a4paper or a5paper or ...
%\geometry{landscape} % Activate for for rotated page geometry
%\geometry{margins=2in} % change margins
\usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty line rather than an indent
\usepackage{graphicx} % add graphics capabilities
\usepackage{lineno} % To add line numbers
\usepackage{amsmath} % AMS operators and symbols
\usepackage{amssymb} % AMS operators and symbols
\usepackage{bm} % Define \bm{} to use bold math symbols
\usepackage{epstopdf} % allow use of .eps graphics with pdflatex
\usepackage{setspace} % http://www.ctan.org/pkg/setspace
\usepackage{color} % Allow color support
\usepackage{subfigure} % subfigure support
\usepackage{float} % http://www.ctan.org/tex-archive/macros/latex/contrib/float/
\usepackage{placeins} % ftp://ftp.ctan.org/tex-archive/macros/latex/contrib/placeins/placeins.txt
\usepackage[bookmarks,colorlinks,breaklinks]{hyperref} % Add hyperref type links in the document, colors
\definecolor{dullmagenta}{rgb}{0.4,0,0.4} % #660066
\definecolor{darkblue}{rgb}{0,0,0.4}
\hypersetup{linkcolor=red,citecolor=blue,filecolor=dullmagenta,urlcolor=darkblue} % coloured links
\usepackage{natbib} % for other bibliography things
\bibpunct{(}{)}{;}{a}{,}{,}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png} % convert tifs and pngs
\graphicspath{{graphics/}} % add other graphics path instead of ./

% Show labels inline for easy referencing
\usepackage[inline]{showlabels,rotating} % to show labels on equations
\renewcommand{\showlabelfont}{\scriptsize \slshape \color{red}}
\renewcommand{\showlabelsetlabel}[1]{
\begin{turn}
{0}\showlabelfont #1
\hspace{15pt}
\end{turn}
}

% To put little todo items
\newcommand{\todo}[1]{ \vspace{5 mm} \par
\noindent \framebox{
\begin{minipage}
[c]{0.94 \textwidth}
\tt #1 \flushright ... todo
\end{minipage}
}
\vspace{5 mm} \par
}
%% SPACING --------------------------------------------------------------------
%\doublespacing
%\linenumbers
%% MACROS ---------------------------------------------------------------------
\let\vaccent=\v % rename builtin command \v{} to \vaccent{}
\renewcommand{\v}[1]{\ensuremath{\mathbf{#1}}} % for vectors
\newcommand{\gv}[1]{\ensuremath{\mbox{\boldmath$ #1 $}}} % for greek letters
\newcommand{\uv}[1]{\ensuremath{\mathbf{\hat{#1}}}} % for unit vector
\newcommand{\abs}[1]{\left| #1 \right|} % for absolute value
\newcommand{\avg}[1]{\left< #1 \right>} % for average
\newcommand{\grad}[1]{\gv{\nabla} #1} % for gradient
\let\divsymb=\div % rename builtin command \div to \divsymb
\renewcommand{\div}[1]{\gv{\nabla} \cdot #1} % for divergence
\newcommand{\curl}[1]{\gv{\nabla} \times #1} % for curl
\newcommand{\eq}[1]{Equation~(\eqref{eq:#1})}
\newcommand{\fig}[1]{Figure~\ref{fig:#1}}
\newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}} % partial derivative
\newcommand{\pdd}[2]{\frac{\partial^2 #1}{\partial #2^2}} % partial double derivative
\newcommand{\diffd}{\mathrm{d}} % differential d
\newcommand{\dd}[2]{\frac{\diffd #1}{\diffd #2}} % derivative
\newcommand{\ddd}[2]{\frac{\diffd^2 #1}{\diffd #2^2}} % double derivative
\newcommand{\boldnabla}{\mbox{\boldmath$\nabla$}} % vector div
\newcommand{\bolddelta}{\mbox{\boldmath$\delta$}} % vector Laplacian
\newcommand{\conj}[1]{\overline{#1}} % overbar conjugate
\newcommand{\real}[1]{\mathrm{Re} \left[ #1 \right]} % more clear real
\newcommand{\imag}[1]{\mathrm{Im} \left[ #1 \right]} % more clear imaginary
\newcommand{\order}[1]{\mathcal O \left( #1 \right)} % order of magnitude
\newcommand{\eee}[1]{\mathrm{e}^{ #1 }} % exponential raised to
\newcommand{\ii}{\mathrm{i}} % imaginary unit i
\newcommand{\markchange}[1]{\textcolor[red]{#1}} % marks changes in text 

% FONTS -----------------------------------------------------------------------
%% Sans Serif for EVERYTHING
%\renewcommand{\familydefault}{\sfdefault}
%\usepackage{sfmath}
%% Fourier for math | Utopia (scaled) for rm | Helvetica for ss | Latin Modern for tt
%\usepackage{fourier} % math & rm
%\usepackage[scaled=0.875]{helvet} % ss
%\renewcommand{\ttdefault}{lmtt} %tt
%
%% Latin Modern (similar to CM with more characters)
%\usepackage{lmodern} % math, rm, ss, tt
%\usepackage[T1]{fontenc}
%
%% Palatino for rm and math | Helvetica for ss | Courier for tt
%\usepackage{mathpazo} % math & rm
%\linespread{1.05} % Palatino needs more leading (space between lines)
%\usepackage[scaled]{helvet} % ss
%\usepackage{courier} % tt
%\normalfont
%\usepackage[T1]{fontenc}
%
%% Euler for math | Palatino for rm | Helvetica for ss | Courier for tt
%\renewcommand{\rmdefault}{ppl} % rm
%\linespread{1.05} % Palatino needs more leading
%\usepackage[scaled]{helvet} % ss
%\usepackage{courier} % tt
%\usepackage{euler} % math
%%\usepackage{eulervm} % a better implementation of the euler package (not in gwTeX)
%\normalfont
%\usepackage[T1]{fontenc}
%
%% Times for rm and math | Helvetica for ss | Courier for tt
%\usepackage{mathptmx} % rm & math
%\usepackage[scaled=0.90]{helvet} % ss
%\usepackage{courier} % tt
%\normalfont
%\usepackage[T1]{fontenc}
%
%% !! COMMERICAL FONT !! Lucida Bright (w/expert package)
%\usepackage[T1]{fontenc}
%\usepackage[expert,vargreek,altbullet]{lucidabr}
%% FRONT MATTER ---------------------------------------------------------------
\title{Title}
\author{Andrew A. Tchieu}
%\date{} % Activate to display a given date or no date
%% MAIN MATTER ----------------------------------------------------------------
\begin{document}
\maketitle
%\begin{abstract}
%\end{abstract}

%\section{Introduction}

%\section{Formulation}

%\section{Results}

%\section{Discussion}
%\cite{zannetti:ejmb2005a}
%\cite{kivotides:el2004b}

%% BIBLIOGRAPHY ---------------------------------------------------------------
%\bibliographystyle{plain}
%\bibliographystyle{plainnat}
%\bibliography{/Users/atchieu/Dropbox/Library/library}

\end{document}

Yea, it’s super long and it looks terrible in WordPress, but I don’t care.

Setting up BibDesk to manage your library of books, references, and media

I am not going to tell you that BibDesk is the best reference management software in the world. The truth of the matter is that there are a TON of software for reference management out there and each one is a bit different and someone in the world will tell you that this one is better than that one. You can go through this massive list yourself:

http://en.wikipedia.org/wiki/Comparison_of_reference_management_software

I am just going to tell you that I use it, why I use it, and how I use it.

Why I use BibDesk

These are not all the reason’s i use BibDesk, but they are the most important ones to me.

  • It’s free
  • It’s natively based from BibTeX (I do a lot of scientific writing)
  • It can populate all fields (title, author, publication year, etc.) automatically
  • It files away my documents automatically
  • It’s frequently updated and maintained
  • And did I mention it’s free?

My only beef is that it does NOT automatically download articles from the web for you, but maybe this is a good thing because maybe you don’t wan’t all that bulk of keeping the files on your local system. But it does give you a link to where you can find the article which might be the next best thing (through web of science).

Now that I think of it, the only other thing is that you have to be an OS X user. My recommendations if you are a Windows or Linux guy is to look at JabRef or KBibTeX, which are very similar and also natively based on BibTeX.

How I use BibDesk

I use to manage my one true library. I even sync it up to Dropbox so that I can have the same library at all my computers. And this is not exclusively academic articles although this post is mainly focused on such. I include all my PDF books in this library (cookbooks, science fiction, art, and more). Lets start with setting up BibDesk from scratch.

Setting up BibDesk

I’m going to go through my preferences (hit Cmd+,). The ones I don’t mention are typically the default ones (so hit “Reset All” if you are unsure). Save a file called “library.bib” or some manifestation of that somewhere you’ll remember. Make a folder called “Files.” You can see I put mine in my Dropbox folder so that it syncs to all my devices.

1. General Application Behavior

Always open up your “library.bib” when opening BibDesk. You are going to keep only ONE library for all your documents.

2. TeX – Typset Preview

I like to generate a preview just to make sure that I know whether my bibliography has some kind of mistake that will keep it from compiling later. If you did screw up somewhere, do a manual binary search on your library by generating previews to figure out whether there is a mistake and where it is.

A preview looks like this at the bottom frame (click the glasses icon, I’ve selected three references here).

3. Cite Key Format (SUPER IMPORTANT)

BibDesk can automatically generate cite keys for you (if you don’t know what this is, this is a very important identifier when you write TeX based documents that links the information in your library.bib to your article). You need this key to be unique and optimally, constant once you’ve created it. So think long and hard and keep it the same for the rest of your life. If you change it, you risk the chance that your previous articles and documents, if you’ve made some updates to the references and they are compiled with TeX, will not compile your bibliography correctly. You can use any cite key format you want. This is what I use. I choose lowercase cite keys because with old journals, the imported author name is capitalized and it annoys me. Check the preview to make sure it comes out how you want it. You will be copying these things to your TeX documents (or TeXShop has an autocomplete feature that is pretty neat).


4. Autofile (SUPER IMPORTANT)

This does wonders. It automatically files the documents (PDF, MS Word, etc.) that you drag and drop onto the reference away in a specified location with a specified file naming convention! You don’t really care where they go, because you won’t ever have to look for that one article again, you’ll just go to BibDesk and search for the article and then double click on the document (I’ll show this later).

In this preference pane, I tell BibDesk to file the papers automatically so that when I drag and drop them, they get put in the specified location. For the local filename format, I use a very descriptive filename because I always like to look at the top of my file and see what I’m reading when I have a ton of PDFs open. Therefore, I file them away in a folder designated by the author then the file name has the author, publication year, and title (don’t forget the extension). This is a lot of description in a title, but I think it is worth it. You can copy my settings below.


Using BibDesk

So now you’ve setup BibDesk, but have no references. We are going to go through and get a reference for you to see how it is done.

Searching for articles

Using VPN or your institution network and Web of Science (or PubMed, etc.)**

(January 21, 2013, NOTE: The recent update to Web of Science has broken a few things!!! I’ll update when I figure out if I can get it working…)

This is my primary choice of how to search for new articles. In fact, if I have already downloaded an article, I will do another search to make sure I get the correct information for my BibTeX entry using this method (as opposed to inputting it in myself). This is because IT’S ABSOLUTELY RELIABLE (unlike Google Scholar, see below). If using Web of Science for example, it even gives you the link to where you can find the article (provided you are on your campus network).

First, you need to be able to access the institution resources by either registering your computer with them or setting up your VPN or something similar to access articles from the web. You might need to contact your local IT people to get this setup (or, god forbid, do a google search). But usually, if you are plugged in with a hardwire and you have registered your MAC address, you’re good to go. If you are at home and used VPN to connect to your institution’s network, you’re also good to go. Note, using a proxy server will not help you in using BibDesk. This is essential for me, because I want to do searches from BibDesk and not from a web browser, so that I can import them more quickly.



After this, go to searches and click on, for example, “Web of Science SCI.”



You’re going to have to learn some syntax and you are going to learn by example. Here is an example that encompasses all the syntax I use for Web of Science.



Press enter, and all these articles should pop up (maximum is 100 of the most recent). These really are the only things that I use to search for articles. If i see something on the web in a browser, I go to BibDesk and search the author (and maybe put in a year to cut down the number that popup)

au = authors
py = publication year (range)
so = journal name
* = match any pattern
and/or = be careful of using and/or, put quotes around it you want to use it in the search

If you want to know more about syntax, click on the “?” mark on the right of the search dialog. It’ll pull up some information about the syntax you can use.

Now click on the “import” button to the left of any of the articles. Then click on your “Library” in the left pane. You should see the article sitting there with all the data imported. You have your first reference! Note that in the right pane, if you got it from Web of Science, will be a webpage where you can download the article. You can download the PDF by double clicking on that webpage (it makes you jump through a few hoops but you eventually get to it in less than 15 seconds).

Once you download the PDF, get this PDF and drag it on top of the reference that it belongs to and drop it in. Your reference will be removed from wherever it was before and filed using the format you gave in the preferences! AUTOMATICALLY! Where does it put it? You don’t really care because you can always get back to the PDF by looking at the right side pane and double clicking on the file!



And there you go. Your first article in BibDesk (with the PDF on the right hand side in the above image). Just double click on the PDF and you will pull it up in your default PDF viewer. No more losing those PDF files and no more manual renaming in some obscure naming convention that changes every time you try to remember it.

Using Google Scholar (or other web-based)

You can also use Google Scholar (no VPN necessary) to download reference information. It’s quite finicky and also the information is not guaranteed to be completely accurate. Go to scholar.google.com using your browser. I always have to re-login in Google, go into settings, check the “show BibTeX citation download.” Once you have this turned on, there will be a small link that says “Import into BibTeX.” Click on this link for the specific article you are interested in. And copy what comes up by selecting it and pressing Command + c. Then go to BibDesk, Publication > New Publication from Clipboard. There you go. It should have pasted in the reference. Since google scholar makes its own cite key, BibDesk will not replace it with the one you defined in the Preferences. Therefore, if you want to reformat the key to you cite key, just go ahead and hit Command + K.

Drag and drop

Sometimes you just have the PDF and don’t want to look for the article. You can drag and drop the PDF straight onto the BibDesk icon and it will try its best to import missing information. This MIGHT work for newer articles. When available, BibDesk will extract metadata (or maybe it uses OCR?) when you drop a PDF into the library and fill some of your articles information for you. It’s not very reliable though, because you don’t know which journals have started doing this. Of course, older articles will not have this data. This is why I just end up going to the Web of Science technique described above to search and import articles.

Searching for articles you already have in your library

There’s a dialog for this up in the right upper corner. Use it. Make sure you select your “Library” on the left pane if you want to search your whole local library.


What if I already have a library of references somewhere and want to import them?

If there are just a bunch of jumbled PDFs somewhere, just start from scratch and spend a few hours sorting through them and importing them into BibDesk using the method I described above. It’ll help you learn too. If you have a huge library built from some other reference management software (that files away your PDFs), if it is natively BibTeX you might have a chance in importing it, but in general you won’t be satisfied until you start from scratch again. The one thing about any of these softwares is that there is a huge startup time if you already have a library built from somewhere else. It is a pain to get it in, no matter what software you use (although Mendeley will try to auto parse some things if you drag and drop your documents into it, but ultimately it will get about half of them wrong so that you have to go in and check/correct them anyway).

What is your non OS X choice?

If BibDesk didn’t exist and I had to choose an alternative, I’d probably choose JabRef or compile KBibTeX for OS X.

Parting remarks

Stay tuned for how to use this library in a .tex document using BibTeX.