# physics and braket packages with different \braket commands

I am using the \usepackage{physics} package and want to write something using bra-ket notation but with a double bar in the middle (physicist's notation in Quantum Chemistry). It can be written as \braket{0||0} using the \usepackage{braket} package, however it is much more useful for me to use the {physics} package for the majority of my work. I cannot use the {braket} package as the command \braket is already a command in the {physics} package, and I don't want to tamper previous pages I've written using the physics package. So I guess I have 2 questions.

1) Can you write the equation in the picture using the physics package?

2) Is it possible to import both packages but call on the \braket command from different packages when I choose? For example, I may want to use the command from the physics package for my first equation, but the braket package for my second equation.

• I don't have time to work up a proper answer, but here is an idea: Use the mathtools package. Look for \braket in the documentation, and learn how to build your own. You can call it whatever you wish. – Harald Hanche-Olsen Jan 9 '18 at 8:59
• You can use $\mel{ij}{}{jk}$. – Sandy G Jan 9 '18 at 17:16

The physics package can do this using matrix element commands \matrixel, or \mel for short. The code

\documentclass{article}
\usepackage{physics}
\begin{document}

$\mel{ij}{}{kl}$

\end{document}


Will produce the desired output. If desired, an additional second argument can be inserted. (It is empty in the example.)

There are two other forms of the \mel command: \mel* and mel**. The no-star version adjusts the delimiter heights based on the first and third arguments, but not the second. The one-star version does no resizing at all. The two-star version resizes delimiters based on all three arguments. For example, the code

$\mel{\rule{2pt}{2ex}}{\rule{2pt}{3ex}}{kl}\quad% \mel*{\rule{2pt}{2ex}}{\rule{2pt}{3ex}}{kl}\quad% \mel**{\rule{2pt}{2ex}}{\rule{2pt}{3ex}}{kl}$


produces the output:

Note that there appears to be a spacing inconsistency between the no-star and one-star versions, compared to the two-star version. The difference appears to be exactly a thinspace. Consider the following code and its output:

H$\mel{ij}{}{kl}$H

H$\mel*{ij}{}{kl}$H

H$\mel**{ij}{}{kl}$H


The spacing on the left and right is equalized by inserting a negative thin space (\!) before \mel or \mel*.

\documentclass{class}
\usepackage[italicdiff]{physics}
\begin{document}

$$\mel{ij}{\grande}{jk}$$

\end{document}

• Is there a LaTeX document class called class? – Mico Jan 9 '18 at 10:05
• Hi, yes dear friend. See pag.2. mirror.hmc.edu/ctan/macros/latex/contrib/physics/physics.pdf (To use the physics package, simply insert \usepackage{physics} in the preamble of your document, before \begin{document} and after \documentclass{class}). – Sebastiano Jan 9 '18 at 11:06
• Happy to learn something new!😀 – Mico Jan 9 '18 at 13:08
• This code does not compile for me. I have no document class called class. And if I use article, there is no command grande. Are you certain the manual for the physics package isn't just using "class" as a placeholder for an actual document class? ...and a macro \grande that's just a placeholder for a large object? – Sandy G Jan 9 '18 at 17:17

I propose a solution based on mathtools, xparse and etoolbox. The syntax is \mybraket{1st argt | 2nd argt |3rd arrgt}. The separator for arguments is |, but it may be changed to, say, a comma or a semi-colon.

This command can take an optional size argument (\big, \Big,&c.). Alternatively, the starred version\mybracket* adds an implicit \left \right pair before the delimiters.

\documentclass{article}
\usepackage{mathtools}
\usepackage{physics}
\usepackage{xparse, etoolbox}

\DeclarePairedDelimiterX\mybraket[1]{\langle}{\rangle}{\braketargs{#1}}%
\NewDocumentCommand{\braketargs}{ >{\SplitArgument{2}{|}}m }
{\braketargsaux#1}
\NewDocumentCommand{\braketargsaux}{ m m m}%
{\IfNoValueTF{#3}{\IfNoValueTF{#2}{#1}{#1\,\delimsize\vert\,\mathopen{}#2}}%
{\ifblank{#2}{#1\,\delimsize\vert\mkern-1mu\delimsize\vert\,\mathopen{}#3}%
{#1\,\delimsize\vert\,\mathopen{}#2\,\delimsize\vert\,\mathopen{}#3}}}%

\begin{document}

$\mybraket*{ij}\quad\mybraket[\big]{ij||jk} \quad\mybraket[\big]{ij|\ell|jk}$%

\end{document}


• I vote also to you +1. Thanks for the help on site Mathematics. – Sebastiano Jan 9 '18 at 18:05