]> git.lyx.org Git - features.git/commitdiff
Backport r39070 and r39140.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 20 Jun 2011 12:15:30 +0000 (12:15 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 20 Jun 2011 12:15:30 +0000 (12:15 +0000)
This fixes two sweave bugs (mainly under windows):
- latex error when the temp dir path contains a space
- latex error when the R dir path contains a space

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@39141 a592a061-630c-0410-9148-cb99ea01b6c8

lib/scripts/lyxsweave.R
status.20x

index 15ec609cfbbc991c67a5d94d9b0c39c3818c8a47..25cfcb3ac31e7e2a0d0b1ccee29e1f832348ac20 100644 (file)
@@ -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
 
 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,4 +43,13 @@ 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])
+ls.cmd = paste('\\includegraphics{', dirname(ls.args[2]), "/", sep = "")
+ls.idx = grep(ls.cmd, ls.doc, fixed = TRUE)
+if (length(ls.idx)) {
+   ls.doc[ls.idx] = sub(ls.cmd, "\\includegraphics{", ls.doc[ls.idx], fixed = TRUE)
+   writeLines(ls.doc, ls.args[2])
+}
index 7b686271997cd96d5eef0465b457ba0ad67040e7..500f39afa7c984b7c540f4abcb13ea3fdf97b82c 100644 (file)
@@ -116,6 +116,10 @@ What's new
 
 - Fixed the latex flag set by the prefs2prefs script (bug 7610).
 
+- Fix LaTeX error with Sweave module when the file name contains a
+  dot (bug 7551).
+
+- Fix error with Sweave module when using some R features (bug 7552).
 
 * USER INTERFACE