I want to setup aliases for Mma functions in a proper manner.
Currently, I copy and paste several aliases to a cell in a new notebook like:
tf:=TableForm
fi:=FactorInteger
re:=RegularExpression
and so forth.
When I searched for aliases in the doc I found descriptions of the Esc ... Esc method, and a chapter on Defining Custom Notation. I hoped to find some initialization file for defining aliases, I suppose. I am somewhat confused at the moment.
Question: - What is the common / proper / best way to define function aliases that you use in any new Notebook ?
To define the input aliases for your specific notebook, you need to append them to the default ones. So code like
SetOptions[EvaluationNotebook[],
InputAliases -> Join[InputAliases/.Options[EvaluationNotebook[], InputAliases],
{"tf" -> TableForm, "fi" -> FactorInteger, "re" -> RegularExpression}]]
will do the trick. (Although, this will not overwrite existing aliases of the same name. So you have to be more careful if need to redefine an existing alias.)
To add these aliases to all notebooks, you can:
$FrontEnd
object (instead of a Notebook object). Option Inspector (Global Preferences) > Editing Options > InputAliases
and use the interface provided.
(This can also be used to change the aliases for any open notebook by selecting it from the dropdown menu.)The first two options will add the definitions to the init.m
file which should be located at FileNameJoin[{$UserBaseDirectory, "FrontEnd", "init.m"}]
.
For example, my "init.m"
file contains the non-standard input alias "l=" -> \[LongEqual]
, since I typeset quite a bit of maths.
Also, if you don't want your input alias to expand the "tf"
out to the full TableForm
, then maybe you could use something like
"tf" -> InterpretationBox[StyleBox["tf", FontSlant -> Italic,
FontColor -> GrayLevel[0.5], Selectable -> False], TableForm]
This keeps the compactness of your original definitions, but does not require the introduction of new symbols to your global context (or a new context). It looks like
To turn the tf
into TableForm
just select it and press Ctrl-Shift-I
, i.e., convert it to InputForm
.
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