From 0745dbe501962f7cd6276bce1d8ec580e83be5f8 Mon Sep 17 00:00:00 2001 From: Taha Ahmed Date: Sun, 16 Jan 2011 18:45:52 +0100 Subject: [PATCH] Initial commit. Files as-is. Currently chertex.sh and simpledelay.sh are most used. --- .gitignore | 4 ++ chepdftk.sh | 180 +++++++++++++++++++++++++++++++++++++++++++++++++ chertex.sh | 149 ++++++++++++++++++++++++++++++++++++++++ chetex.sh | 50 ++++++++++++++ countdown.sh | 87 ++++++++++++++++++++++++ dvi2pdf.sh | 40 +++++++++++ simpledelay.sh | 36 ++++++++++ 7 files changed, 546 insertions(+) create mode 100644 .gitignore create mode 100755 chepdftk.sh create mode 100755 chertex.sh create mode 100755 chetex.sh create mode 100755 countdown.sh create mode 100755 dvi2pdf.sh create mode 100755 simpledelay.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..10aefa9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +biber +pdfcrop +unborn/ +documentation/ diff --git a/chepdftk.sh b/chepdftk.sh new file mode 100755 index 0000000..accc808 --- /dev/null +++ b/chepdftk.sh @@ -0,0 +1,180 @@ +#!/bin/bash +# Umbrella function to simplify use of pdftk +# Created April 20, 2010 +# Taha Ahmed, taha@chepec.se +# ************************** +# Usage: +# ARG 1: filename of pdf, e.g., 'oxides.pdf' +# ARG 2: specify operation, +# - 'dump_data' --> writes metadata to $reportfile in current directory +# ARG 3: used when updating metadata, specifies the input text file + +# $* Stores all the arguments that were entered on the command line ($1 $2 ...). +# $@ Stores all the arguments that were entered on the command line, individually quoted ("$1" "$2" ...). +# -o is logical OR - can be evaluated within single brackets +# -a is logical AND - can be evaluated within single brackets + +############################################################# +## Original pdftk syntax +## ********************* +## Dump metadata to file +#= pdftk dump_data output <$reportfile> +## Update metadata from file +#= pdftk update_info <$reportfile> output +############################################################# + +# Perhaps good to save original PDF + +# Could be nice to be able to input metadata updates directly at the bash prompt, something like +# First, script displays current fields +# echo Which field do you want to update/create? +# echo +# read choice newfieldinfo +# do the whole pdftk update stuff +# voila! + +#set -x # for debugging + +NAME=$(basename $0) +echo "***********************************************************" +echo "This is $NAME. Write $NAME -h for help." + +# Set defaults +DUMPMETADATA=yes # default action +UPDATEMETADATA=no + +# Set filetypes +pdfext=".pdf" +metadataext=".pdfmeta" + +usage () { + cat <.pdfmeta + $NAME .pdf + +AUTHOR + Taha Ahmed + +EOF +} + +OPTIONS=$@ + +for OPTION in "$@"; do + case "$OPTION" in + -h | --help ) + usage + exit 0 + ;; + -a | --all ) + # Perform default action on all PDFs in current directory + + ;; + * ) # no options, just run with default settings + ;; + esac +done + +FILES=$OPTIONS + +# Check if no input files were given +if [ ! -n "$FILES" ]; then + # Perhaps do default action for all pdf files in current directory? + echo -e "\nError: There is no input files! Usage is:\n" + usage + exit 1 +fi + +# Check file types (pre-assumes a file extension exists) +for FILE in "$FILES"; do + PDFFILE=$(echo $FILE | grep '.[Pp][Dd][Ff]$') + TEXFILE=$(echo $FILE | grep '.[Tt][Ee][Xx]$') + if [ ! -n "$PDFFILE" -a ! -n "$TEXFILE" ]; then + echo "$FILE is not a supported file type!" + echo "It should be one of: .pdf or .tex" + exit 1 + fi + NEWFILES="$NEWFILES $FILE" + unset PDFFILE TEXFILE +done +FILES=$NEWFILES + +# Execution +for FILE in "$FILES"; do + # Metadata filename is pdf basename plus .pdfmeta extension + METADATAFILE=${FILE%.*}$metadataext # metadata filename + + if [ "$DUMPMETADATA" = "yes" ]; then + #echo "pdftk $FILE dump_data output $METADATAFILE" + + ## It seems pdftk has problems dealing with spaces in filenames or paths. + ## Possible work-arounds: + ## Escape spaces with back-slashes? + ## Check for spaces in filename, if present, copy to temporary file without spaces, + ## then run call pdftk, then rename again... + + pdftk $FILE dump_data output $METADATAFILE + fi +done + +exit 0 + +### STUFF BELOW IS OLD +reportfile=./chepdftk-report.txt + +# Check number of args supplied +if [ $# -eq 0 ]; then + # Zero arguments + echo No arguments given. + exit +else + # Some arguments were passed. + if [ $# -eq 1 ]; then + # One argument was passed + echo One argument. + else + # More than one argument + if [ $# -eq 2 ]; then + # Two arguments were passed + echo Two arguments. + if [ $2 == "dump_data" ]; then + pdftk $1 $2 output $reportfile + fi + else + # More than two arguments + if [ $# -eq 3 ]; then + # Three arguments were passed + echo Three arguments. + else + # More than three arguments + echo More than three arguments. Too many. + fi + fi + fi +fi diff --git a/chertex.sh b/chertex.sh new file mode 100755 index 0000000..ea9b99b --- /dev/null +++ b/chertex.sh @@ -0,0 +1,149 @@ +#!/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 " Detected filename: " $jobname + echo " Detected extension:" $jobfiletype + + # Verifying that the file extension is *.Rnw + if [[ $jobfiletype == "Rnw" || $jobfiletype == "rnw" || $jobfiletype == "RNW" ]]; then + # File extension is *.Rnw + echo " Detected *.Rnw extension" + jobfiletype="Rnw" + else + # File extension is not *.Rnw + echo " File extension should be *.Rnw" + echo " Terminating..." + exit 1 + fi + + # Introducing a short delay to enable on-screen reading of previous echo + simpledelay.sh 2 + echo "Delay completed" + + # Tangle + echo " Tangling..." + R CMD Stangle $jobname.$jobfiletype + # Weave + echo " Weaving..." + R CMD pgfsweave --graphics-only $jobname.$jobfiletype + + # Introduce delay to give time to read R CMD exit status + echo " -------------------------" + echo " R CMD pgfsweave completed" + echo " -------------------------" + simpledelay.sh 5 + + # Run vc script if vc exists in working directory + echo " Running vc script" + if [ -f vc ]; then + ./vc + fi + + # Run pdflatex, bibtex, and company + echo " Calling LaTeXMK" + latexmk $jobname -pdf -bibtex + + # Don't bother with this. Let latexmk take care of cleaning up + # Move unnecessary auxiliary files generated + #echo " _________________________" + #echo " =========================" + #echo " 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 + # Else, fetch the jobname from the .Rnw filename by stripping 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 + # Remove the file extension + tikzlabel=${tikzfilename%.*} + # Call pdfLaTeX with tikz label as jobname # See TiKZ manual section 63 for more details + echo "Executing " + pdflatex --jobname=$tikzlabel $jobname.$TeXfiletype + 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 + + echo " This script can be run with one argument is process mode," + echo " or with zero arguments in post-processing mode." + echo " Terminating..." + exit 1 +fi + +exit 1 diff --git a/chetex.sh b/chetex.sh new file mode 100755 index 0000000..257ad57 --- /dev/null +++ b/chetex.sh @@ -0,0 +1,50 @@ +#!/bin/bash +## This is a shell for running pdflatex and bibtex on TeX files. +## Written Apr 29, 2010 +## Taha Ahmed + +##### +## Supply the filename argument without file extension! + +if [ $# -gt 2 ]; then + # More than two arguments + echo More than two arguments. Too many! + exit +else + # Two or less arguments + if [ $# -eq 2 ]; then + # Exactly two arguments + # First argument should be jobname + jobname=$1 + # Test second argument + if [ $2 == "-bib" ]; then + BibliographyRequired=1 + fi + if [ $2 == "-biber" ]; then + BiberRequired=1 + fi + else + if [ $# -eq 1 ]; then + # Only one argument + # Argument specifies the jobname + jobname=$1 + # Set BibliographyRequired to false + BibliographyRequired=0 + else + # No arguments submitted + # No use right now + echo No arguments submitted. + exit + fi + fi +fi + +pdflatex $jobname +if [ $BibliographyRequired ]; then + bibtex $jobname +fi +if [ $BiberRequired ]; then + biber $jobname +fi +pdflatex $jobname +pdflatex $jobname diff --git a/countdown.sh b/countdown.sh new file mode 100755 index 0000000..8e0555a --- /dev/null +++ b/countdown.sh @@ -0,0 +1,87 @@ +#!/bin/bash +# Using two digits the represent the value being counted down +# Two-digits set in decimal representation used by printf +# Usage: 'countdown #delay #style' +# Delay is an integer from 1 to 99 (what happens if zero?) +# Style is a string, either "numbers" or "style" +# Arguments should always be given in that order +# Both arguments may be omitted, in that case delay defaults to ten seconds and style to "numbers" + +defaultdelay=10 +numberstyle="numbers" +symbolstyle="symbols" +defaultstyle=$numberstyle + +if [ $# -gt 2 ]; then + # More than two arguments + echo Too many arguments + exit +else + # Two or less arguments + if [ $# -eq 2 ]; then + # Exactly two arguments + # First argument should specify the delay + delaysecs=$1 + # Second argument should specify the display style + style=$2 + else + if [ $# -eq 1 ]; then + # Only one argument + # Argument specifies the delay + delaysecs=$1 + # Style defaults to "numbers" + style="numbers" + else + # No arguments submitted + # Delay defaults + delaysecs=$defaultdelay + # Style defaults + style=$defaultstyle + fi + fi +fi + +# Adjustment by one second +#delaysecs=$[$delaysecs-1] +delaystatic=$delaysecs + +if [ $style == $numberstyle ]; then + while [ $delaysecs -gt 0 ] + do + sleep 1 & + printf "\r" + # Text before counter + printf "Stand by... " + printf "%02d" $[delaysecs] + delaysecs=$[$delaysecs-1] + wait + done + # Printing the zero (end of count-down) + printf "\b\b" + printf "%02d" $[delaysecs] + printf " - Done!" + echo +else + # style is symbolstyle + printf -v line '%*s' "$delaysecs" + printf "%s\r" "${line// /#}" + while [ $delaysecs -gt 0 ] + do + sleep 1 & + printf "+" + delaysecs=$[$delaysecs-1] + wait + done + #printf "\b " + echo +fi + + +# Bash quoting with ANSI-C style +# \b - backspace +# \r - carriage return +# \n - newline +# \f - form-feed +# \t - horizontal tabulator +# \v - vertical tabulator +# http://bash-hackers.org/wiki/doku.php/commands/builtin/printf diff --git a/dvi2pdf.sh b/dvi2pdf.sh new file mode 100755 index 0000000..29dcd69 --- /dev/null +++ b/dvi2pdf.sh @@ -0,0 +1,40 @@ +#!/bin/bash +## Taha Ahmed, Sep 16, 2010 + +## For making PDF from LaTeX file that uses PSTricks, +## also fixing correct page size using the preview package. + +#################################################### +# Required argument: +# Filename (WITHOUT FILE EXTENSION) +#################################################### + +############## +# Runs +# latex +# dvips +# ps2pdf +############## + + +clear +echo "Runs latex, dvips, ps2eps, epstopdf" + +latex $1.tex +echo "===============" +echo "latex $1.tex" +echo "===============" +simpledelay.sh 2 + +dvips $1.dvi +echo "===============" +echo "dvips $1.dvi" +echo "===============" +simpledelay.sh 2 + +ps2pdf $1.ps +echo "===============" +echo "ps2pdf $1.ps" +echo "===============" + +exit 1 diff --git a/simpledelay.sh b/simpledelay.sh new file mode 100755 index 0000000..8eed382 --- /dev/null +++ b/simpledelay.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# Arbitrary delay + +# simpledelay.sh +# is an integer value and specifies the delay interval in seconds + +minint=0 # mininum delay +maxint=15 # maximum delay + +# Check that only one argument has been submitted +if [ $# -eq 1 ]; then + # Check that the argument is an integer and in the valid range + if [ $1 ]; then + if [ ! $(echo "$1" | grep -E "^[0-9]+$") ]; then + echo $1 is not a valid integer. + exit 1 + else + if ! [ $1 -ge $minint ] || ! [ $1 -le $maxint ]; then + echo $1 is an invalid value. Range is [$minint-$maxint] + exit 1 + fi + fi + fi +else + # No args or more than one submitted + echo " Not a valid numbers of arguments. Only one argument allowed." + exit 1 +fi + +# Execute the delay +delaysecs=$1 +while [ $delaysecs -gt 0 ]; do + sleep 1 & + delaysecs=$[$delaysecs-1] + wait +done