The mathtools
package provides a way to define such commands. The documentation contains a definition for \braket
and you can build on this to get an \expectation
macro with similar properties, namely that \expectation*
rescales automatically, and \expectation
, \expectation[\big]
, \expectation[\Big]
, \expectation[\bigg]
, etc., produce specific sizes:

\documentclass{article}
\usepackage{mathtools}
\DeclarePairedDelimiterX{\braket}[3]{\langle}{\rangle}{#1
\,\delimsize\vert\,\mathopen{} #2 \,\delimsize\vert\, \mathopen{}
#3}
\NewDocumentCommand{\expectation}{ s O{} m }{
\IfBooleanTF {#1}
{ \braket*{\psi}{#3}{\psi} }
{ \braket[#2]{\psi}{#3}{\psi} }
}
\begin{document}
\( \braket{\psi}{X}{\phi} \) \( \expectation{X} \)
\( \braket{\psi}{A^{2}}{\phi} \) \( \expectation{A^{2}} \)
Manual sizing
\begin{equation*}
\braket[\bigg]{\psi}{\sum_{i=1}^{n}}{\phi}
\expectation[\bigg]{\sum_{i=1}^{n} B_{i}}
\end{equation*}
\( \braket[\big]{\psi}{A^{2}}{\phi} \) \( \expectation[\big]{A^{2}} \)
Automatic sizing
\begin{equation*}
\braket*{\psi}{\sum_{i=1}^{n}}{\phi}
\expectation*{\sum_{i=1}^{n} B_{i}}
\end{equation*}
\end{document}
\newcommand{\expectation}[1]{\langle \psi #1 \psi \rangle}