Overhauled the TeX stuff so that it can be done via knitr.