I was wondering (because I could not find any documentation on this) if it is possible to do shorthand abbreviations for domains or could one define them?


In[1]:= Element[p,Complexes]
Out[1]= p $\in$ Complexes

to instead do something of the following:

In[1]:= p esc elem esc escCC esc
Out[1]= p$\in\mathbb{C}$

And similarly for others:

$ \begin{align} \text{Algebraics}: &\text{esc AA esc} \,\mapsto\mathbb{A} \\ \text{Rationals}: &\text{esc QQ esc} \,\mapsto\mathbb{Q} \\ \text{Booleans}: &\text{esc BB esc} \,\mapsto\mathbb{B} \\ %%\text{Naturals}: &\text{esc NN esc} \,\mapsto\mathbb{N} \\ \text{Integers}: &\text{esc ZZ esc} \,\mapsto\mathbb{Z} \\ \text{Primes}: &\text{esc PP esc} \,\mapsto\mathbb{P} \\ \text{Reals}: &\text{esc RR esc} \,\mapsto\mathbb{R} \\ \end{align} $

  • $\begingroup$ I removed Naturals, because they are simply Integers in Mathematica. $\endgroup$
    – night owl
    Commented Jun 22, 2012 at 7:16
  • $\begingroup$ night owl, the "Shell Hackers proposal" you link to in your profile no longer exists. $\endgroup$
    – Mr.Wizard
    Commented Mar 16, 2013 at 6:55

3 Answers 3


Shorthand notations:

All those shorthand notations are well documented.

  • For double struck letters like $\mathbb{A}$, use EscdsA, where ds stands for "double struck"

  • For script letters like $\mathcal{A}$, use EscscAEsc, where sc stands for — you guessed it — "script".

Creating your own aliases:

To create your own aliases, use InputAliases. I use it to create shortcuts in this answer, and that might give you some ideas. As for a simple example, try the following:

SetOptions[EvaluationNotebook[], InputAliases -> {"AA" -> "\[DoubleStruckCapitalA]"}]

You should now be able to enter $\mathbb{A}$ as desired.

  • If you're sequentially adding new rules as you think of them, you can use the following:

    SetOptions[EvaluationNotebook[], InputAliases -> 
        Append[OptionValue[Options[EvaluationNotebook[]], InputAliases], newRule]]

    This will append the rules to existing ones for the current notebook.

  • To modify an existing rule, use CurrentValue (courtesy Szabolcs):

    CurrentValue[EvaluationNotebook[], {InputAliases, "AA"}] = "\[DoubleStruckCapitalA]"
  • To set them for all notebooks across all sessions, you can replace EvaluationNotebook[] with $FrontEnd. This will write it to your front end's init.m (located in $UserBaseDirectory/FrontEnd/init.m). Alternately, you can also enter these directly in the init.m, if you maintain it.

You can create a complete list of rules easily as follows:

rules = # <> # -> ToExpression["\[DoubleStruckCapital" <> # <> "]"]& /@ 
    {"A", "B", "C", "N", "P", "Q", "R", "Z"};

Assigning them to the domains

For your purposes, it is as simple as setting $\mathbb{C}$ equal to Complexes, but note that the Attributes of Complexes won't be copied over.

enter image description here

  • $\begingroup$ Thank You. It seems though, when you create multiple assignments -> InputAliases, the memory only hold the last given one. Is there a way where I could store these into the kernal so that way it will always be available to me whenever mathematica is opened, without the need to re-define them and especially each one of them in a single session? $\endgroup$
    – night owl
    Commented Jun 13, 2012 at 0:00
  • $\begingroup$ @nightowl See my edit. $\endgroup$
    – rm -rf
    Commented Jun 13, 2012 at 0:10
  • $\begingroup$ Thanks. So for: InputAliases -> {"AA" -> "\[DoubleStruckCapitalA]"}], do I need to do one for each domain or can I make a list? I guess where I am not sure is if InputAliases a self defined variable or a kernel defined variable? Would I be able to do something of the following: SetOptions[$FrontEnd,InputAliases -> {{"AA" -> "\[DoubleStruckCapitalA]"},{"AA" -> "\[DoubleStruckCapitalA]"},{"CC" -> "\[DoubleStruckCapitalC]"},{"BB" -> "\[DoubleStruckCapitalB]"},{"ZZ" -> "\[DoubleStruckCapitalZ]"},}] and so on. And which one of the two would should be used. 1st or 2nd? $\endgroup$
    – night owl
    Commented Jun 13, 2012 at 0:21
  • $\begingroup$ @nightowl InputAliases is an option for notebooks and the frontend. You can pass a list of rules as you've done in the second case. That's why I directed you to this answer of mine... I create the rules (for that question) by joining strings. You could do something similar to create a rule list and set it for the input aliases. Example: # <> # -> "\[DoubleStruckCapital" <> # <> "]"& /@ CharacterRange["A", "Z"]. $\endgroup$
    – rm -rf
    Commented Jun 13, 2012 at 0:30
  • $\begingroup$ Also, you'll have to wrap that in ToExpression like: ToExpression["\[DoubleStruckCapital" <> # <> "]"] $\endgroup$
    – rm -rf
    Commented Jun 13, 2012 at 0:41

Perhaps this give the behavior that you desire?

$PreRead = # /. 
    {"\[DoubleStruckCapitalC]" -> Complexes,
     "\[DoubleStruckCapitalA]" -> Algebraics,
     "\[DoubleStruckCapitalQ]" -> Rationals,
     "\[DoubleStruckCapitalB]" -> Booleans,
     "\[DoubleStruckCapitalN]" -> Naturals,
     "\[DoubleStruckCapitalZ]" -> Integers,
     "\[DoubleStruckCapitalP]" -> Primes,
     "\[DoubleStruckCapitalR]" -> Reals} &;

$PrePrint = # /. 
    {Complexes  -> "\[DoubleStruckCapitalC]", 
     Algebraics -> "\[DoubleStruckCapitalA]", 
     Rationals  -> "\[DoubleStruckCapitalQ]", 
     Booleans   -> "\[DoubleStruckCapitalB]", 
     Naturals   -> "\[DoubleStruckCapitalN]", 
     Integers   -> "\[DoubleStruckCapitalZ]", 
     Primes     -> "\[DoubleStruckCapitalP]", 
     Reals      -> "\[DoubleStruckCapitalR]"} &;

Now you can enter these with Escds*Esc where * is the letter, and they will be interpreted as the corresponding domain. Also, the domains will be printed as a double-struck letter.

As noted in the comments Naturals is not a valid Mathematica domain but I kept your notation for consistency.

To load these for all sessions on start-up, put this code into one of your init.m files, probably this one: FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}].

For custom input aliases add them to the InputAliases list, possibly using the Option Inspector, or with this, but only run it once:

old = Options[$FrontEnd, "InputAliases"][[1, 2]];

new = Join[old,
   {"CC" -> "\[DoubleStruckCapitalC]",
    "AA" -> "\[DoubleStruckCapitalA]",
    "QQ" -> "\[DoubleStruckCapitalQ]",
    "BB" -> "\[DoubleStruckCapitalB]",
    "NN" -> "\[DoubleStruckCapitalN]",
    "ZZ" -> "\[DoubleStruckCapitalZ]",
    "PP" -> "\[DoubleStruckCapitalP]",
    "RR" -> "\[DoubleStruckCapitalR]"}];

SetOptions[$FrontEnd, InputAliases -> new]
  • 1
    $\begingroup$ Naturals is not a valid domain in Mathematica $\endgroup$
    – rm -rf
    Commented Jun 13, 2012 at 0:56
  • $\begingroup$ @R.M I noticed this, but the OP lists it so I did too. Also, some of the letter choices seem odd to me, but I didn't question them. $\endgroup$
    – Mr.Wizard
    Commented Jun 13, 2012 at 0:57
  • $\begingroup$ @Mr.Wizard: Thanks. How would I make this be possible to be stored for all sessions even after shutting it down? And if possible make the shorcut keys more flexible? I am not used to esc ds esc. It just not come right to mind when thinking in terms of domain, but rather the type of letter itself. $\endgroup$
    – night owl
    Commented Jun 13, 2012 at 8:00
  • $\begingroup$ @nightowl see update. $\endgroup$
    – Mr.Wizard
    Commented Jun 13, 2012 at 10:01
  • $\begingroup$ @Mr.Wizard: I got the esc dsR esc to print $\mathbb{R}$, but it is not interpreted as the domain of Reals. How could I get it like the updated version to be: k esc elem esc esc RR esc $~\mapsto~$ $k \in \mathbb{R}$. where $\mathbb{R}$ represent the Reals and not just the \[DoubleStruckCapitalR]. Also to be automatically loaded for each Mathematica session? $\endgroup$
    – night owl
    Commented Jun 22, 2012 at 7:27

First, it hasn't been pointed out yet that the Notation package has the command AddInputAlias which is in principle designed to do what this question requires. There is even a palette for it.

However, if you want to add several aliases all at once, the manual approach of the Notation package is inconvenient. One way to automate the creation of shortcuts is this:

addInputAliases[rules_List] := 
  InputAliases -> 
     InputAliases /. 
       Quiet[Options[EvaluationNotebook[], InputAliases]] /. 
      InputAliases -> {}]

Here I query the existing options of the EvaluationNotebook and replace the result by an empty list if there was an error getting the InputAliases option. I do this because when I open a new notebook (from an existing one) in Mathematica version 10, the command Options[EvaluationNotebook[], InputAliases] gives an error which has to be caught.

Now to implement the specific shortcuts in the question, I construct the aliases starting from a list of domains, using the fact that Mathematica already knows the corresponding abbreviations. They are used automatically in TraditionalForm output, so I extract them from that in the list symbols, instead of manually entering them. To construct the input aliases, I apply simple arithmetic to the character codes of the double-struck symbols:

domains = {Complexes, Reals, Algebraics, Rationals, Booleans, 
  Integers, Primes}

==> {Complexes, Reals, Algebraics, Rationals, Booleans, Integers, \

symbols = 
 Cases[ToBoxes[#, TraditionalForm] & /@ domains, 
  TagBox[x_, __] :> x, Infinity]

==> {"\[DoubleStruckCapitalC]", "\[DoubleStruckCapitalR]", "\
\[DoubleStruckCapitalA]", "\[DoubleStruckCapitalQ]", "\
\[DoubleStruckCapitalB]", "\[DoubleStruckCapitalZ]", "\

aliases = 
 Map[(# <> # &), 
     ToCharacterCode[#] - ToCharacterCode["\[DoubleStruckCapitalA]"] +
       ToCharacterCode["A"]] & /@ symbols]

(* ==> {"CC", "RR", "AA", "QQ", "BB", "ZZ", "PP"} *)

rules = 
   Function[{alias, domain, 
     symbol}, (alias -> 
      TemplateBox[{}, domain, DisplayFunction :> (RowBox[{symbol}] &),
        InterpretationFunction :> (RowBox[{domain}] &)])],
   {aliases, ToString /@ domains, symbols}];


Here are some tests, entered as shown in the image:


Here is how they are interpreted:

I ∈ Reals

(* ==> False *)

I ∈ Complexes

(* ==> True *)

Sqrt[2] ∈ Algebraics

(* ==> True *)

7 ∈ Primes

(* ==> True *)

7 ∈ Integers

(* ==> True *)

The way I defined the double-struck symbols using TemplateBox, they can also be copied from an output cell into a new input cell without losing the intended interpretation.


Your Answer

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

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