13

Why are bra and ket defined in the official package braket.sty in two different ways (\bra, \Bra and \ket, \Ket)?

I do not understand why there exists the command \bra with non-scalable delimiters. For stylistic reasons, I intuitively used the capital letter versions. Were you ever confronted with the second non-scalable version?

See the short example for bra:

\documentclass{article}
\usepackage{amsmath}
\usepackage{braket}

\begin{document}

\begin{align*}
\Bra{\frac{1}{\sqrt{2}}\left(\uparrow + \downarrow\right)}
  &=\frac{1}{\sqrt{2}}\left(\Bra{\uparrow}+\Bra{\downarrow}\right)\\
\bra{\frac{1}{\sqrt{2}}\left(\uparrow + \downarrow\right)}
  &=\frac{1}{\sqrt{2}}\left(\bra{\uparrow}+\bra{\downarrow}\right)\\
&=2 222 22\\
&=2\mathinner{222}22
\end{align*}

\end{document}

Understanding of the package's definition

For amsmath noobs like myself, the last two lines in the align environment review what \mathinner does (if you look at the braket.sty's package source code). The package defined the commands the following way:

\def\bra#1{\mathinner{\langle{#1}|}}
\def\ket#1{\mathinner{|{#1}\rangle}}
\def\Bra#1{\left\langle#1\right|}
\def\Ket#1{\left|#1\right\rangle}
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
strpeter
  • 5,215
  • I wouldn't use the package (I'm not saying it is bad at all, I just wouldn't use it); I would define my own macros as done here. – Svend Tveskæg Dec 07 '13 at 08:46
  • What is the advantage of using mathtools' command \DeclarePairedDelimiter for the delimiters? You cannot apply user-defined scaling like \Bigg either (you wrote about it in your answer below). – strpeter Dec 09 '13 at 16:02

3 Answers3

17

The macros with uppercase initial are "self-expanding" based on the contents, as the documentation says. Just like it's not good to always use \left and \right, it's also good to choose with care between \Bra and \bra.

As far as the additional spacing is concerned, a solution is to load mleftright:

\documentclass{article}
\usepackage{amsmath}
\usepackage{braket,mleftright}
\mleftright

\begin{document}

\begin{align*}
\Bra{\frac{1}{\sqrt{2}}\left(\uparrow + \downarrow\right)}
  &=\frac{1}{\sqrt{2}}\left(\Bra{\uparrow}+\Bra{\downarrow}\right)\\
\bra{\frac{1}{\sqrt{2}}\left(\uparrow + \downarrow\right)}
  &=\frac{1}{\sqrt{2}}\left(\bra{\uparrow}+\bra{\downarrow}\right)\\
&=2 222 22\\
&=2\mathinner{222}22\\
\end{align*}

\end{document}

enter image description here

David Carlisle
  • 757,742
egreg
  • 1,121,712
  • Why did you use mleftright? Stylistic question: Were you ever confronted with the non-scalable version? – strpeter Apr 13 '13 at 11:14
  • @strpeter \mleftright redefines \left and \right to use the "non spaced" version (that is, to \mleft and \mright respectively). I never use bra-ket notation myself: I do algebra, you know. ;-) – egreg Apr 13 '13 at 11:16
  • 3
    @strpeter, if you have \sum_{i} inside an automatic scaling \left and \right, the delimiters scale to the wrong height. – Aditya Apr 13 '13 at 14:52
6

Generically speaking the \left<delim> ... \right<delim> are used to fit the height of the content with expandable delimiters, chosen to by higher than all parts of the content.

But it is well-known that this choice often produce too large (tall) delimiters, and must be avoided for aesthetic reasons (and resulting typographic rules), as tactfully said by egreg and as exemplified by Aditya's comment. It's better practice to keep the delimiters height as small as possible, provided they ensure good readability.

That is why I don't use braket.sty but my own .sty based on \big and \Big, and some trick related to old-fashion \def with e.g. for the bras:

\def\bra<#1|{\langle #1\rvert}
\def\Bra<#1|{\big\langle #1\big\rvert}
\def\BRA<#1|{\Big\langle #1\Big\rvert}

and I would code the example discussed here:

\BRA<\frac{1}{\sqrt{2}}\left(\uparrow + \downarrow\right)|
    =\frac{1}{\sqrt{2}}\big(\bra<\uparrow|+\bra<\downarrow|\big)

the result of which, is IMO, better looking than the braket.sty result as coded by strpeter and posted by egreg. Bra with \Big
As further comments:

  • it would typeset the fraction in \textstyle to avoid to give him the emphasize
  • the left hand side is not a really meaningful notation for this state
Jhor
  • 4,179
0

For those of you who are here to type bra-ket notation for Markdown or web applications, you can try the following method:

$$
\newcommand{\bra}[1]{\left \langle #1 \right \rvert}
\newcommand{\ket}[1]{\left \rvert #1 \right \rangle}
\newcommand{\E}[1]{\left \langle #1 \right \rangle}
\newcommand{\braket}[2]{\left \langle #1 \middle \rvert #2 \right \rangle}
\newcommand{\braxket}[3]{\left \langle #1 \middle \rvert #2 \middle \rvert #3 \right \rangle}

\bra{\Psi}, ; \ket{\varphi}, ; \E{\frac{\Psi^\dag\Psi}{2/3}}, ; \braket{\frac{\Psi}{2/3}}{\varphi}, ; \braxket{\frac{\Psi}{2/3}}{A}{\varphi} $$

enter image description here

  • 2
    I don't understand why you would use \left \rvert. I would expect \left \lvert (or ever \left \vert). – barbara beeton Mar 05 '22 at 00:16
  • I agree with Barbara, try \braket{1}{-1} the - 1 will have the wrong spacing. (though not sure if middle changes anything) – daleif Mar 05 '22 at 06:46