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 have written an engine to run Sweave (a preprocessor) from TeXShop. It works fine on simple projects.

For complicated projects (e.g. books), I might want to run the preprocessor on a chapter (e.g. Chapter.Rnw), then run latex on the main file (e.g. Book.tex), which will include the processed chapter text using \input{}. The previewer should then show me Book.pdf.

If I set the TEX root to Book.tex, then my engine is called with Book.tex, the preprocessor never sees Chapter.Rnw, and it doesn't work. My preprocessor can be told that Book.tex is the main latex file, and the Sweave engine can run pdflatex on that file, but I can't see a way to tell TeXShop that Book.pdf should be shown in the previewer.

I asked a similar question recently on the TeXWorks mailing list, and in that case I was able to install a post-typesetting hook that determined the output file by examining the console log after running. Is there anything similar in TeXShop, or is there a way for my engine to send a message to TeXShop to tell it which file to preview?

Edited to add:

I have a partial answer.

Sending a message to TeXShop can be done using Applescript. For example, from the command line, this will open the PDF /path/to/my.pdf:

osascript -e 'tell application "TeXShop" to open "path:to:my.pdf"'

Be careful about the quoting; in your shell, it might be different.

This will open a second copy if the file is already open as a preview, but will not open a second copy if one was already opened this way. Is there a way to designate this file as the preview for the current compile, so I don't get a second copy?

Edited again to add:

And another partial answer is to use

%!TEX root = Book.Rnw

in every file in the project, and make sure that the Book.Rnw file somehow triggers the other files to be run through Sweave. (This is easy using my patchDVI package; it is probably also possible using Makefiles or latexmk.)

share|improve this question

Your Answer


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

Browse other questions tagged or ask your own question.