#! /usr/contrib/bin/perl -w # $Id: mmapic,v 1.1 1997/11/20 20:09:44 tjchol01 Exp tjchol01 $ # Convert Mathematica generated PS files stripped of text PS and PDF files # suitable for PDFTeX inclusion. # Depends heavily on idiosyncratic behavior of psrender from Mma-3.0. # It is assumed that the input EPS file is 4 inches wide (288bp). my $defaultwidth = 288; my $defaultscale = 1 / $defaultwidth; #my $pageheight = 792; my $mathroot = "/usr/contrib/apps/mathematica/"; my $psrender = $mathroot . "/SystemFiles/Graphics/Binaries/SGI/psrender"; my $pspath = $mathroot . "SystemFiles/Graphics/SystemResources"; my $ifile = $ARGV[0]; my $file = $ifile; $file =~ s/(.*)\..*/$1/; # strip extension my $no="[0-9\.\-]"; open(INEPS, "$ifile") || die "Usage: mmalabs "; open(PIC, ">$file.pic"); open(EPS, ">$file.eps"); my ($movex, $movey); my ($width, $height, $xoffset, $yoffset); while () { if (/^%%BoundingBox:\s+($no+)\s+($no+)\s+($no+)\s+($no+)/) { print EPS; $width = $3 - $1; $height = $4 - $2; $xoffset = $1; $yoffset = $2; print PIC "\\setlength{\\unitlength}{$defaultscale\\mmawidth} \\begin{picture}($width,$height)($xoffset,$yoffset) \\put($xoffset,$yoffset){\\includegraphics[width=\\mmawidth]{$file}} "; } elsif (/^($no+)\s+($no+)\s+m/) { print EPS; $movex = $1; $movey = $2; } elsif (/^\((.*)\)\s+show/) { # print EPS; my $txt = $1; $txt =~ s/\\\\/\\/g; $txt =~ s/\\\(/\(/g; # unquote parentheses $txt =~ s/\\\)/\)/g; print PIC "\\put($movex,$movey){\$$txt\$}\n"; } elsif (!/setfont|findfont/) { print EPS; } else { # print EPS; } } print PIC "\\end{picture}\n"; close(PIC); close(INEPS); close(EPS); my $yoff = -$yoffset; open(INPDF, "$psrender -pspath $pspath -format pdf -yoff $yoff -width $width -inputfile $ifile |"); open(PDF, ">$file.pdf"); while () { if (!(/^BT/../^ET/)) { s/DummyFont/Courier/g; if (/^\/MediaBox\s+\d+\s+\d+\s+R/) { print PDF "/MediaBox [0 0 $width $height]\n"; } else { print PDF; } } } close(INPDF); close(PDF); exit 0;