# Category Archive: TeX

## Current state of LaTeX on the iPad

Susan Donovan posted a review of the current state of things in the quest to do LaTeX on the iPad: Using LaTeX on the iPad: The best and worst apps for writing mathematics.

I haven’t tried most of these, I haven’t gotten much beyond installing TexTouch and playing with it a little bit. However, most of the alternatives that Susan reviews are really only alternatives if what you want to do is typeset mathematical formulas for papers or emails, being LaTeX-powered equation editors. I’d find such a thing potentially useful if it allowed drawing trees in emails (which is what I sometimes use LaTeXiT on the Mac for), but that’s not going to happen without pretty much a full local installation of LaTeX (so I can include pstricks and pst-jtree).

The remote compilation that TexTouch does, particularly since you can set it up against your own installation on a desktop machine synced with Dropbox, still seems like a pretty optimal solution for using full-blown TeX. Even if Apple’s guidelines didn’t prohibit it, I’m not at all convinced that I actually want a full TeX install on my iPad proper. My desktop machine has much more disk space and computational prowess, and I’m rarely using the iPad in a situation where it isn’t connected to the net.

## Sending EagleFiler metadata to BibDesk

I have a big EagleFiler archive in which I hold all of my PDFs, and as I add papers, I generally fill the “Title” field with the paper title and the “From name” field with the authors, as well as assign tags, etc. EagleFiler is generally my first stop when I acquire a new PDF. Plus, my EagleFiler library lives in my Dropbox, so I can get at these files from my iDevices as well.

However, when I want to add one of these papers to my bibliography, I have to go to BibDesk, make a new record, retype the title and author, and attach the PDF. And then I think: I should automate the export of the metadata someday.

Happily, that someday is today.

I have put together a simple Applescript that will look at the record(s) selected in EagleFiler, and create a corresponding new BibDesk record for each of them. It fills in the title, author, and source URL information from the EagleFiler metadata, attaches the file to the BibDesk record, and then does a couple of other things that are idiosyncratic to my particular filing system. In particular, it looks in the path to see if it is inside a “Journals” folder (in which case it is an article), or in “Monographs” (in which case it is a book), etc. It also looks to see if a tag called “look” was assigned in EagleFiler, and marks the “Read” flag in BibDesk if the tag is found. Obviously, these parts are only useful if you file things the way I do. But even if you don’t, it might be interesting to see how the script works.

I am no Applescript genius. In my initial tests, this ran kind of slowly, and there are probably better or more efficient ways it could be written, but it does seem to work.

Once a BibDesk record is created, the publication window is opened, and generally there needs to be some tweaking: fixing quotation marks, protecting capitals, fixing author lists to use “and” as separators, but it still saves some double-entry.

One installs Applescripts like this into ~/Library/Scripts/Applications/EagleFiler and then they are available via the scripts menu in the menubar.

-- Create a new BibDesk record from EagleFiler record
-- Paul Hagstrom, November 2010
--
-- This is probably kind of idiosyncratic.
-- My filing procedure is to have PDFs in EagleFiler with the
-- title in title
-- authors in from
-- There is very little chance that it will work without any need to edit
-- Maybe later I'll try to figure out how to tag things so that they'll
-- detect the right reference type, etc.

on run
tell application "EagleFiler"
set _records to selected records of browser window 1
repeat with _record in _records
set theTitle to _record's title
set theAuthor to _record's from name
set theSource to _record's source URL
set theFile to _record's file
set thePath to theFile's POSIX path
set theNote to _record's note text
-- special handling based on my idiosyncratic organization
-- look at the path to see if it is a journal or what
set theType to "article"
if thePath contains "Journals" then
set theType to "article"
end if
if thePath contains "Monographs" then
set theType to "book"
end if
if thePath contains "Dissertations" then
set theType to "phdthesis"
end if
if thePath contains "Edited" or thePath contains "WPL" or thePath contains "Conferences" then
set theType to "incollection"
end if
-- special handling of tags.  If something is tagged "look" it goes on the reading list.
set _tags to _record's assigned tags
repeat with _tag in _tags
if _tag's name is "look" then
end if
end repeat
tell application "BibDesk"
tell document 1
set thePub to make new publication at the beginning of publications
set type of thePub to theType
set title of thePub to theTitle
--at some point I might try to replace commas with "and"
--and if theAuthor starts with "ed." put it in the editor
--field instead, since that is my general convention in EF.
set value of field "Author" of thePub to theAuthor
tell thePub
set value of field "Read" to 1
end if
make new linked URL with data theSource at end of linked URLs
--at some point I might try to parse my filenames
--they are generally authorYear-source.pdf
--set value of field "Journal" to theJournal
--set publication year to theYear
set cite key to get generated cite key
end tell
show thePub
end tell
end tell
end repeat
end tell
end run


## A possibly better way to customize the TextMate LaTeX plugin

In the aftermath my recent adventures with a development version of a TextMate LaTeX bundle, I wound up reinstalling the original LaTeX bundle, but in the process lost my customizations for special citations and idiosyncratic inline linguistic examples.

I could have re-edited the bundle (that’s why I posted the instructions here, after all, so I could remember what I did), but I discovered a better way, looking at the TextMate manual section on language grammars and on the TextMate wiki: create my own language, subclassing the language from the LaTeX bundle, with just my additions. The advantage of this is that if I ever update the LaTeX bundle, the additions will continue to be mixed in.

This is in fact how the LaTeX Beamer language definition works, so there’s a ready-made example to look at. It defines a couple of special beamer-related things (frame and frametitle), and then includes the regular LaTeX language. So, I am doing just that. Note, though, that if I want to include the beamer specials, I need to include the beamer class. Since I don’t see any real harm in doing so all the time, I am extending that class which itself extends LaTeX.

Here’s how to do this: Go to Bundles > Bundle Editor > Edit Languages…, open up the LaTeX bundle and select the LaTeX Beamer language. Hit the duplicate button in the lower left corner to duplicate it. Then hit the add button and add a new bundle, call it something, and then drag the beamer duplicate into it. Name your duplicate something better, and click on it to edit it. Change scopeName to text.tex.latex.custom. You probably want to get rid of the firstLineMatch line as well, and change fileTypes to ( 'tex' );. The idea is that it will pick up any file with the .tex extension, without checking to see if it is a beamer file.

Then, just put in the additions. I left the beamer additions in, since I use those too. I couldn’t get an include line to work with text.tex.latex.beamer, maybe TextMate doesn’t allow nested includes. Even including both the beamer addition and the main LaTeX language didn’t work, in either order. So, I just left the beamer additions in.

For completeness, this is what I ended up with:

{	scopeName = 'text.tex.latex.custom';
firstLineMatch = '^\documentclass([.*])?{beamer}';
fileTypes = ( 'tex' );
foldingStartMarker = '\begin{.*}|%.*(fold)s*$'; foldingStopMarker = '\end{.*}|%.*(end)s*$';
patterns = (
{	name = 'meta.function.mot.latex';
contentName = 'string.quoted.mot.latex';
comment = 'Added by Paul Hagstrom';
begin = '((\)mot)({)';
end = '}';
beginCaptures = {
1 = { name = 'support.function.mot.latex'; };
2 = { name = 'punctuation.definition.function.latex'; };
3 = { name = 'punctuation.definition.mot.begin.latex'; };
};
endCaptures = { 0 = { name = 'punctuation.definition.mot.end.latex'; }; };
patterns = ( { include = '$base'; } ); }, { name = 'meta.citation.latex'; begin = '(?x) ( (\) # Marker (?:foot)?(?:full)?(?:no)?(?:short)?(?:poss)?(?:pg)? # Function Name [cC]ite (?:al)?(?:t|p|author|year(?:par)?|title)?[ANP]* *? # Optional Unabreviated ) (?:([)[^]]*(]))? # Optional (?:([)[^]]*(]))? # Arguments ({) # Opening Bracket '; end = '}'; captures = { 1 = { name = 'keyword.control.cite.latex'; }; 2 = { name = 'punctuation.definition.keyword.latex'; }; 3 = { name = 'punctuation.definition.arguments.optional.begin.latex'; }; 4 = { name = 'punctuation.definition.arguments.optional.end.latex'; }; 5 = { name = 'punctuation.definition.arguments.optional.begin.latex'; }; 6 = { name = 'punctuation.definition.arguments.optional.end.latex'; }; 7 = { name = 'punctuation.definition.arguments.latex'; }; }; endCaptures = { 0 = { name = 'punctuation.definition.arguments.latex'; }; }; patterns = ( { name = 'constant.other.reference.citation.latex'; match = '[w:.]+'; }, ); }, { name = 'meta.function.environment.frame.latex'; begin = '(?:s*)((\)begin)({)(frame)(})'; end = '((\)end)({)(frame)(})'; captures = { 1 = { name = 'support.function.be.latex'; }; 2 = { name = 'punctuation.definition.function.latex'; }; 3 = { name = 'punctuation.definition.arguments.begin.latex'; }; 4 = { name = 'variable.parameter.function.latex'; }; 5 = { name = 'punctuation.definition.arguments.end.latex'; }; }; patterns = ( { include = '$self'; } );
},
{	name = 'meta.function.frametitle.latex';
match = '((\)frametitle)({)(.*)(})';
captures = {
1 = { name = 'support.function.frametitle.latex'; };
2 = { name = 'punctuation.definition.function.latex'; };
3 = { name = 'punctuation.definition.arguments.begin.latex'; };
4 = { name = 'entity.name.function.frame.latex'; };
5 = { name = 'punctuation.definition.arguments.end.latex'; };
};
},
{	include = 'text.tex.latex'; },
);
}

## Tex Touch: LaTeX on the iPad that doesn’t even hurt much

I just took Tex Touch for a spin on the iPad, and actually did some substantial editing on a paper. It’s not as fast to type on an iPad as it is on a real keyboard, of course, but I’m pretty impressed with how it works.

The fundamental problem with TeX on an iDevice is that Apple forbids any kind of code compilation on the device itself, and so one couldn’t even in principle do a TeX install on the iPad (at least without jailbreaking, I don’t know what options are open for a jailbroken iPad). So, the only way to make it work is to do the compiling remotely. However, TexTouch makes the process pretty transparent.

Tex Touch allows you to connect yourself to a folder in your Dropbox account (and for the space you need, the free account will suffice), and then it will use that folder as a way to connect to your desktop machine, which needs to be running a program that will watch the folder and compile any TeX files that find themselves there. When the compilation is done, and the PDF file is produced, TexTouch picks it up and allows you to display it on the iPad. The folder watching function is accomplished either by the developer’s own program or by using Ramón Figueroa-Centeno’s LaTeXMe script. LaTeXMe is a Mac program, but Tex Touch itself is intended to also work with a Windows machine on the remote compiler end.

Once you have it set up, you barely realize that it’s being compiled remotely. You hit the “TeX!” button and the file is uploaded, it sits for a little bit, then downloads the PDF (or gives you access to the log).

The editor itself is nice too. No syntax coloring yet, but it has support for templates, and it has an elaborate keyboard setup that allows pretty simple access to brackets and slashes and commonly used LaTeX commands and symbols. After working with it briefly, I found it quite acceptable.

I’m looking forward to seeing how it develops, but this looks like the perfect solution for my own setup. I already keep all of my TeX work in my Dropbox folder anyway, so it’s pretty straightforward to copy over a file I want to work on when I’m away from my computer and get still something done. The only problem that I have had so far is that it didn’t find my bibliography file when it was remotely compiling, but I’m sure that (a) this is pretty easily solvable by adding a path to something somewhere, and (b) I’m unlikely to produce the final version of the PDF this way anyway, so I’ll always have a chance to recompile when I get back to my computer.

## A nicer LaTeX bundle for TextMate

When a document I was trying to compile kept alerting me to fatal errors, but scouring the log file failed to reveal anything that should count, I decided I’d poke around a little bit to see if there were any updates to the LaTeX bundle for TextMate. I found, first, that it seemed to have actually disappeared from the TextMate svn repository, but, second, that there is a relatively nice version maintained by Adam Strzlecki on github. I haven’t done a great deal of exploration, but it does seem to be a bit faster, and there are a few added niceties to the autocompletion mechanisms.

I updated to the new bundle, but since I had made some changes to the old one (see Adding a little bit to TextMate’s LaTeX bundle and More TextMate LaTeX language editing), I decided to fork the existing repository and add those in as well.

Additionally, at present, the current bundle chokes a little bit on files that are within folders that contain spaces in their names. Compilation still works, but the links to errors that you should get in the status window are broken, as is the “jump to corresponding location in the PDF” command. I’ve fixed both of these problems in my fork of the bundle (though it is possible that there are hidden problems I’ve introduced, particularly in the thing that processes error links, I haven’t tried it with a complex master document).

Update: The sad truth is, this is not ready for prime time yet, at least not for me. I rely heavily on the dvi-ps-pdf pathway, and this bundle seems to have disabled it. I tried for a while to re-enable it, but it just wasn’t cooperating. Maybe in the lazy days of Thanksgiving break, but for now I would recommend against installing this bundle.

To install my fork of the TextMate LaTeX bundle, you need to remove the old one (maybe just put it somewhere safe in case you want to go back to it) from ~/Library/Application Support/TextMate/Bundles/ (maybe also check in /Library), and disable or remove the built-in LaTeX bundle. (I, perhaps unwisely, just pulled it out of the .app: right-click on the TextMate application, show package contents, open Contents, Shared Support, and Bundles, wherein is LaTeX.tmbundle.)

To install the new bundle, you need to have git installed. If you don’t, there is some information at github about installing git on Mac OS X.

That done, open a Terminal window and type thusly:

cd ~/Library/Application Support/TextMate/Bundles/
git clone git://github.com/paulhagstrom/LaTeX.tmbundle.git


The next time you start TextMate, the new bundle should be active.

Now, back to that paper.

## TLU vs. TeXLive versions

Just like last year, when the preparations begin for the next version of TeXLive, it starts becoming difficult to use TeX Live Utility (a Mac GUI front end for tlmgr). Last year, this was a problem with the TLU app exclusively updating for 2009 before 2009 was released. This year, just now, there was a glitch (encountered upon updating tlmgr) that bumped my repository into thinking it is a 2010 repository. The signal was this:

tlmgr: package repository http://mirror.unl.edu/ctan/systems/texlive/tlnet
The supported release as specified by the repository (2009)
does not match the release version of the installation (2010), bailing out.


This can at least for the moment (and if it crops up again) be solved by forcing the repository to report 2009. What the repository reports is given around line 50 of TLConfig.pm, which for me was found here.

/usr/local/texlive/2009/tlpkg/TeXLive/TLConfig.pm

Maybe this will be useful to someone else (or to me, later).

## I spoke too soon

I swear it worked after the SL upgrade, but then it didn’t again. TextMate stopped compiling my LaTeX files. After a little bit of poking around, I saw that I have both python 2.5 and 2.6 installed. On what turned out to be a successful whim, I pointed the LaTeX bundle to python 2.5 instead of letting it default to python 2.6.

mate /Applications/TextMate.app/Contents/SharedSupport/Bundles/Latex.tmbundle/Support/bin/texMate.py


I changed the first line to point explicitly to python 2.5, and it worked.

#!/usr/bin/env python2.5 -u


## Snow Leopard?

My experience moving to Snow Leopard while preserving TeX was pretty much seamless, although I did need to reinstate /usr/texbin into my path. Check the MacTeX faq for Snow Leopard on how to get it back. I never knew about /etc/paths.d/ before, that’s also kind of nice trick to know.

## Even better BibDesk preview pane

Having been inspired by the preview pane template I just posted about, I created an even better one. It’s a HTML template, and it’s kind of a work in progress, but it does some interesting things. First: it will display the Skim notes. It will also pick up citations in the Cited-by and Cites fields (which I intend to use as “see also” links) and displays them as clickable links that will bring up the linked-to BibDesk record. It’ll print the abstract if there is one and the keywords if there are any (although I could not figure out how to make the keywords clickable).

The image on the right shows what it does. The red thing at the top is the cite key, the link below is to the PDF itself (and any linked files will appear there), then the keywords, then the links to the BibDesk records mentioned in the Cites field (format is “citekey1,citekey2,citekey3″). Below that the Skim notes.

There are two files that make up this template, one is the outer layer of the HTML page (betterHTML.html), and the other is the inner “partial” that is used for each item in the list (betterItemHTML.html). You can see how it works by reading through it. The code is below the fold (or click on the links just given to download them directly). To install, put these in ~/Library/Application\ Support/BibDesk/Templates/ (if you downloaded them, be sure to change the name so the extension is .html, not .txt) and then go to the Templates pane of the Preferences and add a new template. Give it a name, choose betterHTML.html as the file, and then select the new template and hit + to add a second file within the template. Add betterItemHTML.html as type Default Item. And, then, you should be able to select it as a display mode for one of your panes (I’d suggest the right-hand pane).

## BibDesk preview pane with Skim notes

I just came across this nice template for BibDesk that will display your Skim notes in a preview pane. My new BibDesk layout has the notes preview in the right-hand pane and the files preview in the lower pane. Also, note that in the files display, there is a hidden zoom control in the top center.

Get the “previewTemplate” here at Jim Harrison’s templates page . To install it, put previewTemplate.rtf in ~/Library/Application\ Support/BibDesk/Templates/ and then go into the BibDesk Templates preference pane, make sure nothing is selected, and hit the + button. Click on the new name twice slowly and give it a name like “previewTemplate”, and double-click on the file to choose the previewTemplate.rtf file you just put into your Library folder. Finally, select the previewTemplate from the template popup under the pane you want to put the preview template in.