# Using standard notation for vector magnitude

The mathematical notation for the magnitude of a vector is $$\vert x \vert$$, but this does not work:

∥ {1, 2, 3} ∥


Is there any way to overload the DoubleVerticalBar symbol so my Mathematica code would look like a textbook formula?

• Please try Norm. Nov 11, 2020 at 11:30
• @ΑλέξανδροςΖεγγ I know about Norm, but I would like to use a "nicer" notation for it Nov 11, 2020 at 11:32

If you only want to have the "nice" format for input, you could assign Norm to DoubleBracketingBar (which is equivalent to \[LeftDoubleBracketingBar] # \[RightDoubleBracketingBar] &)

DoubleBracketingBar := Norm
DoubleBracketingBar[x]
(* Norm[x] *)


Alternatively, and more usable, you could use the Notation package

Needs["Notation"]
Notation[ParsedBoxWrapper[
RowBox[{"DoubleBracketingBar", "[", "x_",
"]"}]] \[DoubleLongLeftRightArrow] ParsedBoxWrapper[
RowBox[{"Norm", "[", "x_", "]"}]]]
Notation[ParsedBoxWrapper[
RowBox[{"\[LeftDoubleBracketingBar]", "x_",
"\[RightDoubleBracketingBar]"}]] \[DoubleLongLeftRightArrow]
ParsedBoxWrapper[
RowBox[{"Norm", "[", "x_", "]"}]]]


Which is displayed more readable as

The usage is then as expected:

DoubleBracketingBar[x] // FullForm
(* Norm[x] *)
\[LeftDoubleBracketingBar]x\[RightDoubleBracketingBar] \
// FullForm
(* Norm[x] *)
Norm[x]
(* \[LeftDoubleBracketingBar]x\[RightDoubleBracketingBar] *)


Edit: By the way, the reason I did not use \[DoubleVerticalBar] is because it is built in as an infix operator.

• Thank you a lot! Do you happen to know an easy way to insert the special character for DoubleBracketingBar aswell? It isn't in the Esc menu Nov 11, 2020 at 15:48
• @lama12345 Esc-l||-Esc and Esc-r||-Esc (left and right double bar) works. Nov 11, 2020 at 15:56

You could create an input alias for this:

CurrentValue[EvaluationNotebook[], {InputAliases, "norm"}] = TemplateBox[
{"\[SelectionPlaceholder]"},
"Norm"
]


The only downside is you have to tab to the placeholder.

• Wow, Norm with DoubleBracketingBar` feels like a native construct now (at least for one notebook). Thank you a lot! Nov 12, 2020 at 8:48