2

I got to know that \left and \right allow us to automatically adjust the sizes of brackets. I'm currently working on some documents of Quantum Physics with so-called Dirac notations of bra and ket, made of \langle, | and \rangle.

Typically, there are 5 types of combinations: |a>, <b|, <a>, <a|b> and <a|c|b>. It is easy to use \left and \right for the first 3 types, how can I make automatic adjustment for all the symbols?

  • Welcome to TeX.SX! Do you know the braket package? – egreg Apr 9 '19 at 17:42
  • @egreg, thanks! I'm wondering how this implemented? – Yang Wang Apr 9 '19 at 17:45
3

You could use braket, where the commands \bra, \ket and \braket have the “automatic extended” variants \Bra, \Ket and \Braket.

Or you can make your own commands. Here each of the \bra, \ket and \braket command accepts an optional size argument (\big, \Big, \bigg or \Bigg), or a * for the automatically extensible version.

\documentclass{article}

\usepackage{mathtools,xparse}

\DeclarePairedDelimiterX{\bra}[1]{\langle}{\rvert}{#1\,}
\DeclarePairedDelimiterX{\ket}[1]{\lvert}{\rangle}{\,#1}
\DeclarePairedDelimiterX{\makebraket}[1]{\langle}{\rangle}{#1}

\NewDocumentCommand{\braket}{som}{%
  \begingroup\activatebraketbar
  \IfBooleanTF{#1}
    {\makebraket*{#3}}
    {\IfNoValueTF{#2}{\makebraket{#3}}{\makebraket[#2]{#3}}}%
  \endgroup
}

\makeatletter
\newcommand{\braketbar}{%
  \,\delimsize\vert\@ifnextchar|{\!}{\,}%
}
\makeatother
\newcommand{\activatebraketbar}{%
  \begingroup\lccode`~=`|\lowercase{\endgroup\let~}\braketbar
  \mathcode`|="8000
}

\begin{document}

\begin{gather*}
\bra{x}+\ket{\psi(t)}+
\bra[\big]{x}+\ket[\big]{\psi(t)}+
\bra[\Big]{x}+\ket[\Big]{\psi(t)} \\
\braket{x|\psi(t)}\quad\braket{x|y|\psi(t)} \\
\braket[\big]{x|\psi(t)}\quad\braket[\big]{x|y|\psi(t)} \\
\braket[\Big]{x|\psi(t)}\quad\braket[\Big]{x|y|\psi(t)} \\
\braket*{\frac{x}{y}|z}+\braket*{x|\frac{a}{b}|z} \\
\braket{a||b}
\end{gather*}

\end{document}

enter image description here

| improve this answer | |
2

The use of \middle can help here.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\def\z{\frac{x}{y}}
\[
\left\lvert\z\right\rangle\quad
\left\langle\z\right\rvert\quad
\left\langle\z\right\rangle\quad
\left\langle\z\middle\vert b\right\rangle\quad
\left\langle\z\middle\vert b\middle\vert c\right\rangle
\]
\end{document}

enter image description here

| improve this answer | |
0

The package physics has few commands for this purpose.

  1. \bra

enter image description here

\[\bra{a} \quad \bra{\frac{a}{b}} \quad \bra*{\frac{a}{b}}\]
  1. \ket

enter image description here

\[\ket{b} \quad \ket{\frac{a}{b}} \quad \ket*{\frac{a}{b}}\]
  1. \braket

enter image description here

\[\braket{a}{b} \quad \braket{a}{\frac{x}{y}} \quad \braket*{a}{\frac{x}{y}}\]
  1. \expectationvalue or \ev

enter image description here

\[\ev{a} \quad \ev{H}{a}\]
  1. \matrixelement or \mel

enter image description here

\[\mel{a}{H}{b}  \quad \mel{a}{\hat{H}}{b} \quad \mel**{a}{\hat{H}}{b}\]

MWE

\documentclass{article}
\usepackage{physics}

\begin{document}
\[\bra{a} \quad \bra{\frac{a}{b}} \quad \bra*{\frac{a}{b}} \]
\[\ket{b} \quad \ket{\frac{a}{b}} \quad \ket*{\frac{a}{b}} \]
\[\braket{a}{b} \quad \braket{a}{\frac{x}{y}} \quad \braket*{a}{\frac{x}{y}}\]
\[\ev{a} \quad \ev{H}{a}\]
\[\mel{a}{H}{b}  \quad \mel{a}{\hat{H}}{b} \quad \mel**{a}{\hat{H}}{b}\]
\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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