# different plus/minus within braket environment?

I m using the braket notation to write a physics report (with the braket package). Writing a plus and a minus within a ket or a bra looks really ugly (bra is < | and ket is | > ) Are there any ideas on how to make it look better? having a line like this:

|1,-1>=<--|1, -1>|-->+<-+|1, -1>|-+>+<+-|1, -1>|+ -> etc


is pretty unreadable in the pdf, as the pluses/minuses inside and outside the braket notation are indistinguishable. The idea is that a smaller or smaller and thicker plus/minus only within the braket notation would make it more readable, only I don't know if such a symbol exists. Would I have to create it manually? I d like to avoid that, as it would decrease my typing speed seriously, even with a shortcut..

• post a complete example ...
– user2478
Apr 11, 2011 at 9:53
• Also, I am hoping you are not using what you highlighted as code as the actual code. The braket package defines the commends \bra{} and \ket{} and more... Apr 11, 2011 at 13:48
• Is the following a correct interpretation of your question? You want to define a command \bra{} which takes one argument, such that for all instances of the symbols + and -, you want them to be set in a different fontsize/weight? Apr 11, 2011 at 14:13
• No, I didn't make myself clear. I do use \bra{}, \ket{} and \braket{}, that's the whole point of the braket package. The thing is if I fill it will +-, The +- inside and outside the brakets are indistinguishable. I need another type of +-, maybe smaller and thicker, to distinguish them visually on the final pdf! Apr 11, 2011 at 14:54
• To an extent, your problem will be unavoidable, because what you are writing is the quantum-physical version of a tongue-twister. Adding more space between your terms using \; macros is the simplest, and perhaps the best, thing that you can do – after changing to a different typeface for the contents of the \bracket{}s and \ket{}s of course. Apr 11, 2011 at 21:32

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}

• " is used for hexadecimal numbers. \mathcodes are 15-bit numbers, i.e., between "0000 and "7ffff. "8000 is a special \mathcode. See The TeXbook or TeX by Topic for details.
– TH.
Apr 12, 2011 at 8:06
• this is great! however, although it does work standalone, I can't seem to embed it in my text..It complains about encoding of a font I think (I m writing in greek).. I ll check the code carefully and see what the cause could be. Thanks !! Apr 12, 2011 at 8:14
• Also, I copied part of the math in your example, and noticed that this doesn't work for underbraces! If I write something under the underbrace, the plus sign is the thicker one, not the normal one. Otherwise, the result is what I wanted! Apr 12, 2011 at 8:23
• Is your underbrace within the argument of \bra{}? Apr 13, 2011 at 13:35
• sorry for the late reply I wasn't notified.. yes, it usually is. Apr 15, 2011 at 18:25

Assuming I got it right what dingo_d said:

$$\def\bra#1{\left\langle\raise.3ex\hbox{\scriptscriptstyle#1}\right|} \def\ket#1{\left|\raise.3ex\hbox{\scriptscriptstyle#1}\right\rangle} \left|1,-1\right\rangle = \bra{--}1,-1\rangle\ket{--} + \bra{-+}1,-1\rangle\ket{-+} + \bra{+-}1,-1\rangle\ket{+-}$$
\bye


My eyes hurt… :-(
I threw the .3ex from a hat. If it helps, it was a nice looking hat.

• That's what the braket package does! My problem is visual. If I could print in colour and it was allowed in dirac notation, I would have the inner =- painted another colour to distinguish them from the others! btw, my eyes and my mind hurts when I read this.. Apr 11, 2011 at 14:57
• Sorry, dingo_d is right, I didn't look at your code carefully. Thank you, I assumed it just redefines bra and ket as if braket didn't exist. This solution seems ok, too, but it doesn't work for the \braket{}, which can be < > , < | > , or < | | >. Also, how can I put the \def parts outside the  environment and into the preamble? Apr 12, 2011 at 8:49
• @sfranky: I assume you're using LaTeX? I'm sorry, I don't really know enough about it to be of help here. Apr 12, 2011 at 14:35

When I want to write something in QM with braket notation I use \langle and \rangle, looks just fine and you can combine it with simple | sign.

HTH ^^

• What's wrong with the code morbusg posted? You can clearly see the thick minus and plus on the outside and smaller on the inside... Plus have you looked at some books in QM, they all have the same sized + and -, talk about headache there :D Also, how come I can only answer to my own big answer? :\ Apr 12, 2011 at 7:51
• I just made up for that :) \langle and \rangle are fine, but I am speedtyping and I need to be able to hit the fewest keystrokes possible. In vim, i have these remaps: << ---> \bra{ , >> ---> \ket{ , <> ---> \braket{ which makes this really fast for me!! Apr 12, 2011 at 8:52
• Oh, I see, hmmmm I'm sure you could try to make another definitions like morbusg suggested but for various combination (braket). I renamed the \bra and \ket with \< and \> and it works. But I see that if you'd write \bra{+}\ket{-} you'd get aa extra | which is not good... I think that you just need to redefine the morbusgs definitions a bit and you're good to go :) Apr 12, 2011 at 9:24