# Gap between ket and bra by using the braket-package

I'm using the braket-package for using the braket notation. It works fine, but I've got some problems by using the package for writing a tensor product.

There is always a big gap between the ket and the bra by writing \ket{x}\bra{x}. So I want to have it like |x><x| and not like |x> <x|. Does anyone know this problem and perhaps also a solution for it?

Example:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{braket}
\begin{document}
\begin{align*}
\ket{x}\bra{x}
\end{align*}
\end{document}

• your question would be easier to answer if you made a small complete document showing your input and the bad space then people can test answers. (you can use the {} button in the editor to mark a mult-line code block) – David Carlisle Jan 21 '16 at 12:09

It's “by design”. The definitions of \bra and \ket are

% braket.sty, line 31:
\def\bra#1{\mathinner{\langle{#1}|}}

% braket.sty, line 32:
\def\ket#1{\mathinner{|{#1}\rangle}}


and \mathinner adds a thin space on either side of the construction.

If you want to remove those additional thin spaces (which is not a bad idea, by the way), you can redefine them like

\renewcommand\bra[1]{{\langle{#1}|}}
\renewcommand\ket[1]{{|{#1}\rangle}}


However, the sidebearings of \langle and \rangle will still leave a hole.

\documentclass[10pt,a4paper]{article}

\usepackage{braket}

\renewcommand\bra[1]{{\langle{#1}|}}
\renewcommand\ket[1]{{|{#1}\rangle}}

\begin{document}

$\ket{x}\bra{x}$

$\ket{x}\!\bra{x}$

\end{document}


You might check whether a \bra immediately follows a \ket:

\documentclass[10pt,a4paper]{article}

\usepackage{braket}

\renewcommand\bra[1]{{\langle{#1}|}}
\makeatletter
\renewcommand\ket[1]{%
\@ifnextchar\bra{\k@t{#1}\!}{\k@t{#1}}%
}
\newcommand\k@t[1]{{|{#1}\rangle}}
\makeatother

\begin{document}

$\ket{x}\bra{x}$

\end{document}