Is there a way to avoid having to do ⋮[[⋮
to obtain those great looking brackets for Part
?
Is there a way for this to be done automatically after you ran a function or a definition ?
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.
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).
Mathematica is a symbolic mathematical computation program, sometimes called a computer algebra program, used in many scientific, engineering, mathematical, and computing fields.
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 〚
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With