From ebb85745a9ee478d9c59e368b789f3008220e8a0 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 20 Jun 2011 10:59:23 +0000 Subject: [PATCH] When Sweave.sty is not available to LaTeX, copy it in the temp directory instead of using the stylepath argument of Sweave(). This is better under windows, where the path to Sweave.sty may contain spaces. Add Yihui Xie as co-author. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39140 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/scripts/lyxsweave.R | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/scripts/lyxsweave.R b/lib/scripts/lyxsweave.R index 09dad2d273..25cfcb3ac3 100644 --- a/lib/scripts/lyxsweave.R +++ b/lib/scripts/lyxsweave.R @@ -3,6 +3,7 @@ # Licence details can be found in the file COPYING. # author Jean-Marc Lasgouttes +# author Yihui Xie # Full author contact details are available in file CREDITS @@ -15,10 +16,16 @@ ls.args <- commandArgs(trailingOnly=TRUE) # check whether Sweave.sty is seen by LaTeX. if it is not, we will -# pass the option stylepath=TRUE to sweave so that a full path is given -# to \usepackage. +# copy it alongside the .tex file (in general in the temporary +# directory). This means that an exported LaTeX file will not work, +# but this is a problem of installation of R on the user's machine. +# The advantage compared to the use of stylepath, is that the exported +# .tex file will be portable to another machine. (JMarc) ls.sweavesty <- system("kpsewhich Sweave.sty", intern=TRUE, ignore.stderr=TRUE) -ls.sp <- (length(ls.sweavesty) == 0) +if (!length(ls.sweavesty)) { + stypath <- file.path(R.home("share"), "texmf", "tex", "latex", "Sweave.sty") + file.copy(stypath, dirname(ls.args[2]), overwrite=TRUE) +} # set default encoding for input and output files; ls.enc is used in # the sweave module preamble to reset the encoding to what it was. @@ -36,7 +43,7 @@ tmpout <- gsub(".", "-", sub("\\.tex$", "", basename(ls.args[2])), fixed = TRUE) ls.pr <- paste(dirname(ls.args[2]), tmpout, sep="/") # finally run sweave -Sweave(file=ls.args[1], output=ls.args[2], syntax="SweaveSyntaxNoweb", stylepath=ls.sp, prefix.string=ls.pr) +Sweave(file=ls.args[1], output=ls.args[2], syntax="SweaveSyntaxNoweb", prefix.string=ls.pr) # remove absolute path from \includegraphics ls.doc = readLines(ls.args[2]) -- 2.39.2