Skip to content
Prev 165015 / 398503 Next

using dvi with latex object: directory not correctly set, maybe due to error in shQuote()

Dear Bernhard

You were right, pushing my knowledge about R once again to the next level! Sys.getenv("R_SHELL") indeed returns "". The fix you are proposing works for me. If I am right, your function dvi.latex2 makes use of shell rather than of sys in the original function dvi.latex and stores results in the specified for tempdir(). On my system the original function dvi.latex also works up to the point when I want to produce a ps file (see output below: dvi can't be opened). 

However the next problem is the output (either by opening the dvi file with yap or the ps file with ghostscript). The page size is not the one specified by the parameters width and height in dvi.latex/dvi.latex2. It looks like DIN A4. I apologize if, at this point, it becomes a problem caused by Miktex 2.7 and geometry package. Ultimately, I want to embed the pdf file into another file and I cannot use the large format.

Cheers
Marco
Das System kann den angegebenen Pfad nicht finden.
This is pdfTeX, Version 3.141592-1.40.4 (MiKTeX 2.7 Beta 4)
entering extended mode
(C:/DOKUME~1/ferimawi/LOKALE~1/Temp/Rtmpr4CG3A/file33ea5db2.tex
LaTeX2e <2005/12/01>
Babel <v3.8g> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman, ngerman, french, loaded.
("C:\Programme\MiKTeX 2.7\tex\latex\base\report.cls"
Document Class: report 2005/09/16 v1.4f Standard LaTeX document class
("C:\Programme\MiKTeX 2.7\tex\latex\base\size10.clo"))
("C:\Programme\MiKTeX 2.7\tex\latex\geometry\geometry.sty"
("C:\Programme\MiKTeX 2.7\tex\latex\graphics\keyval.sty")
("C:\Programme\MiKTeX 2.7\tex\latex\geometry\geometry.cfg"))
No file file33ea5db2.aux.
[1] (file33ea5db2.aux) )
Output written on file33ea5db2.dvi (1 page, 300 bytes).
Transcript written on file33ea5db2.log.
This is dvips(k) 5.96 Copyright 2007 Radical Eye Software (www.radicaleye.com)
dvips: ! DVI file can't be opened.
This is pdfTeX, Version 3.141592-1.40.4 (MiKTeX 2.7 Beta 4)
entering extended mode
("H:/Asset Allocation/PROJECTS/MAM/latex/plot_tbl/file48cc23c9.tex"
LaTeX2e <2005/12/01>
Babel <v3.8g> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman, ngerman, french, loaded.
("C:\Programme\MiKTeX 2.7\tex\latex\base\report.cls"
Document Class: report 2005/09/16 v1.4f Standard LaTeX document class
("C:\Programme\MiKTeX 2.7\tex\latex\base\size10.clo"))
("C:\Programme\MiKTeX 2.7\tex\latex\geometry\geometry.sty"
("C:\Programme\MiKTeX 2.7\tex\latex\graphics\keyval.sty")
("C:\Programme\MiKTeX 2.7\tex\latex\geometry\geometry.cfg"))
No file file48cc23c9.aux.
[1] (file48cc23c9.aux) )
Output written on file48cc23c9.dvi (1 page, 300 bytes).
Transcript written on file48cc23c9.log.
This is dvips(k) 5.96 Copyright 2007 Radical Eye Software (www.radicaleye.com)
' TeX output 2008.12.17:1739' -> tst.ps
<C:/Programme/MiKTeX 2.7/dvips/base/tex.pro>
<C:/Programme/MiKTeX 2.7/dvips/base/texps.pro>. 
<C:/Programme/MiKTeX 2.7/fonts/type1/bluesky/cm/cmr10.pfb>[1]


-----Urspr?ngliche Nachricht-----
Von: Pfaff, Bernhard Dr. [mailto:Bernhard_Pfaff at fra.invesco.com] 
Gesendet: Wednesday, December 17, 2008 4:25 PM
An: Willner, Marco; r-help at r-project.org
Cc: charles.dupont at vanderbilt.edu
Betreff: AW: [R] using dvi with latex object: directory not correctly set,maybe due to error in shQuote()

Hello Marco,

as might not be evident at first sight, but have you set the environment variable "R_SHELL"? If you spot at the dvi method for latex you will find a call to sys(), which will call shell() and if the argument shell is unset then the contents of "R_SHELL" will be used. Hence, what does:

Sys.getenv("R_SHELL")

yield at your machine? I reckon "" will be returned. Therefore as a first step: 
Sys.setenv(R_SHELL = "cmd.exe") or permanently in your R environment file. Having done so and running dvi(latex.obj) now produces at least not the warning that everything beyond "cd" is skipped and the command via paste is parsed. The next problem is the path the randomly generated file that latex cannot handle. The following alternative might work for you too:

dvi.latex2 <- function (object, prlog = FALSE, nomargins = TRUE, width = 5.5, height = 7, ...) 
{
    fi <- object$file
    sty <- object$style
    if (length(sty)) 
        sty <- paste("\\usepackage{", sty, "}", sep = "")
    if (nomargins) 
        sty <- c(sty, paste("\\usepackage[paperwidth=", width, 
            "in,paperheight=", height, "in,noheadfoot,margin=0in]{geometry}", 
            sep = ""))
    tmp <- tempfile(tmpdir = tempdir())
    tmptex <- paste(tmp, "tex", sep = ".")
    infi <- readLines(fi, n = -1)
    cat("\\documentclass{report}", sty, "\\begin{document}\\pagestyle{empty}", 
        infi, "\\end{document}\n", file = tmptex, sep = "\n")
    sc <- if (under.unix) {
        "&&"
    } else {
        "&"
    }
    shell(paste("cd", shQuote(tempdir()), sc, optionsCmds("latex"), 
        "-interaction=scrollmode", shQuote(tmp)), translate = TRUE)
    if (prlog) 
        cat(scan(paste(tmp, "log", sep = "."), list(""), sep = "\n")[[1]], 
            sep = "\n")
    fi <- paste(tmp, "dvi", sep = ".")
    structure(list(file = fi), class = "dvi")
}


And therefore:

tbl.loc   <- matrix(1:4, ncol=2)
latex.obj <- latex(tbl.loc)
tempdir <- function(){"H:/PROJECTS/data"}
Sys.getenv("R_SHELL")
Sys.setenv(R_SHELL = "cmd.exe")
Sys.getenv("R_SHELL")
## options(xdvicmd='dviout') set appropriately I use TeXLive and have not yap installed; 
## working with MikTeX there should be no need to change the default viewer
dvi.latex2(latex.obj)
## It might be the case that the dvi file is not displayed immediately after production but can be opened 
## manually


Does this work for your? Probably it is also a good idea to address this problem directly to the package maintainer (already cc'ed).

Best,
Bernhard