I’ve always had problems with MiKTeX on my work computer. I can install it just fine, or get IT to install it, but then the package manager doesn’t work because of our firewall. You can set up a local repository to get around this problem, and I will show you how. I’m just doing a basic setup here, just enough to compile the RStudio Rmd template to PDF.

“Why do I need MiKTeX?”, you might ask. Well, because if you want to create a PDF from an RMarkdown file in RStudio it is required. Otherwise you get this polite error message.

RStudio: No pdflatex error message

I downloaded the 32-bit basic version from https://MiKTeX.org/download.

MiKTeX Basic 32-bit Download

You’ll probably just want to pick the default options for the install EXCEPT for the question that asks whether you want MiKTeX to install missing packages automatically. I’m saying “no” to that because that is where the firewall gets in the way.

Say "no" to automatic package installs

MiKTeX will update your PATH system variable, but to get RStudio to recognize that it has changed you will need to restart it. Trying to knit the RStudio Rmd template to PDF right after install gives a new error, that it cannot find the file “url.sty”. Actually, if you had done the default install, MiKTeX would have tried to install the needed package automatically. But, this would have just failed if the needed port is not open on your firewall.

One way to get the packages you need is to create a local package repo and install the packages “manually”.

I’ve created a github repo with a minimal set of LaTeX packages to get this working, https://github.com/adamleerich/miktex-repo. So, you can clone it straight, download a ZIP, or fork and clone. Up to you. I’m going to assume you know how to get these files from github and put them somewhere inside your firewall. I’ve put mine in a folder called c:\home\git\Other\miktex_pkgs.

Next, open the MiKTeX package manager on your computer, the admin version. It was just installed. Select change package repository from the repository menu. It will then ask you what kind of repo you want.

You want a local repo

On the next screen browse to the folder where you cloned the git repo, and point to the “repo-local” subdirectory.

You can send me an email if I've lost you

MiKTeX will take forever to synchronize the package database, but once it is done, you can select the packages you want installed. Unfortunately, I have not been able to figure out how to create an index file that just has the downloaded packages in it. So, the package manager will still list all of the packages available at the CTAN mirror. I know, it sucks. But, to not have to worry about this you can just run the batch file scripts\100-mpm-install.bat as an admin and it will install the packages for you.

If you decide you want to add more packages to your local repo, just put the file name in the DOWNLOAD file and re-run the scripts scripts\050-download-locals.bat and scripts\100-mpm-install.bat.

Let me know if this helps or if it doesn’t work for you.