94

I am using the braket package to generate bra and ket vectors. However, I could not figure out how to do <0|0> using the package. Is there a command for this?

5 Answers 5

92

Use \braket{0|0}:

\documentclass{standalone}

\usepackage{braket}

\begin{document}

$\braket{0|0}$

\end{document}

enter image description here

0
78

There is the physics package:

\documentclass{article}
\usepackage{physics}
\begin{document}
  $\bra{\Psi}\ket{\Psi}$ $\expval{A}{\Psi}$
\end{document}

enter image description here

It offers many other goodies for typsetting physics things. Details can be found in the manul (texdoc physics from command prompt/terminal).

Edit by @Gaussler in 2023: Do not use the physics package at all. To quote Henri Menke’s comment below, “[t]he implementation is really horrible and it destroys the spacing all over the place.” To put it differently, physics belongs together with commath in package hell. Use one of the solutions from the other answers instead.

3
  • 8
    I love you man, I had a lot of stuff the package implements, defined manually. Feb 25, 2015 at 22:23
  • 26
    Do not use the physics package. The implementation is really horrible and it destroys the spacing all over the place. Sep 4, 2019 at 10:38
  • And whoever reads this, please downvote this answer.
    – Gaussler
    Jul 18, 2023 at 17:49
51

A solution using the mathtools package:

\documentclass{article}

\usepackage{mathtools}
\DeclarePairedDelimiter\bra{\langle}{\rvert}
\DeclarePairedDelimiter\ket{\lvert}{\rangle}
\DeclarePairedDelimiterX\braket[2]{\langle}{\rangle}{#1\,\delimsize\vert\,\mathopen{}#2}

\begin{document}

\begin{align*}
  \bra{a}       &= \bra*{\frac{a}{1}} \\
  \ket{a}       &= \ket*{\frac{a}{1}} \\
  \braket{a}{b} &= \braket*{\frac{a}{1}}{\frac{b}{1}}
\end{align*}

\end{document}

output

Notice that the starred versions of the macros scale automatically.

4
  • 2
    Hope one of a better suggestion...
    – MadyYuvi
    Sep 4, 2019 at 10:41
  • 1
    And it works for MathJax!
    – Cheng
    Aug 6, 2021 at 8:21
  • 3
    Adapted from section 3.6 of the docs, it's best to add \mathopen{} after \vert: \DeclarePairedDelimiterX\braket[2]{\langle}{\rangle}{#1\,\delimsize\vert\,\mathopen{}#2}. Otherwise \braket{a}{-b} will typeset | - b as if it's subtracting b, instead of | -b.
    – anderium
    Nov 9, 2021 at 11:12
  • 1
    @anderium Thanks! I've updated the answer according to your suggestion. (I don't know why this hasn't happened before.) Jul 18, 2023 at 15:58
38

You can use the \langle and \rangle commands. For example, to do <0|0>, you would do:

\langle 0 | 0 \rangle

Result:

enter image description here

If you have things which use vertical space (like fractions), you can use \left, \right and \middle to adjust the vertical size of the <, > and | symbols. For example:

\left\langle \frac{1}{2} \middle| 1 \right\rangle

Result:

enter image description here

3
  • 5
    I didn't know the existence of \middle! thanks
    – Andrea
    Mar 2, 2020 at 15:36
  • Thanks a lot for the \middle
    – Mike22LFC
    Sep 10, 2020 at 14:12
  • That \middle was my salvation, thank you
    – FacuO.Z.
    Jun 10, 2022 at 3:52
8

A complement to the answers above. In case one wants to have a different operators in the left/right and want something in the middle the \expval does no help. An option is to use the \matrixelement in the physics package. This also have the advantage of the proper scaling of the bras & kets for disproportional operators.

\documentclass{article}
\usepackage{physics}
\begin{document}
\begin{equation}
 \mel{n}{A}{m}
\end{equation}
\end{document}

Result

5
  • 2
    Do not use the physics package. The implementation is really horrible and it destroys the spacing all over the place. Sep 4, 2019 at 10:40
  • Despite I did not have problems with the physics package, I can't disagree with you as i never check the implementation. If I found another formulation that solves the problem in such simple manner and has a better implementation, I will definitely update. Meanwhile we have your warning for anyone who may need/want to use it.
    – Guto
    Sep 4, 2019 at 19:26
  • Actually, the construct in the example you show already destroys the spacing. Try \fbox{$\mel{n}{A}{m}$} (screenshot). You can see that there is more space on the left than on the right, which comes from the fact that the implementation of physics is utter garbage. Sep 6, 2019 at 6:54
  • @HenriMenke What alternative do you advise?
    – Andrea
    Mar 2, 2020 at 15:38
  • 1
    @Andrea I think you probably found your answers already, but since I stumbled upon this question now and use maththools package I noramlly have nowadays: \DeclarePairedDelimiter{\bra}{\langle}{\rvert}% \DeclarePairedDelimiter{\ket}{\lvert}{\rangle}% \DeclarePairedDelimiterX\braket[3]{\langle}{\rangle}{#1\,\delimsize\vert\,\mathopen{}#2\,\delimsize\vert\,\mathopen{}#3}% \DeclarePairedDelimiterX\ketbra[2]{\lvert}{\rvert}{#1\delimsize\rangle\!\delimsize\langle#2}% \DeclarePairedDelimiterX\projector[1]{\lvert}{\rvert}{#1\delimsize\rangle\!\delimsize\langle#1}% Mar 15, 2023 at 20:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .