Re: How to fix bad EPS output from Display[.., .., "EPS"]
- To: mathgroup at smc.vnet.net
- Subject: [mg15633] Re: [mg15582] How to fix bad EPS output from Display[.., .., "EPS"]
- From: Brian Boonstra <boonstb at cmg.fcnbd.com>
- Date: Sat, 30 Jan 1999 04:28:32 -0500 (EST)
- References: <199901280923.EAA13046@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi I ran into some similar troubles when trying to incorporate Mathematica-generates EPS figures in TeX documents. The problem is with the bounding box that Mathematica creates. At first, I wrote some Python code to fix the trouble (included below, no guarantees), but later I discovered the easiest way to deal with the problem was to copy the figure to the clipboard, paste it in my word processor (which fixed the BB for some reason), and save it from there. You might want to try something similarly low-tech. _______________________________ Dr Brian K Boonstra Vice President, Quantitative Research First National Bank of Chicago 1 First National Plaza Chicago, Illinois 60670 Tel: (312) 732-8368 Fax: (312) 732-5068 Email: boonstb at cmg.fcnbd.com ===== cut here ======== def main(args = None): '''Main execution loop. Creates a new correctMmaEPSFile as a matter of course. ''' import sys if not args: args = sys.argv[1:] if args: file = args[0] else: file = '-' if file == '-': f = sys.stdin else: try: f = open(file, 'r') except IOError, msg: print file, ":", msg sys.exit(1) data = f.readlines() if f is not sys.stdin: f.close() found = 0 foundAt = 0 # Find the bounding box line for line in data[:]: if regex.search("BoundingBox", line) >= 0: found = 1 keyline = line break foundAt = foundAt + 1 if found: newfile = [] # we will turn printing off for the first newpath...clip newpath # sequence, since we want to cut that out foundNewPath = 0 printingOff = 0 # parse the bounding box line for coords coordinates = string.split(keyline) firstValue = string.atof(coordinates[1]) secondValue = string.atof(coordinates[2]) fifthValue = string.atof(coordinates[5]) # print lines up to bounding box for line in data[:foundAt]: newfile.append(line) # print corrected bounding box line newfile.append("""%%BoundingBox: 0 0 """+str(int(0.5+secondValue-firstValue))+" "+str(int(0.5+fifthValue))+"\n") newfile.append("""%%HiResBoundingBox: 0 0 """+str(secondValue-firstValue)+" "+coordinates[5]+"\n") # process remaining lines, clipping first newpath and # fixing translate command for line in data[foundAt+1:]: # stop printing if we found first newpath if (regex.search("newpath",line)>-1) and not foundNewPath: foundNewPath = 1 printingOff = 1 if not printingOff: # fix it if it's a translation line if regex.search(coordinates[1]+'[\.,0-9]* '+coordinates[4]+'[\.,0-9]* translate',line)>-1: newfile.append('0 '+coordinates[5]+' translate\n') else: # otherwise just print it newfile.append(line) # turn printing back on at end of first newpath if (regex.search("clip newpath",line)>-1) and foundNewPath: printingOff = 0 if f is sys.stdin: outfile = sys.stdout else: try: outfile = open(file, 'w') #flock(outfile,'w') except IOError, msg: print file, ":", msg sys.exit(1) outfile.writelines(newfile) if f is not sys.stdin: #flock(outfile,'u') outfile.close()
- References:
- How to fix bad EPS output from Display[.., .., "EPS"]
- From: hsg@lem.phy.duke.edu (Henry S. Greenside)
- How to fix bad EPS output from Display[.., .., "EPS"]