Using MiKTeX with R for Windows

This page is written about R 2.1.1 or earlier. The methods described in it should not be necessary since the release of R 2.2.0, unless MiKTeX changes again.

Recent versions of MiKTeX can be used with the R for Windows build system, but only with some changes to their configuration. Symptoms of needing these changes are failures to run the LaTeX step in checking a package or building the manuals.

We know of two changes that are needed with MiKTeX 2.4 (released in November, 2003):

Putting Rd.sty on the search path

For one or two versions, MiKTeX has been ignoring the TEXINPUTS environment variable that most other TeX distributions use to indicate additions to the search path. The R make process uses TEXINPUTS to add $RHOME/share/texmf to the search path, so that the Rd.sty style file will be found.

Instead of using TEXINPUTS, MiKTeX uses the command line option "-include-directory=foo", to prepend foo to the search path.

There are four workarounds to this.

Workaround 1: If you don't mind losing the e-tex engine, then you can switch to the old TeX engine, and TEXINPUTS works fine. Do this as follows [but see the note below: this may not work for you!]

1. Run the MiKTeX options program, choose the TeX formats page, and then for each program that you want to use the old engine (e.g. latex, pdflatex, etc.) do the following:

2. Click on the Edit button,

3. Choose "TeX" or "pdfTeX" as the compiler,

4. Click Apply,

5. Click Build

Workaround 2: If you want to keep the e-tex engine, but you don't mind always searching the R style file, then just hard code it into localtexmf/miktex/config/miktex.ini. You don't need any options in that file unless you want to override the standard ones. For example:

;; miktex.ini: the MiKTeX local configuration file

[LaTeX]

;; where LaTeX searches for input files
;;Input Dirs=.;%R\etex\latex//;%R\etex\generic//;%R\etex//;%R\tex\latex//;%R\tex\generic//;%R\tex//
Input Dirs=.;f:/R/rw1091/share/texmf//;%R\tex\latex//;%R\tex\generic//;%R\tex//

[pdfLaTeX]

;; where pdfLaTeX searches for input files
Input Dirs=.;f:/R/rw1091/share/texmf//;%R\pdfetex\latex//;%R\pdfetex\generic//;%R\pdfetex//;%R\pdftex\latex//;%R\pdftex\generic//;%R\pdftex//;%R\etex\latex//;%R\etex\generic//;%R\etex//;%R\tex\latex//;%R\tex\generic//;%R\tex//

[pdfTeX]

;; where pdfTeX searches for input files
Input Dirs=.;f:/R/rw1091/share/texmf//;%R\pdftex\plain//;%R\pdftex\generic//;%R\pdftex//;%R\tex\plain//;%R\tex\generic//;%R\tex//

[pdftexinfo]

;; where pdftexinfo searches for input files
Input Dirs=.;f:/R/rw1091/share/texmf//;%R\pdftex\texinfo//;%R\pdftex\plain//;%R\pdftex\generic//;%R\pdftex//;%R\tex\texinfo//;%R\tex\plain//;%R\tex\generic//;%R\tex//

[TeXinfo]

;; where texinfo searches for input files
Input Dirs=.;f:/R/rw1091/share/texmf//;%R\tex\texinfo//;%R\tex\plain//;%R\tex\generic//;%R\tex//

Workaround 3: Create shell scripts that make latex, pdflatex, etc. work like those of other distributions, by taking the TEXINPUTS environment variable and adding it to the command line before calling the MiKTeX programs. I haven't done this.

Workaround 4: Install the R style files into MikTeX. Remember to re-install updates when you upgrade R! Instructions for this were written by Gabor Grothendieck:

1. Create a new tex subfolder of your \localtexmf folder:

    md \localtexmf\tex

2. Copy your R .sty and .fd files into it:

 
     cd \Program Files\R\rw2001\share\texmf
     copy *.* \localtexmf\tex

3. Go into

 
     Start | Programs | MiKTeX | MiKTeX Options | General
and press Update Now and Refresh Now. (I am not certain that this step needs to be done but it can't hurt.)

4. You can check whether it is finding Rd.sty in the right place with the command:

     findtexmf Rd.sty

#2 - #4 need to be repeated each time one installs a new version of R if the *.sty or *.fd files have changed but if they have not changed then nothing at all needs to be done. It has the advantage that it leaves all MiKTeX options at their defaults and does not need a custom miktex.ini file.

[Added in February, 2005]:
The most recent version of pdftex no longer supports TEXINPUTS, even with the old pdftex engine, so Workaround 1 no longer works.

e-TeX compatibility mode

The November 2003 release of MiKTeX defaults to running e-TeX in enhanced mode, rather than TeX. This defines a few primitive functions which conflict with the ones used by older versions of the Rd.sty style, e.g. \middle.

If you used the TeX engine above, then this won't be a problem for you. If you want the e-tex engine, then you need compatibility mode.

To force MiKTeX to use e-TeX in compatibility mode, follow these steps:

1. Run the MiKTeX options program, choose the TeX formats page, and then for each program that you want in compatibility mode (e.g. latex, pdflatex, etc.) do the following:

2. Click on the Edit button,

3. Choose "e-TeX compatibility mode" as the compiler,

4. Click Apply,

5. Click Build

Comments?

Please send comments about errors in this file to Duncan Murdoch.