TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm doing a report that is heavy in R but also would like to use system fonts, so I was hoping to be able to use Sweave and XeLaTeX.

My preferred tex editor is TexShop (Mac 10.7), but it seems to only allow me to select either Sweave or XeLaTeX. I can produce a .tex file from Sweave and then manually run that through the XeLaTeX engine after adjusting the packages/fonts, but it seems like there must be an easier way.

It looked to me like RStudio had this functionality, but when I chose XeLaTeX as the typesetter it yields the error: [object Uint8Array]' is not a valid argument for 'Function.prototype.apply', which looks like some sort of C-based code. The Sweave document that produces that error is:


pdfLatex compiles it fine. Resources I checked on using XeLaTeX and Sweave don't address this issue as far as I've been able to see.

share|improve this question
up vote 8 down vote accepted

The easiest way to do this is to make yourself a Sweave-XeLaTeX engine file for TeXShop. To do this, do the following.

  • Using the Go menu in the Finder, navigate to the TeXShop Engines folder by choosing Go and then entering ~/Library/TeXShop/Engines
  • Make a Copy of the Sweave engine and rename it Sweave-XeLaTeX
  • Open the engine in TeXShop and change the line

     pdflatex "${1%.*}"


     xelatex "${1%.*}"

Save the file, and restart TeXShop. You should now have a Sweave-XeLaTeX engine file in the dropdown menu next to the Typeset button.

You can also access the engine automatically in your .Rnw file by adding

% !TEX TS-program = Sweave-xelatex

as the first line of your file (you can choose this from the Macros -> Program menu item too.)

share|improve this answer
Thanks, works great! That's helpful in understanding how the different engines work too. – Señor O Dec 25 '12 at 4:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.