Search code examples
htmlrsweave

How to turn a LaTeX Sweave file (Rnw) into HTML?


I searched for this, but couldn't find a solution.

I understand that one could use the HTML markdown with Sweave, and then output it to HTML using:

library(R2HTML) 
Sweave('temp1.rnw', driver = RweaveHTML)

What I am wondering though, is if there a way to turn the .tex file that is created into an HTML file, but through R.

p.s: I am looking for a solution for windows. I've seen that other OS already has their own solutions.

Thanks.


Solution

  • TeX to HTML is a non-trivial task, because TeX is so general. As @richiemorrisroe said, mk4ht is available on Windows. So is tth (the other method suggested at the Vanderbilt page you linked to). I don't think you want to write a TeX parser in R ... Can you tell us why you want a pure-R solution? Is it just for the sake of having the solution self-contained?

    I don't think the installation is really that hard. This should get you most of the way there ...

    TTHurl <- "http://hutchinson.belmont.ma.us/tth/tth-noncom/tth_exe.zip"
    SWconvurl <- "http://biostat.mc.vanderbilt.edu/wiki/pub/Main/SweaveConvert/sweave2html"
    download.file(TTHurl,dest="tth.zip")
    unzip("tth.zip") ## creates tth_exe
    download.file(SWconvurl,dest="sweave2html")
    Sys.chmod(c("tth_exe","sweave2html"),mode="0755") ## ???
    

    You will need ImageMagick (binary downloads here) too if you want to convert PDF to PNG on the fly ...

    tth is a little less general than mk4ht, which contains a complete (La)TeX parser, but it's also more lightweight -- useful if you want to give this recipe to other users to install and don't want them to have to download oodles of stuff (unfortunately ImageMagick is pretty big -- these days, you can probably concoct a solution where you generate the images in PNG in Sweave in the first place).