Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

If you edit the

Wolfram Research\Mathematica\8.0\SystemFiles\FrontEnd\TextResources\Windows\MenuSetup.tr

file you can make Ctrl+Shift+C copy not plain but in $\LaTeX$ format. Very useful. Look for the line in the file that says "&LaTeX" and the one that says "Plain &Text". The & sign gives the underscore letter in the menu. Then replace them with the following:

MenuItem["Plain &Text", FrontEnd`CopySpecial["PlainText"]],
         MenuItem["&LaTeX", KernelExecute[ToExpression["FrontEnd`CopyAsTeX[]"]],
         MenuKey["C", Modifiers->{"Control", "Shift"}],
         MenuEvaluator -> Automatic],

Restart Mathematica and you are done.

The question I have is if anyone knows what MenuEvaluator does, or if you know how to do this modification from a notebook in Mathematica rather than modifying the config file.

share|improve this question
add comment

migrated from stackoverflow.com Feb 5 '12 at 1:26

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 12 down vote accepted

MenuEvaluator->Automatic uses the default kernel to evaluate the expression in the menu. MenuEvaluator->None is the default, which means that the front end "evaluates" the expression (which generally means the expression is composed only of FE tokens and packets). One could also use MenuEvaluator->"kernelname" to point to an explicit kernel.

For doing the kind of menu editing you wish to do, you have to rewrite the menus wholesale. You can begin by reading the menu from the layout, tweaking it how you want, and then sending it to the FE in ResetMenusPacket. Here's an example:

Begin["System`"];
menu = Get[
   FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", 
     "TextResources", "Windows", "MenuSetup.tr"}]];
End[];
menu = menu /. {MenuItem["Plain &Text", ___] -> 
     MenuItem["Plain &Text", FrontEnd`CopySpecial["PlainText"]], 
    MenuItem["&LaTeX", ___] -> 
     MenuItem["&LaTeX", 
      KernelExecute[ToExpression["FrontEnd`CopyAsTeX[]"]], 
      MenuKey["C", Modifiers -> {"Control", "Shift"}], 
      MenuEvaluator -> Automatic]};
FrontEndExecute[FrontEnd`ResetMenusPacket[menu]]

Some notes about this code:

  • A number of symbols in the menu expression aren't in the System` context, but need to be for this to work. That's the reason for the Begin/Endcalls.
  • To make this code work on Linux, replace "Windows" with "X"
  • To make this code work on Mac, replace "Windows" with "Macintosh", "Control" with "Command", and remove the ampersands.
  • This code only work on v7 and later (when MenuItem was introduced)

Finally, and this is really important, you need to be playing with this stuff in a fresh session of Mathematica, and frequently either saving your work or copying to the clipboard. If you make any mistakes, you can lose all of your menus, including the ability to evaluate, save, or copy. You might be able to recover by using the contextual menu, but probably safer to just quit and restart.

Assuming you haven't really hosed your menus, you can reset to the default by evaluating:

FrontEndExecute[FrontEnd`ResetMenusPacket[{Automatic}]]

Another option is to simply make your own MenuSetup.tr which is in $UserBaseDirectory or $BaseDirectory, in the same location it is now in $InstallationDirectory. But I don't generally advise this because, if you do, all copies of Mathematica will find it, including past and future versions, which could cause you hopeless confusion.

share|improve this answer
add comment
  1. I believe that MenuEvaluator -> Automatic automatically selects a kernel to run KernelExecute[ . . . ] on. By comparison the MenuItem directly above it relies only on the FrontEnd itself.

  2. I do not know of a way to make this change without editing that file. There is a limited way to add menu commands but I do not believe you can overwrite existing key combinations with it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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