# How do you get high resolution plots in applications using the Mathematica MathService?

This is for Mac users only using MathService (MathService it seems, given that it was created back in 2004, is a power pc code and requires Rosetta to run on Intel).

If I type a plot command in another application (in this case TextEdit):

...and then use Mathematica to evaluate that code within that application using MathService:

...all works fine.

But the problem then arises when you want to print the document because the graphic is at screen resolution. Does anyone know how to use MathService to generate print quality plots within other applications?

Also in MS Word it seem that only the "Evaluate to Text" service is available which (obviously) returns FullForm of the plot rather than the graphic. Why isn't "Evaluate to Graphic" available?

Incidentally using Mathematica this way seems to allow multiple undos of kernel evaluations.

-
Can increasing ImageSize->... option to 'Plot help ? – Vitaliy Kaurov Jan 31 '12 at 3:13
No. it has no effect. But it is nice to be able to continually undo these evaluations. Wish you could do that natively in Mma. – Mike Honeychurch Jan 31 '12 at 3:21
Any idea what format the graphic is in? (The service isn't working on my computer for some reason.) – Brett Champion Jan 31 '12 at 5:22
@Brett. no. Any idea how I would identify the format once it has been inserted into the document? I am using 32 bit 10.6.8 but I have used MathService on and off for several years with 10.4 and 10.5. Are you using Lion? (I have never tried MathService on my 64 bit laptop) – Mike Honeychurch Jan 31 '12 at 5:25
The short answer is no, there is no way to generate a graphic in a format other than TIFF. When I get a chance I'll update it to allow PDF (vector) graphics and compile it for Intel. – ragfield Feb 4 '12 at 5:24

Try this.

1) Open Automator and create a new Service.

2) In the search box, type "Run Apple Script" and drag the action into the workflow space on the right.

3) Replace the sample script (changing MyName appropriately) with:

on run {input, parameters}
set inputResult to (input as string)
set cmd to " -run 'Export[\"~/Desktop/test.pdf\"," & input & "];Exit[]'"
set mathPath to POSIX path of file ((path to application "Mathematica" as text) & "Contents:MacOS:MathKernel")

do shell script mathPath & cmd
set the clipboard to (alias "Users:MyName:Desktop:test.pdf") as «class furl»

tell application "System Events"
keystroke "v" using {command down}
end tell

end run


4) Hit the hammer icon to verify the code, then save the file to give the service a name.

5) In TextEdit try something like

Plot[Sin[x],{x,0,Pi},PlotStyle->{Dashed,Red},ImageSize->500]


or

Style[TraditionalForm[Integrate[Gamma[Pi x]y[x],{x,0,2}]],FontSize->48]


It will embed a high quality PDF, saving the temp file to the desktop.

-
(+1) I like the keystroke trick to do the pasting! Pasting from clipboard is something Automator doesn't have out of the box. I recall using keystrokes like that when controlling an old non-scriptable application (Rita), and it comes in handy here. My main general concern is that for bad input, Mathematica scripts could run really long or lead to zombie processes if they fail. If that happens enough times you suddenly won't be able to start a new MMA process. So I would wrap the MMA input in TimeConstrained`. – Jens May 16 '12 at 15:15
Good idea, Jens. This was admittedly a bit of a hack which is why I just saved the file to the desktop. Since I use LaTeX for just about everything I don't have much need of this service. But I got curious about services and wanted to see if I could create one to do what the OP was asking in a transparent way. – azdahak May 16 '12 at 16:40
I can't get this to work -- an applescript error is returned. The temp PDF is saved to the desktop but when i look at the clipboard it is empty but nothing has been pasted in the TextEdit document. – Mike Honeychurch May 17 '12 at 22:28
I assume the PDF file has the proper plot which means the first half is working. Did you change the "MyName" in the code to the proper path? I think Applescript has built in alias paths for the desktop, but I just hardcoded it here. – azdahak May 18 '12 at 14:16