;;;; Manodeep Sinha 06/01/2011 v 1.0 ;;;; Blatantly copied from vis_psfrag from Michael Galloy (see ;;;; http://www.astrobetter.com/idl-psfrag/). ;;;; ;;;; ;;;; Here is the template latex file (figure.tex.sed) that I use: ; ; \documentclass{article} ; \usepackage{times} ; \usepackage{geometry, graphicx, psfrag} ; \pagestyle{empty} ; \geometry{paperwidth=12.1cm,paperheight=8.1cm,margin=0pt} ; \begin{document} ; \psfrag{tag_text}[c][c][1.5]{replacement_text} ; \includegraphics[width=11.9cm,height=7.9cm]{filename} ; \end{document} ; ;;;; ;;;; Of course, while opening the ps device in IDL -- use /times ;;;; keyword. Otherwise, the fonts will be different for other text ;;;; that already exists in the plot. The code is still less than ;;;; satisfactory since the replaced text size does not seem to ;;;; correspond exactly with the IDL charsize. The 1.5 in the \psfrag ;;;; gives me the closest (by eye) in terms of font size. The code is ;;;; not tested at all -- it did work for the one case that I ;;;; needed. The replacement text was '{\bf{log M [M$_\odot$/h]}}'. ;;;; ;;;; Needs str_replace, arr2str and str2arr from UWash library ;;;; http://www.astro.washington.edu/docs/idl/idllib/ssw/allpro/ ;;;; ;;;; pro ms_psfrag, infname,templatefname,outfname,tag_text,replacement_text compile_opt idl2,strictarrsubs,logical_predicate ;on_error,2 if n_elements(infname) eq 0 or n_elements(templatefname) eq 0 then begin print,'Error: Need both input eps file and the template tex file' return endif if file_test(infname) ne 1 or file_test(templatefname) ne 1 then begin print,infname,templatefname,format='("Error: Can not find files: ",A," ",A)' return endif catch, error if error ne 0L then begin catch, /cancel if n_elements(tmpdir) gt 0L then file_delete, tmpdir, /recursive message, /reissue_last endif if n_elements(outfname) eq 0 then outfname = 'idl.eps' tmpdir = filepath(string(systime(/seconds), format='(%"psfrag-%f")'), /tmp) file_mkdir, tmpdir ;;; make a list of all the temp. file names tex_filename = filepath('figure.tex', root=tmpdir) dvi_filename = filepath('figure.dvi', root=tmpdir) ps_filename = filepath('figure.ps', root=tmpdir) epsi_filename = filepath('figure.epsi', root=tmpdir) eps_filename = filepath('figure.eps', root=tmpdir) ;;; make the filename and replacement text sed-safe. '\' must appear ;;; first in the list. Add in any others at the end.. splchars = ['\','[',']','$','/'] new_replacement_text = replacement_text new_infname = infname for i=0L,n_elements(splchars)-1 do begin chr = splchars[i] if (chr eq '\') eq 1 then begin rep_chr = '\\\' endif else begin rep_chr = '\' + chr endelse new_replacement_text = str_replace(new_replacement_text,chr,rep_chr) new_infname = str_replace(new_infname,chr,rep_chr) endfor ;;;;; tag_text is the place holder in the latex template file. Will be ;;;;; replaced by the actual content of the tag_text variable. Note ;;;;; that tag_text variable is not made sed-safe. Presumably, people ;;;;; will use a `reasonable' text tag. so on for the replacement_text ;;;;; and filename..(except that those two are made sed-safe) sedCmdF = '(%"sed -e\"s/filename/%s/g\" -e\"s/tag_text/%s/g\" -e\"s/replacement_text/%s/g\" %s > %s")' sedCmd = string(new_infname, $ tag_text,new_replacement_text,$ templatefname, tex_filename, $ format=sedCmdF) spawn, sedCmd, sedOutput, sedErrorOutput, exit_status=sed_status if (sed_status ne 0L) then message, 'sed command failed' ;; run latex texCmdF = '(%"latex -output-directory %s %s")' texCmd = string(tmpdir, tex_filename, $ format=texCmdF) ;print,texcmd spawn, texCmd, texOutput, texErrorOutput, exit_status=tex_status if (tex_status ne 0L) then message, 'LaTeX command failed' ;;; run dvips to produce PostScript file dvipsCmdF = '(%"dvips -o %s %s")' dvipsCmd = string(ps_filename, $ dvi_filename, $ format=dvipsCmdF) spawn, dvipsCmd, dvipsOutput, dvipsErrorOutput, exit_status=dvips_status if (dvips_status ne 0L) then message, 'dvips command failed' ;;; run ps2epsi ps2epsiCmdF = '(%"ps2epsi %s %s")' ps2epsiCmd = string(ps_filename,epsi_filename,format=ps2epsiCmdF) spawn,ps2epsiCmd,psoutput,pserroroutput,exit_status=ps2epsi_status if ps2epsi_status ne 0L then message, 'ps2epsi command failed' ;;; strip out the preview part for the epsi files execstring = "perl -ne 'print unless /^%%BeginPreview/../^%%EndPreview/' < " + epsi_filename + ' > ' + eps_filename spawn,execstring,perloutput,perlerroroutput,exit_status=perl_status if perl_status ne 0L then message,'perl command failed' ;;; write the new figure to the desired directory file_copy, eps_filename, $ file_expand_path(outfname), $ /overwrite file_delete, tmpdir, /recursive end