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

I searched for this but could not find a solution.

I understand that you can use an HTML snapshot with Sweave and then output it to HTML using:

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

However, I am wondering if there is a way to convert a .tex file created into an HTML file, but through R.

ps: I'm looking for a solution for Windows. I saw that other OSs already have their own solutions .

Thanks.

+4
source share
2 answers

TeX to HTML is a non-trivial task because TeX is so general. As @richiemorrisroe said, mk4ht is available on Windows. So tth (another method suggested on 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 to make the solution self-sufficient?

I don’t think the installation is really that complicated. That should make you most of the way ...

 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 ), also if you want to convert PDF to PNG on the fly ...

tth little less general than mk4ht , which contains a full (La) TeX parser, but it is also lighter - useful if you want to give this recipe to other users for installation and do not execute it so that they have to download a bunch of things (unfortunately , ImageMagick is pretty big - these days you can probably come up with a solution where you first create images in PNG in Sweave).

+6
source

Well, this is not a very clean solution for Windows, but you can use the tex4ht package and call htlatex in the latex file after sweaving.

Something like a system ("htlatex somesweavedfile.tex") after running Sweave from the R-interface (which I assume). By the way, this html can also be opened with an open office, and then converted to a word, which is always useful.

I always did this (on Windows) from the command line, and the man page for? The system notes that some commands may not work properly in Windows. From my reading of the corresponding help page, it seems like it will be. The only problem may be that if the htlatex command has a problem and tries to tell you, I'm not sure if the data will return from stderr to the R GUI.

Just to mark Tal, the mk4ht package is also available on Windows, but I see how you might not have gotten that impression of a webpage that is very specific to Linux (and also very useful to me, thanks for the link! )

EDIT: in response to Tel's comment below.

If you install MikTeX on windows, this will give you a package manager that you can use to install mk4ht. This should (all the right ways) allow me to fulfill my answer.

+4
source

All Articles