#!/bin/csh
#alias latexdiff ../latexdiff
set sample = example
# set sample = verbatim
# NOT including -t option
set options="-V -s SAFE -f FLOATSAFE"

set pdftypes=( UNDERLINE CTRADITIONAL TRADITIONAL CFONT FONTSTRIKE INVISIBLE BOLD PDFCOMMENT CCHANGEBAR CFONTCHBAR CULINECHBAR CHANGEBAR LUAUNDERLINE ) 
set dvitypes=(  )

#set pdftypes=( UNDERLINE PDFCOMMENT )
#set dvitypes=()

set failed 
set pdfout
set psout
foreach type ( $pdftypes )
  echo "========================================="
  echo "Differencing ${sample}-old.tex ${sample}-new.tex with type $type"
  latexdiff $options -t$type ${sample}-old.tex ${sample}-new.tex > ${sample}-diff-t$type.tex
  if ( $type =~ LUA* ) then 
    lualatex --interaction=batchmode ${sample}-diff-t$type.tex
  else
    pdflatex --interaction=batchmode ${sample}-diff-t$type.tex
  endif
  if ($status || ! -e ${sample}-diff-t$type.pdf ) then 
   echo "Compilation of ${sample}-diff-t$type.tex did not complete as expected."
   set failed=($failed ${sample}-diff-t$type.tex)
  else
   set pdfout=($pdfout ${sample}-diff-t$type.pdf )
  endif
end

foreach type ( $dvitypes )
  echo "========================================="
  echo "Differencing ${sample}-old.tex ${sample}-new.tex with type $type"
  latexdiff $options -t$type ${sample}-old.tex ${sample}-new.tex > ${sample}-diff-t$type.tex
  latex --interaction=batchmode ${sample}-diff-t$type.tex
  if ($status || ! -e ${sample}-diff-t$type.dvi ) then 
   echo "Compilation of ${sample}-diff-t$type.tex did not complete as expected."
   set failed=($failed ${sample}-diff-t$type.tex)
  else
   set psout=($psout ${sample}-diff-t$type.ps )
  endif
  dvips -o${sample}-diff-t$type.ps ${sample}-diff-t$type.dvi 
end


foreach out ( $pdfout )
  echo "okular $out"
end
foreach out ( $psout )
  echo "gv $out"
end
echo "The compilation of the following programs resulted in problems:"
echo $failed
