3
$\begingroup$

I would like to add another command to "Save as" menu that is generated by right clicking on selected text.

enter image description here

We have there "Plain Text" and after this I would like to add "Sagemath code". After clicking on it the text/code would be copied as plaintext with addition that spaces that represent multiplication would be replaced with "*".

For example if you "copy as plain text" this code 3 x^2 + 2 x + 1 you get string "3 x^2 + 2 x + 1" but I would like it to be 3*x^2 + 2*x + 1 because Sagemath recognizes only "*" as multiplication.

Sorry no code from me. I have no clues how to do it.

Update:

Why the code from here does not work anymore?

The code should rewrite the file MenuSetup.tr with new menu (in my code with unchanged default menu) but when I look at the file its modification time is not changed which means nothing was done to the file Wolfram Research\Mathematica\8.0\SystemFiles\FrontEnd\TextResources\Windows\MenuSetup.tr.

Begin["System`"];
menu = Get[
   FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", 
     "TextResources", "Windows", "MenuSetup.tr"}]];
End[];
FrontEndExecute[FrontEnd`ResetMenusPacket[menu]]
$\endgroup$

1 Answer 1

1
$\begingroup$

In fact it is the file ContextMenus.tr that has to be modified. I did it manually in text editor.

In the "Input" -> { section of the file I added:

MenuItem["SageMath", FrontEndExecute[{FrontEnd`NotebookApply[FrontEnd`InputNotebook[],"InputForm[\[SelectionPlaceholder]]",All],FrontEndToken["Evaluate"]}]]

It applies InputForm to selected code.

enter image description here

enter image description here

I was unable to figure out how to also copy it to clipboard.

If someone see a way to add copy to clipboard after applying InputForm or even better leave the selected code untouched just copy it to clipboard in "input form" I would be happy to see it.

$\endgroup$

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.