|
|
|
#!/bin/bash
|
|
|
|
## Process *.Rnw files
|
|
|
|
## Written May 14, 2010
|
|
|
|
## Taha Ahmed
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# For now, MAKE SURE that the argument consists of
|
|
|
|
# a complete filename, with extension, and
|
|
|
|
# in the directory of the Rnw file
|
|
|
|
####################################################
|
|
|
|
|
|
|
|
clear
|
|
|
|
echo "---------------------------------------------------------------"
|
|
|
|
echo "cheRTeX -- a script for processing R-Sweave-LaTeX-TikZ projects"
|
|
|
|
echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
|
|
|
|
echo "MMX -- taha.ahmed@mkem.uu.se -- CHEPEC doctoral degree project"
|
|
|
|
echo "---------------------------------------------------------------"
|
|
|
|
|
|
|
|
Rfiletype="R"
|
|
|
|
TeXfiletype="tex"
|
|
|
|
tikzfiles="*.tikz"
|
|
|
|
Rnwfiles="*.Rnw"
|
|
|
|
|
|
|
|
if [ $# -eq 1 ]; then
|
|
|
|
# Check if the argument contains a filetype
|
|
|
|
# Assumes a complete filename was passed
|
|
|
|
jobfilename=$1
|
|
|
|
jobfiletype=${jobfilename#*.} # File extension
|
|
|
|
jobname=${jobfilename%.*} # Filename without extension part
|
|
|
|
|
|
|
|
echo "<cheRTeX> Detected filename: " $jobname
|
|
|
|
echo "<cheRTeX> Detected extension:" $jobfiletype
|
|
|
|
|
|
|
|
# Verifying that the file extension is *.Rnw
|
|
|
|
if [[ $jobfiletype == "Rnw" || $jobfiletype == "rnw" || $jobfiletype == "RNW" ]]; then
|
|
|
|
# File extension is *.Rnw
|
|
|
|
echo "<cheRTeX> Detected *.Rnw extension"
|
|
|
|
jobfiletype="Rnw"
|
|
|
|
else
|
|
|
|
# File extension is not *.Rnw
|
|
|
|
echo "<cheRTeX> File extension should be *.Rnw"
|
|
|
|
echo "<cheRTeX> Terminating..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Introducing a short delay to enable on-screen reading of previous echo
|
|
|
|
simpledelay.sh 2
|
|
|
|
echo "Delay completed"
|
|
|
|
|
|
|
|
# Tangle
|
|
|
|
echo "<cheRTeX> Tangling..."
|
|
|
|
R CMD Stangle $jobname.$jobfiletype
|
|
|
|
# Weave
|
|
|
|
echo "<cheRTeX> Weaving..."
|
|
|
|
R CMD pgfsweave --graphics-only $jobname.$jobfiletype
|
|
|
|
|
|
|
|
# Introduce delay to give time to read R CMD exit status
|
|
|
|
echo "<cheRTeX> -------------------------"
|
|
|
|
echo "<cheRTeX> R CMD pgfsweave completed"
|
|
|
|
echo "<cheRTeX> -------------------------"
|
|
|
|
simpledelay.sh 5
|
|
|
|
|
|
|
|
# Run vc script if vc exists in working directory
|
|
|
|
echo "<cheRTeX> Running vc script"
|
|
|
|
if [ -f vc ]; then
|
|
|
|
./vc
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Run pdflatex, bibtex, and company
|
|
|
|
echo "<cheRTeX> Calling LaTeXMK"
|
|
|
|
latexmk $jobname -pdf -bibtex
|
|
|
|
#echo "<cheRTeX> Calling texi2dvi()"
|
|
|
|
#R CMD texi2dvi --pdf --verbose $jobname.tex
|
|
|
|
### Perhaps the choice should be dictated from a command-line argument?
|
|
|
|
|
|
|
|
# Don't bother with this. Let latexmk take care of cleaning up
|
|
|
|
# Move unnecessary auxiliary files generated
|
|
|
|
#echo "<cheRTeX> _________________________"
|
|
|
|
#echo "<cheRTeX> ========================="
|
|
|
|
#echo "<cheRTeX> Moving auxiliary files..."
|
|
|
|
#mv *.aux logs
|
|
|
|
#mv *.log logs
|
|
|
|
#mv *.out logs
|
|
|
|
else
|
|
|
|
# Either no arguments, or more than one argument
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
# Zero arguments. Present a menu of choices
|
|
|
|
echo "This is cheRTeX POST-PROCESSING" # only one choice for now
|
|
|
|
echo "<1> 'pdf-all' -- Process all .tikz files to pdf graphics"
|
|
|
|
echo "Any other input exits the program"
|
|
|
|
read usrchoice
|
|
|
|
|
|
|
|
## Determine number of .Rnw files in current directory
|
|
|
|
#Rnwfileno=$(ls -1 $Rnwfiles | wc -l)
|
|
|
|
#echo "No of .Rnw files: $Rnwfileno"
|
|
|
|
#
|
|
|
|
## Check if number of .Rnw files larger than one
|
|
|
|
#if [ $Rnwfileno -gt 1 ]; then
|
|
|
|
# # If larger than one, ask for user input
|
|
|
|
# # Indicates more than one Rnw file in current directory.
|
|
|
|
# # This introduces a naming ambiguity.
|
|
|
|
# # Resolve by asking user for current jobname
|
|
|
|
# echo "Found $Rnwfileno .Rnw files in current directory"
|
|
|
|
# echo "Please specify the jobname"
|
|
|
|
# read jobname
|
|
|
|
# if [ -z "$jobname" ]; then
|
|
|
|
# # string is null
|
|
|
|
# echo "Specified jobname cannot be parsed. Terminating..."
|
|
|
|
# exit 1
|
|
|
|
# fi
|
|
|
|
#else
|
|
|
|
# # There is exactly one *.Rnw file is current directory
|
|
|
|
# # Fetch the jobname from the .Rnw filename by stripping off the file extension
|
|
|
|
# Rnwfilename=$(ls -1 $Rnwfiles)
|
|
|
|
# jobname=${Rnwfilename%.*}
|
|
|
|
#fi
|
|
|
|
#
|
|
|
|
#echo "Jobname set to: $jobname"
|
|
|
|
|
|
|
|
if [[ $usrchoice == "pdf-all" || $usrchoice == "1" ]]; then
|
|
|
|
echo "<1> 'pdf-all' chosen"
|
|
|
|
# This for loop ONLY USED to determine number of *.tikz files in directory
|
|
|
|
for tikzfiles in "$tikzfiles"; do tikzfilenumber=${#tikzfiles}; done
|
|
|
|
echo "cheRTeX detected $tikzfilenumber TikZ files for processing"
|
|
|
|
echo "Starting TikZ file processing..."
|
|
|
|
simpledelay.sh 2
|
|
|
|
|
|
|
|
for tikzfilename in $tikzfiles; do
|
|
|
|
# Call tikz2pdf
|
|
|
|
echo "<Executing> tikz2pdf $tikzfilename"
|
|
|
|
tikz2pdf --once $tikzfilename
|
|
|
|
done
|
|
|
|
echo "Completed TikZ file processing"
|
|
|
|
fi
|
|
|
|
echo "Terminating..."
|
|
|
|
|
|
|
|
#mv $jobname-*.pdf tikz-pdfs
|
|
|
|
#mv *.aux logs
|
|
|
|
#mv *.log logs
|
|
|
|
#mv *.out logs
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Here is the wild land of more than one *.Rnw file in current directory
|
|
|
|
|
|
|
|
echo "<cheRTeX> This script can be run with one argument is process mode,"
|
|
|
|
echo "<cheRTeX> or with zero arguments in post-processing mode."
|
|
|
|
echo "<cheRTeX> Terminating..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 1
|