#!/usr/bin/tcsh # # file: ~/bin/fixfignew # # USAGE: # > fixfignew -- fixes ALL files in current directory # > fixfignew foo* -- fixes all foo files in current directory # # NOTE: you must use "foo*" (not "foo") # to get foo.pstex_t and foo.pdftex_t, etc) # # Changes so that it works in cygwin: # (1) use tcsh instead of # #!/usr/bin/csh -f # (2) use awk instead of nawk # # NEW VERSION OF fixfig # (because transfig now to default to eps, not ps) # # Purpose: To fix *.tex files produced by transfig # so that it will search for *.eps files # in a subdirectory "figs" of the current directory # # Author: Chee Yap # # April 2007: need to handle the new way of inserting fig files # into latex, using "export in combined PS/Latex format". # This export produces two files, foo.pstex and foo.pstex_t, from foo.fig. # Only "foo.pstex_t" file need to be fixed. # Also, if we want to export in "combined PDF/Latex format", # then we need to fix foo.pdftex_t. # April 2008: add the ability to take arguments, useful for fixing only ONE file! # echo "fixfig -- new version" if ($#argv == 0) then set files = * else set files = ( $argv ) endif set noglob foreach i ($files) if ($i =~ *.tex) then echo "...Appending figs/ to file " $i awk 'BEGIN{FS="{"}\ /includegraphics/ {\ n=length($0);\ print "\\includegraphics{figs/" substr($0,18,n);}\ \!/includegraphics/ {print;}\ END{}\ ' $i > $i.x mv -f $i.x $i endif if ($i =~ *.pstex_t) then # new, April 2007 echo "...Appending figs/ to file " $i awk 'BEGIN{FS="{"}\ /includegraphics/ {\ m=index($0, "{"); n=index($0, "}");\ w=substr($0,m+1,n-m-1); n=split(w,patharray,"/");\ print "\\includegraphics{figs/" patharray[n] "}"; }\ \!/includegraphics/ {print;}\ END{}\ ' $i > $i.x mv -f $i.x $i endif if ($i =~ *.pdftex_t) then # new, April 2007 (but pdflatex fails on this) echo "...Appending figs/ to file " $i awk 'BEGIN{FS="{"}\ /includegraphics/ {\ m=index($0, "{"); n=index($0, "}");\ w=substr($0,m+1,n-m-1); n=split(w,patharray,"/");\ print "\\includegraphics{figs/" patharray[n] "}"; }\ \!/includegraphics/ {print;}\ END{}\ ' $i > $i.x mv -f $i.x $i endif end