]> git.lyx.org Git - lyx.git/blob - lib/scripts/lyxsweave.R
Fix bug #7551: Inclusion "." in filename creates LaTeX error sweave graphic generation
[lyx.git] / lib / scripts / lyxsweave.R
1 # file lyxsweave.R
2 # This file is part of LyX, the document processor.
3 # Licence details can be found in the file COPYING.
4
5 # author Jean-Marc Lasgouttes
6
7 # Full author contact details are available in file CREDITS
8
9 # Wrapper around Sweave that sets up some things for LyX
10 # argument 1 is the absolute name of the input file
11 # argument 2 is the absolute name of the output file
12 # argument 3 is the iconv name for the encoding of the file
13 # argument 4 is the original document directory
14
15 ls.args <- commandArgs(trailingOnly=TRUE)
16
17 # check whether Sweave.sty is seen by LaTeX. if it is not, we will
18 # pass the option stylepath=TRUE to sweave so that a full path is given
19 # to \usepackage.
20 ls.sweavesty <- system("kpsewhich Sweave.sty", intern=TRUE, ignore.stderr=TRUE)
21 ls.sp <- (length(ls.sweavesty) == 0)
22
23 # set default encoding for input and output files; ls.enc is used in
24 # the sweave module preamble to reset the encoding to what it was.
25 ls.enc <- getOption("encoding")
26 options(encoding=ls.args[3])
27
28 # Change current directory to the document directory, so that R can find 
29 # data files.
30 setwd(ls.args[4])
31
32 # this is passed as a prefix.string to tell where temporary files should go
33 ls.pr <- gsub('\\.([^/]*)$', '-\\1', sub("\\.tex$", "", ls.args[2]))
34
35 # Replace the default pdf device by the null device (tip from Yihui Xie)
36 # See: http://yihui.name/en/2010/12/a-special-graphics-device-in-r-the-null-device/ 
37 .Call("R_GD_nullDevice", PACKAGE = "grDevices")
38
39
40 # finally run sweave
41 Sweave(file=ls.args[1], output=ls.args[2], syntax="SweaveSyntaxNoweb", stylepath=ls.sp, prefix.string=ls.pr)