MiKTeX Behind a Windows Firewall

[This article was first published on TeachR, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.

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_pkgs. 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. 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.
Then you can 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 script ./scripts/050-download-locals.bat and then scripts\100-mpm-install.bat.

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

To leave a comment for the author, please follow the link and comment on their blog: TeachR.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)