#!/usr/bin/perl # Assuming that you have perl, and that you have changed the permissions on this file so that it can be executable ("chmod figtex2eps") # then the usage is: # figtex2eps [file] # # written by: Jaideep Singh # date: April 11, 2006 # email: singhj AT jlab DOT org # # description: creates an eps file from a xfig that has been exported in "Combined PS/LaTeX" format # OR automatically creates the requisite pstex and pstex_t files using fig2dev # # NOTE: works better when you export the fig in "Combine PS/LaTeX" format in xfig first # the font size doesn't always work well, but is almost always worse using fig2dev #----- #XFIG: (http://www.xfig.org/userman/latex_and_xfig.html) #----- #1. Use latex commands (like math mode: $\sigma$) in the text objects #2. For these text objects, use the "Special Flag" in the edit panel #3. Export as "Combined PS/LaTeX (both parts)" #4. You should now have the files: "foo.fig" , "foo.pstex" , "foo.pstex_t" #------ #LATEX: #------ #1. Create a Latex file "foo.tex" that looks like the following: #%%%%%%%%%%%%% CUT HERE #\documentclass[letterpaper]{article} # #\usepackage[dvips] #\usepackage{graphicx} # #\pagestyle{empty} #\topmargin = 0pt #\headheight = 0pt #\headsep = 0pt #\textheight = 9.5in #\footskip = 0pt #\oddsidemargin = 0pt #\evensidemargin = 0pt #\marginparsep = 0pt #\marginparwidth = 0pt #\paperwidth = 6.0in # #\begin{document} # \input{foo.pstex_t} #\end{document} #%%%%%%%%%%%%% CUT HERE #----- #DVIPS #----- #1. Run the dvips with the -E option: # #dvips -E foo.dvi -o foo.eps # #STEP 0: check the arguments and determine whether pstex and pstex_t files exist $file = $ARGV[0]; $is_fig_file = qx(file $file); die "Input file must be an xfig file: $file\n" unless ($is_fig_file =~ /FIG image text/); @file_parts = split(/\.fig/,$file); $base = $file_parts[0]; print "Processing file($base): $file\n"; $is_pstex = qx(file $base.pstex); $is_pstex_t = qx(file $base.pstex_t); if (($is_pstex =~ /cannot open/) or ($is_pstex_t =~ /cannot open/)) { print "creating pstex and pstex_t files!\n"; #STEP 1: create the *.pstex file using the command fig2dev $ok_pstex = qx(fig2dev -L pstex $file $base.pstex); die "Creating pstex file failed" unless ($ok_pstex == ""); #STEP 2: create the *.pstex_t file using the command fig2dev and add the include lines for the pstex file open(FILE_PSTEX_T,">$base\.pstex_t"); print FILE_PSTEX_T "\\begin{picture}(0,0)\%\n"; print FILE_PSTEX_T "\\includegraphics{$base\.pstex}\%\n"; print FILE_PSTEX_T "\\end{picture}\%\n"; close(FILE_PSTEX_T); $ok_pstex_t = qx(fig2dev -L pstex_t $file >> $base.pstex_t); die "Creating pstex_t file failed" unless ($ok_pstex_t == ""); } else { print "BOTH pstex and pstex_t files already exist\n"; } #STEP 3: create the latex file to process the latex commands in the pstex_t file open(FILE_TEX,">$base\.tex"); print FILE_TEX "\\documentclass[letterpaper]{article}\n"; print FILE_TEX "\n"; print FILE_TEX "\\usepackage[dvips]{pstcol}\n"; #print FILE_TEX "\\usepackage{graphicx,psfig}\n"; #print FILE_TEX "\\usepackage[dvips]\n"; print FILE_TEX "\\usepackage{graphicx}\n"; print FILE_TEX "\n"; print FILE_TEX "\\pagestyle{empty}\n"; print FILE_TEX "\\topmargin = 0pt\n"; print FILE_TEX "\\headheight = 0pt\n"; print FILE_TEX "\\headsep = 0pt\n"; print FILE_TEX "\\textheight = 9\.5in\n"; print FILE_TEX "\\footskip = 0pt\n"; print FILE_TEX "\\oddsidemargin = 0pt\n"; print FILE_TEX "\\evensidemargin = 0pt\n"; print FILE_TEX "\\marginparsep = 0pt\n"; print FILE_TEX "\\marginparwidth = 0pt\n"; print FILE_TEX "\\paperwidth = 6\.0in\n"; print FILE_TEX "\n"; print FILE_TEX "\\begin{document}\n"; print FILE_TEX " \\input{$base\.pstex_t}\n"; print FILE_TEX "\\end{document}\n"; close(FILE_TEX); #STEP 4: create a dvi file from the latex file $ok_dvi = qx(latex $base); print "Font Warning!! check image!\n" if ($ok_dvi =~ /LaTeX Font Warning/); #STEP 5: create the eps file from the dvi file $ok_eps = qx(dvips -E $base.dvi -o $base.eps); #STEP 6: delete auxilliary files $delete_stuff = qx(rm -f $base.tex); $delete_stuff = qx(rm -f $base.log); $delete_stuff = qx(rm -f $base.dvi); $delete_stuff = qx(rm -f $base.aux);