library(tools)
source("sweaveHelper.R")
rm(dd)
load("../results.RData")
curwd = getwd()
sols_dir = paste(curwd, "solutions/", sep="/")

dir.create("solutions/")



for(i1 in 1:length(dd)) {
  cat(i1, "\n")
  d = dd[[i1]]
  outfile = paste("solutions/", d$stud_id, ".tex", sep="")
  Sweave("template.Rnw", output=outfile)
  setwd(sols_dir)##texi2dvi needs to be in the actual directory!
  outfile = paste(d$stud_id, ".tex", sep="")
  texi2dvi(outfile, pdf=TRUE, clean=TRUE)
  setwd(curwd)
}

setwd("solutions")

for(file in list.files(pattern=".pdf")) {
  print_com = paste("lpr -o SelectColor=Auto -o Staple=1Staple\\(Left\\)", file)
  system(print_com)
}




