You are not logged in.

#1 2009-12-06 13:30:54

Pank
Member
From: IT
Registered: 2009-06-13
Posts: 371

[Solved] Script to check for changes

Hello,
I am writing a paper using Sweave (That is replacing R-chunks with LaTeX-code).
As some of you might know this can be quite time-consuming for large documents with many files. On Friday the paper took a couple of minutes to compile which. I have been able to optimize the LaTeX-procedure, now I just need to optimize Sweaving.

The procedure is quite ineffective at the moment since it Sweave every file every time.
What I want is to record the md5sum and only recompile if it has changed.
To illustrate in pseudo-code:

md5sum $files
check "database"
save changed files as $changedfiles
update database
sweave $changedfiles
latex main.tex

I have looked at various code-snips around the 'net, but I haven't been able to make a useful script yet.

I hope somebody would be able to help me out here.

Thanks,
Rasmus

Last edited by Pank (2009-12-06 14:56:50)


Arch x64 on Thinkpad X200s/W530

Offline

#2 2009-12-06 14:55:55

Pank
Member
From: IT
Registered: 2009-06-13
Posts: 371

Re: [Solved] Script to check for changes

I have made a script that works decently now. It is based on a code from expert-exchange.

#!/bin/bash
cd sections
for file in *.Rnw;
do
  md5sum --status -c $file.md5
  if [ $? -ne 0 ]
  then
      pgfsweave --pgfsweave-only $file
#      echo "Sweave $file!"
      md5sum $file > $file.md5
  fi
  echo "Nothing to do for $file"
done
cd ..
latexmk -pdf main.tex

the great thing about latexmk is that it checks if the pdf should be updated.
This is an effective script. R-plots are exported as Tikz code and converted to pdf.

Last edited by Pank (2009-12-06 14:56:35)


Arch x64 on Thinkpad X200s/W530

Offline

Board footer

Powered by FluxBB