I am not too sure what font to use for the internal +
and -
, so I just used \hbox{\texttt{+}}
. In TeX, each character has a \mathcode
, describing its behavious in maths. All of them lie between "0000
and "7FFF
(in hexadecimal), except the special mathcode "8000
, which makes the character act like an active character. Within the group which \bra
, \ket
and \braket
define, I get +
and -
to be active and expand to \braket@inner@minus
and \braket@inner@plus
.
\documentclass{article}
\usepackage{braket}
\makeatletter
\newcommand{\braket@inner@minus}{\hbox{\texttt{-}}}
\newcommand{\braket@inner@plus}{\hbox{\texttt{+}}}
\begingroup
\catcode`\-=13\relax %active
\catcode`\+=13\relax %active
\@firstofone{\endgroup %end the local changes to catcodes.
\newcommand\braket@inner@defs{%
\edef\restore@mathcode{%
\mathcode`\noexpand +=\the\mathcode`+%
\mathcode`\noexpand -=\the\mathcode`-%
}%
\mathcode`\+="8000\relax
\mathcode`\-="8000\relax
\def+{\begingroup\restore@mathcode\braket@inner@plus\endgroup}%
\def-{\begingroup\restore@mathcode\braket@inner@minus\endgroup}%
}%
}
% old definition:
% \newcommand{\bra}[1]{\mathinner {\langle {#1}|}}
% new definition:
\renewcommand{\bra}[1]{\mathinner {\langle \braket@inner@defs {#1}|}}
\renewcommand{\ket}[1]{\mathinner {|\braket@inner@defs{#1}\rangle }}
\renewcommand{\braket}[1]{\mathinner {\langle \braket@inner@defs {#1}\rangle }}
\makeatother
\begin{document}
\[
\bra{++--}A^\dag A\ket{-+-+} = \braket{++--|A^\dag A|-+-+} = \cdots
\]
However,
\[
\bra{++}(A+B)\ket{--} \neq \braket{++|(A+B)|--}
\]
\end{document}
Here is a tikz
version which automatically gets you all the flexibility inherent in tikz
such as rotating the symbol to be appropriate for the axis, adjusting the line style, colors, arrow style, etc...
Further Enhancement:
- Automatically rotate the symbol to be along the path.
- Provide a style setting that can be used to customize the symbol
Code:
\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\newcommand{\AxisRotator}[1][rotate=0]{%
\tikz [x=0.25cm,y=0.60cm,line width=.2ex,-stealth,#1] \draw (0,0) arc (-150:150:1 and 1);%
}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (3,0) node [midway] {\AxisRotator};
\draw (0,0) -- (0,-3) node [midway] {\AxisRotator[rotate=-90]};
\draw (0,-3) -- (3,0) node [midway] {\AxisRotator[rotate=60]};
\end{tikzpicture}
%
\begin{tikzpicture}
\draw (0,0) -- (3,0) node [midway] {\AxisRotator[x=0.2cm,y=0.4cm,->,densely dotted]};
\draw (0,0) -- (0,-3) node [midway] {\AxisRotator[x=0.2cm,y=0.4cm,->,rotate=-90,blue, dashed]};
\draw (0,-3) -- (3,0) node [midway] {\AxisRotator[x=0.2cm,y=0.4cm,->,rotate=60, red ]};
\end{tikzpicture}
\end{document}
Best Answer
I once proposed the following definitions
Example