# Is there a keybinding for absolute value?

Is there a keyboard shortcut or esc-sequence for typing in the absolute value bars into input cells? I know that if you do,

Abs[-4] // TraditionalForm


and copy the output into an input cell using the "Paste literal" option, you get functioning absolute value bars with a placeholder. I'm curious if there's a less roundabout way to obtain them.

• You can define your own function to follow this form: BracketingBar[x_] := Abs[x] Jun 4 '16 at 22:09
• That give the traditional notation in the output (for arguments that are not numeric), but not in input. O.P. requested the notation in Input cells. Jul 15 '16 at 14:48

There isn't a built-in keybinding, but you can define one yourself:

ClearAll[myAbs]

appearanceAbs[x_] :=
TemplateBox[{x}, "myAbs",
DisplayFunction :> (RowBox[{"\[LeftBracketingBar]",
"\[NoBreak]", #1, "\[NoBreak]", "\[RightBracketingBar]"}] &),
InterpretationFunction :> (RowBox[{"myAbs", "[", #1, "]"}] &)]

myAbs[x_?NumericQ] := Abs[x]

myAbs /: MakeBoxes[myAbs[x_], _] := appearanceAbs[ToBoxes[x]]

SetOptions[EvaluationNotebook[],
InputAliases ->
DeleteDuplicates@
Join[{"abs" -> appearanceAbs["\[SelectionPlaceholder]"]},
InputAliases /.
Quiet[Options[EvaluationNotebook[], InputAliases]] /.
InputAliases -> {}]]


This adds a shortcut EscabsEsc to the notebook's InputAliases. When you type it, a template will appear that looks the way one expects, $|\square|$. You may have to tab into it (that's a bug that didn't exist in older versions), and it will evaluate as Abs if the argument you entered is numeric. Otherwise, the display will remain of the form you see in TraditionalForm output. The evaluation of Abs happens because I define the template with an InterpretationFunction. I restrict this to numeric arguments, and for the other cases there is the definition myAbs /: MakeBoxes which kicks in when an unevaluated template is to be displayed again. To make this case distinction possible, I define an intermediate function myAbs.

If one does not mind occupying BracketingBar this can be done quite cleanly.

MakeBoxes[Abs[x_], StandardForm] := MakeBoxes @ BracketingBar[x]

BracketingBar = Abs;


This provides bidirectoinal translation, i.e. Abs[x] is formatted with bars, and also it may be entered with the special characters \[LeftBracketingBar] and \[RightBracketingBar], entered with EscL|Esc and EscR|Esc.

Alternatively one may use the Notation Package to set up bidirectional or unidirectional translation.

• Do you mind adding how you would go about this using the Notation Package? Fine with asking as a separate question if you'd prefer. Feb 9 at 0:09
• @Sterling I have been away from Stack Exchange. Did you solve this in the interim? Mar 6 at 19:04
• No worries. I haven't solved this yet. Mar 8 at 16:07