Search code examples
rsweavepdflatex

Using pdflatex or something similar in R 3.0.1


I would like to compile a pdf document using Sweave() and pdflatex using R 3.0.1

The sweave() command works, however, pdflatex from the package 'utils' or 'tools' cannot be installed because it is not available for R version 3.0.1).

Is there any other way to compile a pdf from R?


Solution

  • Try texi2pdf from the tools package

    require(tools)
    tex_code <-
    "\\documentclass{article}
    \\begin{document}
    Hello \\LaTeX
    \\end{document}"
    
    cat(tex_code, file = "/tmp/code.tex")
    
    texi2pdf("/tmp/code.tex", clean = TRUE)
    

    Just in case you have trouble, there's a texi2dvi argument inside this function to choose your backend in my machine the default is /usr/bin/texi2dvi but we can change it like this

    texi2pdf("/tmp/code.tex", texi2dvi = "/usr/bin/texi2pdf", clean  = TRUE)
    

    Change it accoring to your settings. I don't have Mac OS but I'm sure that you'll find something similar in /usr/texbin