Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way around using [[ and ]] for Part in Mathematica?

Is there a way to avoid having to do ⋮[[⋮ to obtain those great looking brackets for Part?

enter image description here

Is there a way for this to be done automatically after you ran a function or a definition ?

like image 771
500 Avatar asked Sep 06 '11 23:09

500


People also ask

How do you do brackets in Mathematica?

You can do this by clicking below the last command with your pointer until you see a horizontal line. One of the first stumbling points in Mathematica is the use of parentheses and brackets. In Mathematica, it's always brackets [ ] that are used to indicate the argument of a function.

What does ampersand mean in Mathematica?

The ampersand denotes the end of the pure function (so that in more complicated expressions one could use several pure functions and limit what they do).

What is the meaning of Mathematica?

Mathematica is a symbolic mathematical computation program, sometimes called a computer algebra program, used in many scientific, engineering, mathematical, and computing fields.


2 Answers

I have the following addition in /Applications/Mathematica.app/SystemFiles/FrontEnd/TextResources/Macintosh/KeyEventTranslations.tr which lets me enter double brackets with key combinations. You can do the same by modifying the file (where ever it is on your OS). I first learnt of this from Szabolcs's website here. He has other mathematica related stuff there that might be of help to you.

The commands added are:

  • with Ctrl+[
  • with Ctrl+]
  • 〚〛 with Ctrl+Alt+]

Equivalents, as listed in the KeyEventTranslations.tr file are:

Modifiers can be "Shift", "Control", "Command", "Option"

For Macintosh: "Command" = Command Key, "Option" = Option Key

For X11: "Command" = Mod1, "Option" = Mod2

For Windows: "Command" = Alt, "Option" = Alt

Insert the following after EventTranslations[{ in the above file.

(* Custom keyboard shortcuts *)
    Item[KeyEvent["[", Modifiers -> {Control}],
        FrontEndExecute[{
            FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],
                "\[LeftDoubleBracket]", After]
        }]],
    Item[KeyEvent["]", Modifiers -> {Control}],
        FrontEndExecute[{
            FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],
                "\[RightDoubleBracket]", After]
        }]], 
    Item[KeyEvent["]", Modifiers -> {Control, Command}],
        FrontEndExecute[{
            FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],
                "\[LeftDoubleBracket]", After],
            FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],
                "\[RightDoubleBracket]", Before]
        }]], 

You're not the only one who's peeved by it. Here's my attempt to avoid having to stretch to hit Esc by mapping Caps lock to Esc. Mr. Wizard also had a couple of questions related to conversion of [[ to .

like image 144
abcd Avatar answered Oct 12 '22 20:10

abcd


My preference is the following (code fixed thanks to Sjoerd C. de Vries):

n = SelectedNotebook[];
SetOptions[n, 
 InputAliases -> 
  Append[Options[n, InputAliases][[1, 2]], 
   "[]" -> "\[LeftDoubleBracket]\[SelectionPlaceholder]\[RightDoubleBracket]\[Placeholder]"]]

This adds a new input alias ⋮[]⋮ that inserts both [[ and ]], places the cursor on a placeholder inside the brackets, and puts another placeholder outside the brackets which you reach by pressing Tab.

Try it and see. If you like it, you can add it to your Global options: Format -> Option Inspector -> Show option values -> Global preferences -> Search for InputAliases.

You could also combine this with the keyboard shortcut solution proposed by yoda.

like image 43
Andrew Moylan Avatar answered Oct 12 '22 19:10

Andrew Moylan