19
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Has anyone done this recently? Also, in Windows, I think you need to "run as administrator" for whatever application you're using to edit MenuSetup.tr (e.g. notepad). $\endgroup$
    – Sterling
    Oct 28, 2020 at 20:28

2 Answers 2

16
$\begingroup$

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.

$\endgroup$
2
$\begingroup$
  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.

$\endgroup$

Your Answer

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

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