Friday, December 27, 2013

Customizing Input in Mathematica Notebook

Here we customize the Mathematica Notebook frontend by the following example: bind key ctrl + ] into [[]] (which is array label in Mathematica), and let the cursor stay in the middle of the double brackets.

The way is to modify KeyEventTranslations.tr. This file is located at

Linux:
$MATHEMATICA_HOME/SystemFiles/FrontEnd/TextResources/X

Windows:
$MATHEMATICA_HOME/SystemFiles/FrontEnd/TextResources/Windows

Mac OS:
$MATHEMATICA_HOME/SystemFiles/FrontEnd/TextResources/OSX

One can directly modify this file. But the recommended method (at least under Linux) is to copy this file to user directory. For example, in Linux, this file should be copied to (create the directory before copying)

.Mathematica/SystemFiles/FrontEnd/TextResources/X/

The above copying step can be omitted if one prefers to edit directly system-wide.

After this, insert the following code before the final closing "}]" near the end of the file. Note that one may also need to add a comma in front of this code block, to make this entry an element of the whole list.

Item[KeyEvent["[", Modifiers -> {Control}], FrontEndExecute[{
    FrontEnd`NotebookWrite[FrontEnd`InputNotebook[], "[", After],
    FrontEnd`NotebookWrite[FrontEnd`InputNotebook[], "]", Before]
}]]



No comments:

Post a Comment