Based on egreg's alternate solution to my previous question from which I learned the idea of making characters into macros, I've now defined a different syntax for bra-kets which I actually like even more. My macro almost works (although there's a bit of cargo cult programming going on here because I've copied some part of his solution which I didn't fully understand — the two lines beginning with \begingroup\lccode
— in my macro and adapted them slightly; I suspect the problem is in there, because the rest I believe I understand sufficiently, thanks to egregs explanations to the other question).
Here's my macro definition:
\newcommand{\braket}[2][\middle]{\ensuremath{
\begingroup
\begingroup\lccode`~=`<
\lowercase{\endgroup\def~}{#1\langle}
\begingroup\lccode`~=`|
\lowercase{\endgroup\def~}{#1\pipedel}
\begingroup\lccode`~=`>
\lowercase{\endgroup\def~}{#1\rangle}
\edef\pipedel{\delimiter\the\delcode`|}
\mathchardef\lt\mathcode`<
\mathchardef\pipechar\mathcode`|
\mathchardef\gt\mathcode`>
\mathcode`\<=\string"8000
\mathcode`\|=\string"8000
\mathcode`\>=\string"8000
\left.
#2
\right.
\endgroup
}}
The following usages all work as expected:
\braket{<\psi|\psi>}
\braket{<\psi|A|\psi>}
\braket{<\psi|\frac{p^2}{2m}|\psi>}
\braket[\Big]{<\alpha|\beta>}
\braket{|a \gt 0>}
\braket[]{<\psi|\frac{p^2}{2m}|\phi>}
(the last one simply disables automatic size adaption).
However, the following does not work correctly:
\braket{<0|1>}
It should give "〈0|1〉" but only gives "〈0〉".
So what's wrong with my macro, and how do I fix it?
|
.\bracket{<0| 1>}
produces the expected result. – Werner Dec 1 '11 at 3:05\braket{||\psi>>}
— the braket package doesn't help you). On the other hand I don't learn anything by just using the package. – celtschk Dec 2 '11 at 18:49