Math & Sciencebras and kets

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
episanty
Posts: 26
Joined: Tue Mar 24, 2009 2:24 am

bras and kets

Post by episanty »

Hi!

I'm writing my thesis on quantum mechanics, and as such I need to use physicists' bra-ket notation. I copied my template from http://www.dfcd.net/articles/latex/latex.html and it works quite well to make the angles and bars larger in a consistent way when one of the factors is large.

(I'm aware now that there's a package that does this, but my notation is quite set as switching to the package would require changing all my brackets from \bracket{...}{...} to \bracket{...|...}).

There's just one thing that's bugging me, and I can't really figure out what's going on:

Code: Select all

\documentclass[11pt,notitlepage]{book}%,cmss,c,
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\newcommand{\bra}[1]{\ensuremath{\left\langle#1\right|}}
\newcommand{\ket}[1]{\ensuremath{\left|#1\right\rangle}}
\newcommand{\bracket}[2]{\ensuremath{\left\langle#1 \vphantom{#2}\right| \left. #2 \vphantom{#1}\right\rangle}}
\newcommand{\matrixel}[3]{\ensuremath{\left\langle #1 \vphantom{#2#3} \right| #2 \left| #3 \vphantom{#1#2} \right\rangle}}

\begin{document}

These commands write quantum-mechanical bras and kets, such as \bra{\alpha} and \ket{\beta}, as well as their products, like \bracket{\alpha}{\eta}, and also matrix elements such as \matrixel{\xi}{T}{\pi}. They're quite useful when one of the factors is large: for instance \ket{\xi} vs \ket{\hat{\xi}}, or when one has \matrixel{\xi}{\hat{T}}{\pi}.

There's only one funny space, in the bracket (as opposed to the ket) below, which shouldn't really be there, and which I can't really figure out:
\begin{align*}
a\ket{\alpha,1}&=\alpha\ket{\alpha,1}+\ket{\alpha}\\
\bracket{\alpha,1}{\alpha,1}&=1
\end{align*}
\end{document}
I think it's definitely the \left. that's causing trouble, since switching \right| \left. to \right. \left| will move the space left of the bar. but aren't \left. and \right. supposed to be silent?

Any thoughts?

cheers!
Last edited by episanty on Thu Mar 03, 2011 5:55 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

bras and kets

Post by localghost »

At first thanks for this complete example which made comprehending the problem very easy. There is a simple trick. Beside \left and \right there also exists \middle to adjust a delimiter. Use this in your command definitions.

Code: Select all

\newcommand{\bra}[1]{\ensuremath{\left\langle#1\right|}}
\newcommand{\ket}[1]{\ensuremath{\left|#1\right\rangle}}
\newcommand{\bracket}[2]{\ensuremath{\left\langle #1 \middle| #2 \right\rangle}}
\newcommand{\matrixel}[3]{\ensuremath{\left\langle #1 \middle| #2 \middle| #3 \right\rangle}}
The additional spaces now disappear.
episanty wrote:[…] (I'm aware now that there's a package that does this, but my notation is quite set as switching to the package would require changing all my brackets from \bracket{...}{...} to \bracket{...|...}). […]
Nevertheless you should think about using a package like braket. The mathtools package provides the \DeclarePairedDelimiter command so that you could stay with your command names. But typesetting bras and kets would be much more comfortable.
episanty wrote:[…] I think it's definitely the \left. that's causing trouble, since switching \right| \left. to \right. \left| will move the space left of the bar. but aren't \left. and \right. supposed to be silent? […]
Actually these invisible delimiters aren't really invisible, or silent as you call it. At their place there is some horizontal space inserted which is determined by the \nulldelimiterspace length register.


Thorsten
episanty
Posts: 26
Joined: Tue Mar 24, 2009 2:24 am

bras and kets

Post by episanty »

Thank you!

the revised version

Code: Select all

\newcommand{\bracket}[2]{\ensuremath{\left\langle#1 \vphantom{#2}\middle|  #2 \vphantom{#1}\right\rangle}}
works beautifully.

I guess another solution would be to temporarily set \nulldelimiterspace to zero, but I am not entirely sure of how one would do that; my naive attempt,

Code: Select all

\newcommand{\bracket}[2]{\ensuremath{{\nulldelimiterspace=0pt \left\langle#1 \vphantom{#2}\right|\left.  #2 \vphantom{#1}\right\rangle}}}
won't work.
Post Reply