Make IMHO not really sense, but if you want:
\documentclass{article}
\makeatletter
\NewDocumentCommand{\bracket}{r<|}{%
\typeout{TRACE1: \detokenize{#1}}%
\@bracket{#1}|%
}
\NewDocumentCommand{\@bracket}{mr|>}{%
\left\langle #1\middle|#2\right\rangle
}
\makeatother
\begin{document}
\begin{equation}
\bracket<\phi|\phi>
\end{equation}
\end{document}
or with one macro:
\documentclass{article}
\NewDocumentCommand{\bracket}{e{<}r|>}{%
\left\langle #1\middle|#2\right\rangle
}
\begin{document}
\begin{equation}
\bracket<\phi|\phi>
\end{equation}
\end{document}
But IMHO better would be something like:
\documentclass{article}
\ExplSyntaxOn
\NewDocumentCommand{\bracket}{r<>}
{
\seq_set_split:Nnn \l_tmpa_seq { | } { #1 }
\seq_pop_left:NN \l_tmpa_seq \l_tmpa_tl
\left\langle \l_tmpa_tl
\seq_map_inline:Nn \l_tmpa_seq { \middle | ##1 }
\right\rangle
}
\ExplSyntaxOff
\begin{document}
\begin{equation}
\bracket<\phi|\phi>
\bracket<\phi>
\bracket<>
\bracket<\phi|\phi|\phi>
\end{equation}
\end{document}
or easier:
\documentclass{article}
\ExplSyntaxOn
\NewDocumentCommand{\bracket}{r<>}
{
\tl_set:Nn \l_tmpa_tl { #1 }
\tl_replace_all:Nnn \l_tmpa_tl { | } { \middle | }
\left\langle \l_tmpa_tl \right\rangle
}
\ExplSyntaxOff
\begin{document}
\begin{equation}
\bracket<\phi|\phi>
\bracket<\phi>
\bracket<>
\bracket<\phi|\phi|\phi>
\end{equation}
\end{document}
Both result in:
\NewDocumentCommand\bracket{}{\brackethelp} \def\brackethelp<#1|#2>{\left\langle #1 \right|\left. #2 \right\rangle}
qualify?\bracket<\phi|\phi>
looks that much clearer than\bracket{\phi}{\phi}
? Also, please note that there is a package for braket notation namedbraket
, maybe you want to give it a try instead fo reinventing the wheel?\NewDocumentCommand
, the whole idea of it is to implement standard argument types, all the more exotic ones are discouraged, better stick to\def
, imho, maybe add an\@ifdefinable\racket
to ensure the macro doesn't conflict with things. Also, inbraket
the syntax would be something like\braket{\phi|\phi}
, not too far off from yours, but way more LaTeXy.\left\langle #1 \right|\left. #2 \right\rangle
does not ensure the < and > have the same size which is rather weird. why not\left\langle #1 \middle| #2 \right\rangle
????