How do I use R and Sweave with PCTeX?

To use Sweave in PCTeX, you will need to copy the tex and bibtex folders from R's share\texmf\ folder to PCTeX's texmf\ folder. If you should get a warning that there are already tex and bibtex folders, click Yes to continue copying.

There should now be a Sweave.sty file in PCTeX's texmf\tex\latex\ folder.

You will also need to go to PCTeX's Typeset menu, select INITeX, select LaTeX, put an asterisk in front of LATEX.LTX (i.e. *LATEX.LTX) in the "Macro file name" field, and click INITeX.

You can now typeset a Sweave file. There will be some missing packages, but PCTeX will offer to find and install those packages.

You can configure PCTeX to run Sweave by going to PCTeX's Settings menu, selecting Configure Tools, clicking Add Tool, opening the R.exe in R's bin folder, entering "CMD Sweave %f.Rnw" (without the quotation marks) in the Parameter field, and clicking OK.

Now when you have a Sweave .tex file open in PCTeX, you can go to the Tools menu, select R, and it will process the .Rnw file with the same name as the .tex file. PCTeX will notice that the .tex file has been changed and offer to load the new version.

Unfortunately, it's not possible to configure RStudio to use PCTeX. On my system, I was able to create a batch file that allows RStudio to use PCTeX, but it might not work if your RStudio uses different parameters than the one I downloaded.

To create the batch file, create a text file called "pdflatex.bat" in PCTeX's program directory (usually C:\Program Files\PCTeX\PCTeXv6\).

Inside the file, paste the following 6 lines:

if "%1"=="-synctex" GOTO Run
pdfetex %1
pdfetex --output-format=pdf "&latex" %5

RStudio should be able to find the batch file and use it to run PCTeX. You will need to typeset one Sweave .tex in PCTeX first to make sure that all the required packages are installed in PCTeX.

(Contributed by Kevin from PCTeX Tech Support)

Keywords: R, Sweave, tip, LaTeX