I have had, for approximately the last nine months, an R Studio/knitr/LaTeX problem. After spending several hours looking at it I have discovered that it was a TeX issue, and no fault of the other two. However, neither offered me any clue as to what was going on. I will detail this problem and the solution (TLDR: removed MikTeX and replaced it with TeXLive).
I am (co-)authoring another book. This one, like my data analysis book, is comprised of a master document with multiple child documents. The data analysis book was written with Emacs and Sweave, whereas this one is being written with R Studio and knitr. The problem I was having was that the book would compile fine on my Mac OS X machines, but under Windows I would get a message like
Running pdflatex.exe on chapter04.tex...failed, and the PDF viewer would not launch. I initially tracked this down to the inclusion of the
\makeindex command in my master document. In fact, through the use of a minimal example, I discovered that even after I took this command back out of the document, it would not compile until I deleted the auxiliary files created by LaTeX–in particular, the
.idx file for the document.
I started to write a post for stackoverflow and in doing so, I decided I really should make sure that all my software was up-to-date. This, in turn, broke everything! It was, however, obvious that what was broken was MikTeX.
MikTeX – why hast thou forsaken me?
I have been a big fan of MikTeX for a very long time. It traditionally has been, at least for me, a really robust TeX installation for Windows. One of the features I really like is its “Install packages on-the-fly” mechanism, whereby it can automatically install any package that is on CTAN that it detects is missing when it tries to compile a document. This means that the initial install is quite minimal, and usually very fast. At some point in 2020 (or maybe even 2019—I wasn’t paying too much attention) MikTeX changed the way it works. In particular, it seemed to become quite finicky about installing package updates as an Administrator or as a User, and no matter what I did, I couldn’t get it to have those two modes in sync with each other. That is, MikTeX would complain that there were different versions installed for the Administrator than those installed for the User, and vice versa.
TeXLive – what fresh hell is this?
Given MikTeX seemed to be broken, I decided I would try and setup TeXLive. I did this for a couple of reasons. Firstly, MikTeX was pissing me off, and secondly, given I was trying to synchronise behaviour, I thought perhaps having the same TeX distribution as I have on my Macs might help. I have traditionally avoided TeXLive because it doesn’t have the “install on-the-fly” feature, it used to require a huge initial download (not that that really matters anymore) and it was a pain to keep up to date. On the Mac you don’t have a lot of choice about using it. TeXLive does offer a internet installer these days, however, something is seriously wrong with it. I tried three different repositories in three different countries, but each was looking like it would take nearly 24 hours to download and install the software. I got fed up, and downloaded a 3.8GB ISO using a torrent in about five minutes. Windows 10 has a very nice feature which allows an ISO to be treated like a regular drive, and so I could run the installer straight off the ISO. Even so, the install took over 12 minutes which seems excessive on a core-i9 machine with 32GB of RAM, and an SSD but it worked. I then rather foolishly decided I should run the TeXLive Manager and update my installation. This process took 3 hours and 39 minutes!! I have no idea why it was so slow, but I have seen a lot of complaints about this on the net.
So it worked
So the problem was MikTeX. I still don’t know exactly what the issue was, but finally I can compile my book on my Windows machines again. I did have to install a custom class file for the book, but that was rather straightforward compared to the rest. And now I have wasted the rest of my day with writing a blog post. I do sincerely hope that it helps someone!