Sweave Engine for TeXShop

November 17, 2008
By

(This article was first published on cameron.bracken.bz » R, and kindly contributed to R-bloggers)

Sweave is an awesome utility for including the output of R code in a LaTeX document which I have started using regularly.

TeXShop is my favorite editor/viewer for LaTeX under Mac OS X for many reasons. One of which is the speed of the edit -> compile -> view process which it enables. Therefore, I have been reluctant to use Sweave in the past because of the extra LaTeX compilation step that is not supported by default in TeXShop.

Recently, my friend Charlie Sharpsteen first showed me this way to get around this with a custom “engine”. The engine file looke like this:

Sweave.engine

#!/bin/bash

export PATH=$PATH:/usr/texbin:/usr/local/bin
R CMD Sweave "$1"
pdflatex "${1%.*}"

Place this file in ~/Library/TeXShop/Engines/, make sure PATH includes the location of you TeX distribution.

Make sure executable permissions (like 744) are set on both files or TeXShop will give an error message. Now open (or re-open) TeXShop and select “Sweave” from the list at the top left. Now you can use command-t to compile Sweave and view your document in one step! Thanks Chuck!

To leave a comment for the author, please follow the link and comment on his blog: cameron.bracken.bz » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.