[R] a question about "latex" in Hmisc and .dvi file

Erik Iverson eriki at ccbr.umn.edu
Thu May 13 18:46:11 CEST 2010


Looks good.  I came up with something on my own which was basically to 
re-write print.latex.  I call pdflatex a few times because with the 
longtable package, sometimes things don't line up right until you run 
pdflatex multiple times.  I think mine is less flexible though, and I 
like your solution better.

The only thing I can see to make your solution more flexible is to note 
that there is already options("pdfviewer") in R, so maybe you could just 
use whatever that is for options("xdvicmd") and then in show.dvi, you 
can test

if(viewer == options("pdfviewer")) {
...
}

--Erik

RICHARD M. HEIBERGER wrote:
> Here is the full repair for the latex functions in Hmisc to make 
> pdflatex work in Windows.
> This version is still slightly awkward.  I hope that Charles and Frank 
> will smooth it out
> and put it in their next release.
>  
> I added two new options() and revised show.dvi so it will use them.
> 
> Rich
>  
>  
>  
> library(Hmisc)
>  
> show.dvi <-
> function (object, width = 5.5, height = 7)
> {
>     viewer <- optionsCmds("xdvi")
>     cmd <- if (viewer == "yap") {
>         paste(viewer, object$file)
>     }
>     else if (viewer == "kdvi") {
>         paste(viewer, object$file)
>     }
>     else if (viewer == "xdvi") {
>         paste(viewer, " -paper ", width, "x", height, "in -s 0 ",
>             object$file, sep = "")
>     }
>     else if (basename(viewer) == "AcroRd32") {
>       object$file <- sub("dvi", "pdf", object$file)
>         paste(viewer, object$file)
>     }
>     else {
>         paste(viewer, object$file)
>     }
>     system(cmd, intern = TRUE, wait = TRUE)
>     invisible(NULL)
> }
> environment(show.dvi) <- environment(print.dvi)
>  
> options(latexcmd="pdflatex",
>         xdvicmd="c:/Progra~1/Adobe/Reader~1.0/Reader/AcroRd32")
>  
> x <- matrix(1:24, 6,4, dimnames=list(letters[1:6], LETTERS[1:4]))
> show.dvi(dvi(x.tex <- latex(x)))
> paste(getwd(), x.tex$file, sep="/")  ## location of the table itself
> ## The tex file with headers and the pdf file are in the directory
> ## given in the printed output from dvi().



More information about the R-help mailing list