When I want to include a numerical table in a LaTeX document I often already have the data collected together in a Numbers spreadsheet with the desired layout. For example, I might want to go from:

to

The following TextExpander snippet (gist) lets me simply copy the data from Numbers, including the column headers, to the clipboard, and then insert it into a LaTeX document as a nicely formatted table by typing ;ptable:[1]

The script assumes centred justification of each column. A limited amount of table formatting can be specified in the Numbers data: any cells in the topmost row can include a pipe character | to indicate that this column should be bounded by a vertical line on the right side, e.g. column 1 | will add a c| format string to the begin{tabular}{FORMAT} code in the LaTeX header via the define_format method.

Inspired by a similar workflow by Dr Drang for copying tables from Numbers to Markdown. ↩

Inspired by Eddie Smith’s post on working with LaTeX in Sublime Text 2, I am experimenting with doing just that. While it is going to take me a while to get to grips with all the power-text-editing-goodness inside Sublime Text 2, I have been poking around inside the syntax highlighting, and the result is TeXShop Extended; as the blurb says, a light theme designed for LaTeX in TextMate / Sublime Text. This is based on my colour scheme in TeXShop, with extensions for additional syntax highlighting for \ref, \label, \cite, \footnote, math environment, and others. The .tmTheme file also supports syntax highlighting for \caption and \mathrm, provided these are listed in the LaTeX.tmLanguage file.

The .tmTheme file is available as a gist. Caveat emptor, etc. I have only tested this theme with RevTeX files, and your mileage may vary with standard LaTeX.

A short rb-appscript script that opens a new window in Terminal in the current working directory on a remote machine. This is much quicker than launching a new window and having to cd manually when you are deep in your directory hierarchy:

Last week I posted a script for extracting the contents of note annotations from PDFs. An alternative approach uses the comprehensive scripting library of PDFpen.[1] One advantage of this method is that the notes, which inherit from the imprint class, are contained within separate pages, allowing page numbers to be accessed. The AppleScript is as follows:

tell application "PDFpen"
set finalResult to ""
set pageNumber to 0
repeat with aPage in pages of document 1
set pageResult to ""
set pageNumber to pageNumber + 1
repeat with theImprint in imprints of aPage
if the class of theImprint is equal to note then
set theResult to rich text of theImprint
set pageResult to pageResult & "* " & theResult & "
"
end if
end repeat -- imprints
if pageResult is not equal to "" then
set finalResult to finalResult & "page " & (pageNumber as string) & ":
" & pageResult
end if
end repeat -- pages
end tell
set the clipboard to the finalResult

This script can be accessed from inside PDFpen by saving it to /Users/name/Library/Application Support/PDFpen/Scripts, or combined with a Open Finder Items action in Automator to build a Service. Running as a Service will crash the AppleScript above if the PDF has not finished opening. Adding the following code makes the main Applescript wait before trying to process the PDF:

Today I was trying out ReaddleDocs on the iPad for reading PDFs of papers. This app is not as full-featured as GoodReader but it importantly supports syncing of entire folders with Dropbox, and I like the cleaner interface.[1]

While apps like this make it very easy to annotate PDFs with comments, which can then be synced across all your devices through the power of Dropbox, getting these comments back out again once you get back to your Mac can be a pain.

This is a ruby script that uses the pdf-reader gem to find all the comments in a PDF document and copy them to the clipboard:

This script can be accessed as a Service with the following setup in Automator:

The only complication here is Automator’s insistence on using the system version of ruby (1.8.7) instead of v. 1.9.3 I have installed elsewhere in my path, which meant that the service initially could not find the pdf-reader gem. This was fixed by reinstalling pdf-reader into the system gem path with /usr/bin/gem install pdf-reader.

I would also like to be able to pull out highlighted text, and to add a page number to each comment in the copied output, but these appear to be advanced topics.[2]

Update: An alternative workflow using AppleScript and PDFpen is described here.

I use Papers for cataloguing PDFs, which has made it a lot easier to keep track of numerous resources when researching a field or writing a paper.

Papers will automatically generate cite keys; identifier strings that can be used to reference a publication in a manuscript. For example, in LaTeX publications can be referenced using \cite{CITE_KEY} and the bibliographic information included in a bibliography section at the end of the document, or extracted from a linked bibTeX database. While Papers has the noble goal of generating “universal cite keys” to allow collaborating authors to keep compatible library databases, I came to Papers with a large bibTeX database and my own cite key scheme. This scheme defines cite keys as follows:

Single author: [Surname]_[Journal][Year], for example Morgan_JImprobRes2012.

Two authors: [First_Surname][Second_Surname]_[Journal][Year] for example MorganAndCoauthor_JImprobRes2012.

More than two authors: [First_Surname]EtAl_[Journal][Year]
for example MorganEtAl_JImprobRes2012.

This is usually sufficient to uniquely identify any paper in my library. In the case of duplicate entries from particularly prodigious authors I then append letters e.g. MorganEtAl_JImprobRes2012a

I find these cite keys more easily human readable than those generated by Papers, which are of the form Morgan:2012sj, or even the possible auto generated cite keys in BibDesk. When reading a LaTeX file I find it easier to remember which paper I referred to, since I can see the journal title, and have some idea about the number of authors. The second advantage is that these cite keys are easily human generated. If I want to reference a paper that is not yet in my database I can type in an appropriate cite key and carry on writing without having to worry about editing a BibTeX entry until later.

Unfortunately Papers does not support user defined cite keys, and editing the metadata by hand is a one of those tasks that only takes a few seconds but becomes tedious for a large number of papers. As a workaround I now use a TextExpander snippet that builds a cite key from the metadata present in Papers.[1] This runs the following ruby script:

This uses appscript[2] and some GUI scripting to access the Papers command “Copy as BibTeX Record” to extract the metadata for the currently selected paper. The rest of the script is straight Ruby, and prints the appropriate cite key.

The end result is that I can edit the auto-generated cite key for the selected paper and type ;cite to change the entry to my own format.[3] This is one of those little reductions in friction that makes life better.[4]