[R] texi2dvi: option "clean" also deletes the generated pdf file
Marius Hofert
m_hofert at web.de
Thu Aug 19 15:13:33 CEST 2010
Dear all,
many thanks for your help. I totally missed that texi2dvi is also a system command (I don't use that explicitly to compile my .tex docs). So I checked my "system-texi2dvi". It's quite interesting, if I use the option "--mostly-clean", everthing is removed. However, if I use just "--clean", then the generated pdf file is not removed. So the solution is to call (in the shell):
texi2dvi --clean --pdf ./test/myLaTeXFile2.tex
I can call this from within system() [or even use pdflatex directly from within system()]. I guess I don't need R's texi2dvi anymore.
Many thanks
Marius
Ps: Here is the output of what Duncan suggested:
> debug(tools:::.shell_with_capture)
> require(tools)
> filepath <- paste(getwd(),"/test/myLaTeXFile2.tex",sep="")
> sink(file=filepath)
> cat("\\documentclass{article}\n")
> cat("\\usepackage[T1]{fontenc}\n")
> cat("\\usepackage[english]{babel}\n")
> cat("\\usepackage{blindtext}\n")
> cat("\\begin{document}\n")
> cat("\\blindtext[10]\n")
> cat("\\end{document}\n")
> sink()
> texi2dvi(filepath,pdf=TRUE,clean=TRUE,quiet=TRUE)
debugging in: .shell_with_capture(paste(shQuote(texi2dvi), "--help"))
debug: {
outfile <- tempfile("xshell")
errfile <- tempfile("xshell")
on.exit(unlink(c(outfile, errfile)))
status <- if (.Platform$OS.type == "windows")
shell(sprintf("%s > %s 2> %s", command, outfile, errfile),
input = input, shell = "cmd.exe")
else system(sprintf("%s > %s 2> %s", command, outfile, errfile),
input = input)
list(status = status, stdout = readLines(outfile, warn = FALSE),
stderr = readLines(errfile, warn = FALSE))
}
Browse[2]>
debug: outfile <- tempfile("xshell")
Browse[2]>
debug: errfile <- tempfile("xshell")
Browse[2]>
debug: on.exit(unlink(c(outfile, errfile)))
Browse[2]>
debug: status <- if (.Platform$OS.type == "windows") shell(sprintf("%s > %s 2> %s",
command, outfile, errfile), input = input, shell = "cmd.exe") else system(sprintf("%s > %s 2> %s",
command, outfile, errfile), input = input)
Browse[2]>
debug: system(sprintf("%s > %s 2> %s", command, outfile, errfile), input = input)
Browse[2]>
debug: list(status = status, stdout = readLines(outfile, warn = FALSE),
stderr = readLines(errfile, warn = FALSE))
Browse[2]>
exiting from: .shell_with_capture(paste(shQuote(texi2dvi), "--help"))
debugging in: .shell_with_capture(paste(shQuote(texi2dvi), opt_pdf, opt_quiet,
opt_extra, shQuote(file)))
debug: {
outfile <- tempfile("xshell")
errfile <- tempfile("xshell")
on.exit(unlink(c(outfile, errfile)))
status <- if (.Platform$OS.type == "windows")
shell(sprintf("%s > %s 2> %s", command, outfile, errfile),
input = input, shell = "cmd.exe")
else system(sprintf("%s > %s 2> %s", command, outfile, errfile),
input = input)
list(status = status, stdout = readLines(outfile, warn = FALSE),
stderr = readLines(errfile, warn = FALSE))
}
Browse[2]>
debug: outfile <- tempfile("xshell")
Browse[2]>
debug: errfile <- tempfile("xshell")
Browse[2]>
debug: on.exit(unlink(c(outfile, errfile)))
Browse[2]>
debug: status <- if (.Platform$OS.type == "windows") shell(sprintf("%s > %s 2> %s",
command, outfile, errfile), input = input, shell = "cmd.exe") else system(sprintf("%s > %s 2> %s",
command, outfile, errfile), input = input)
Browse[2]>
debug: system(sprintf("%s > %s 2> %s", command, outfile, errfile), input = input)
Browse[2]>
debug: list(status = status, stdout = readLines(outfile, warn = FALSE),
stderr = readLines(errfile, warn = FALSE))
Browse[2]>
exiting from: .shell_with_capture(paste(shQuote(texi2dvi), opt_pdf, opt_quiet,
opt_extra, shQuote(file)))
On 2010-08-19, at 15:02 , Tim Gruene wrote:
> Dear Marius,
>
> I see. I suppose it's a matter of your version of texi2dvi then - when I do the
> same in a freshly created directory (including the "test" directory), cutting
> and pasting your very code into R leaves me only with "myLaTeXFile2.pdf" and
> "test/myLaTeXFile2.tex"
>
> This is texi2dvi --version
> texi2dvi (GNU Texinfo 4.11) 1.104
>
> Tim
>
> On Thu, Aug 19, 2010 at 01:55:06PM +0200, Marius Hofert wrote:
>> Dear Tim,
>>
>> if I run ...
>>
>> ## Example 2: texi2dvi also deletes the generated .pdf
>> require(tools)
>> filepath <- paste(getwd(),"/test/myLaTeXFile2.tex",sep="")
>> sink(file=filepath)
>> cat("\\documentclass{article}\n")
>> cat("\\usepackage[T1]{fontenc}\n")
>> cat("\\usepackage[english]{babel}\n")
>> cat("\\usepackage{blindtext}\n")
>> cat("\\begin{document}\n")
>> cat("\\blindtext[10]\n")
>> cat("\\end{document}\n")
>> sink()
>> texi2dvi(filepath,pdf=TRUE,clean=TRUE,quiet=TRUE)
>>
>> ... on a "fresh-and-clean" working directory (and also no files in the subdirectory ./test), I only get the file myLaTeXFile2.tex in ./test, so *everything* (including the .pdf) is deleted :-(
>>
>> I work with R version 2.11.1 (2010-05-31) on a MacBook Pro running 10.6.4.
>>
>> Cheers,
>>
>> Marius
>>
>> On 2010-08-19, at 13:38 , Tim Gruene wrote:
>>
>>> Dear Marius,
>>>
>>> yes, that's what I had meant.
>>>
>>> I am sorry I had not actually tested my suggestion nor your problem (bad
>>> practice). Now I have and actually in case 2 you describe I only end up
>>> with test/myLaTeXFile2.tex and myLaTeXFile2.pdf.
>>>
>>> If, however, I run texi2dvi at least once with option 'clean=F', the auxiliary files
>>> are generated and left in the path. Also upon a subsequent run with the option
>>> 'clean=T', they are not being deleted.
>>>
>>> Could this also be the case for you, i.e., that you once used the option
>>> 'clean=F' (or not set at all) and now are made believe 'clean=T' does not work
>>> because they are still there but actually left-overs from the old run?
>>>
>>> I run "R version 2.7.1 (2008-06-23)" on Debian stable.
>>>
>>> Kind regards, Tim
>>>
>>> On Thu, Aug 19, 2010 at 12:41:57PM +0200, Marius Hofert wrote:
>>>> Dear Tim,
>>>>
>>>> you mean
>>>>
>>>> require(tools)
>>>> filepath <- paste(getwd(),"/test/myLaTeXFile2.tex",sep="")
>>>> sink(file=filepath)
>>>> cat("\\documentclass{article}\n")
>>>> cat("\\usepackage[T1]{fontenc}\n")
>>>> cat("\\usepackage[english]{babel}\n")
>>>> cat("\\usepackage{blindtext}\n")
>>>> cat("\\begin{document}\n")
>>>> cat("\\blindtext[10]\n")
>>>> cat("\\end{document}\n")
>>>> sink()
>>>> texi2dvi(filepath,pdf=TRUE,quiet=TRUE,texi2dvi=getOption("texi2dvi --mostly-clean"))
>>>>
>>>> ?
>>>> The problem is that this does not work. It produces the same output as my "Example 2" without the "clean"-option. So it leaves all files in the working directory.
>>>>
>>>> The reason why I am looking for a "clean-up" is that I have to compile several hundred LaTeX files in different directories...
>>>>
>>>> Cheers,
>>>>
>>>> Marius
>>>>
>>>>
>>>> On 2010-08-19, at 12:33 , Tim Gruene wrote:
>>>>
>>>>> Dear Marius,
>>>>>
>>>>> from reading the texi2dvi man-page and R-help on texi2dvi I suggest to set
>>>>> 'clean=F' and use 'texi2dvi = getOption("texi2dvi --mostly-clean")' instead.
>>>>>
>>>>> Tim
>>>>>
>>>>> On Thu, Aug 19, 2010 at 10:36:30AM +0200, Marius Hofert wrote:
>>>>>> Dear expeRts,
>>>>>>
>>>>>> below are two examples of using texi2dvi. The problem becomes clear from the
>>>>>> second example: on cleaning, texi2dvi also deletes the generated .pdf file.
>>>>>> Is there a solution?
>>>>>>
>>>>>> Cheers,
>>>>>>
>>>>>> Marius
>>>>>>
>>>>>> ## Example 1: texi2dvi cleans fine, without deleting the generated .pdf
>>>>>> require(tools)
>>>>>> sink(file="myLaTeXFile1.tex")
>>>>>> cat("\\documentclass{article}\n")
>>>>>> cat("\\usepackage[T1]{fontenc}\n")
>>>>>> cat("\\usepackage[english]{babel}\n")
>>>>>> cat("\\usepackage{blindtext}\n")
>>>>>> cat("\\begin{document}\n")
>>>>>> cat("\\blindtext[10]\n")
>>>>>> cat("\\end{document}\n")
>>>>>> sink()
>>>>>> texi2dvi("myLaTeXFile1.tex",pdf=TRUE,clean=TRUE,quiet=TRUE)
>>>>>>
>>>>>> ## Example 2: texi2dvi also deletes the generated .pdf
>>>>>> require(tools)
>>>>>> filepath <- paste(getwd(),"/test/myLaTeXFile2.tex",sep="")
>>>>>> sink(file=filepath)
>>>>>> cat("\\documentclass{article}\n")
>>>>>> cat("\\usepackage[T1]{fontenc}\n")
>>>>>> cat("\\usepackage[english]{babel}\n")
>>>>>> cat("\\usepackage{blindtext}\n")
>>>>>> cat("\\begin{document}\n")
>>>>>> cat("\\blindtext[10]\n")
>>>>>> cat("\\end{document}\n")
>>>>>> sink()
>>>>>> texi2dvi(filepath,pdf=TRUE,clean=TRUE,quiet=TRUE)
>>>>>>
>>>>>> ______________________________________________
>>>>>> R-help at r-project.org mailing list
>>>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>>
>>>>> --
>>>>> --
>>>>> Tim Gruene
>>>>> Institut fuer anorganische Chemie
>>>>> Tammannstr. 4
>>>>> D-37077 Goettingen
>>>>>
>>>>> GPG Key ID = A46BEE1A
>>>>>
>>>
>>> --
>>> --
>>> Tim Gruene
>>> Institut fuer anorganische Chemie
>>> Tammannstr. 4
>>> D-37077 Goettingen
>>>
>>> GPG Key ID = A46BEE1A
>>>
>
> --
> --
> Tim Gruene
> Institut fuer anorganische Chemie
> Tammannstr. 4
> D-37077 Goettingen
>
> GPG Key ID = A46BEE1A
>
More information about the R-help
mailing list