8
$\begingroup$

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):

enter image description here

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

enter image description here

...all works fine.

enter image description here

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.

$\endgroup$
17
  • $\begingroup$ Can increasing ImageSize->... option to 'Plot` help ? $\endgroup$ Commented Jan 31, 2012 at 3:13
  • $\begingroup$ 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. $\endgroup$ Commented Jan 31, 2012 at 3:21
  • $\begingroup$ Any idea what format the graphic is in? (The service isn't working on my computer for some reason.) $\endgroup$ Commented Jan 31, 2012 at 5:22
  • $\begingroup$ @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) $\endgroup$ Commented Jan 31, 2012 at 5:25
  • 1
    $\begingroup$ 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. $\endgroup$
    – ragfield
    Commented Feb 4, 2012 at 5:24

1 Answer 1

3
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ (+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. $\endgroup$
    – Jens
    Commented May 16, 2012 at 15:15
  • $\begingroup$ 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. $\endgroup$
    – azdahak
    Commented May 16, 2012 at 16:40
  • $\begingroup$ 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. $\endgroup$ Commented May 17, 2012 at 22:28
  • $\begingroup$ 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. $\endgroup$
    – azdahak
    Commented May 18, 2012 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.