# Subequations with individual references in same line nicely spaced (without minipages?)

In my overall document, I have many subequations like:

\documentclass[a4paper]{report}

\usepackage{mleftright}
\usepackage{amsmath}
\usepackage{mathtools}

\begin{document}

These two operators, which in turn map pairs of operators $\mleft( \hat{A} ; \hat{B} \mright)$ onto another operator, are defined as:
\newline
\begin{subequations}
\begin{minipage}[t]{0.5\textwidth}
$$\label{DefComm} \mleft[ \hat{A} ; \hat{B} \mright] \coloneqq \hat{A} \hat{B} - \hat{B} \hat{A}$$
\end{minipage}\hfill
\begin{minipage}[t]{0.5\textwidth}
$$\label{DefAntiComm} \text{and } \{ \hat{A} ; \hat{B} \} \coloneqq \hat{A} \hat{B} + \hat{B} \hat{A} \, ,$$
\end{minipage}
\end{subequations}
\newline
\newline
\newline
respectively.

\end{document}


This working example gives the following output:

I would like Latex/tex to do the spacing itself with me only having to specify what parts belong to distinct subequations. Is that possible. As is, I have to manually tweak the size of the minipages and also the intertext doesn't look nice. I'd like the end to be sort of central and equally spaced from the parenthesis (1a) and the next equation. Or whatever your suggestions for how it should look are, but it certainly doesn't look nice as it is.

• Do you really want \mleft(\hat{A};\hat{B}\mright)? The output is not really pretty compared to (\hat{A};\hat{B}). Just look at your equation 1a and 1b. The latter is good, the former isn't. – egreg Jun 2 '20 at 10:14

Here is a proposal that measures the widths of the expressions and allocates the minipage widths accordingly.

\documentclass[a4paper]{report}

\usepackage{mleftright}
\usepackage{xfp}
\usepackage{mathtools}
\newcommand\SideBySideEquations[3][3em]{%
\setbox0\hbox{$\displaystyle#2$}%
\setbox1\hbox{$\displaystyle#3$}%
\par\noindent
\begin{minipage}[t]{\fpeval{(\wd0+#1)/(\wd0+\wd1+#1+#1)}\textwidth}
$$#2\vphantom{#3}$$
\end{minipage}%
\begin{minipage}[t]{\fpeval{(\wd1+#1)/(\wd0+\wd1+#1+#1)}\textwidth}
$$#3\vphantom{#2}$$
\end{minipage}\vskip\belowdisplayskip\par\noindent
}
\begin{document}

These two operators, which in turn map pairs of operators $\mleft( \hat{A} ; \hat{B} \mright)$ onto another operator, are defined as
\begin{subequations}
\SideBySideEquations{%
\mleft[ \hat{A} ; \hat{B} \mright] \coloneqq \hat{A}\hat{B} - \hat{B} \hat{A}}{%
\text{and}\quad \{ \hat{A} ; \hat{B} \} \coloneqq \hat{A} \hat{B} + \hat{B} \hat{A}}
\end{subequations}
respectively.

Here is another example,
\begin{subequations}
\SideBySideEquations{%
\hat{A}}{%
\text{and}\quad \{ \hat{A} ; \hat{B} \} \coloneqq \hat{A} \hat{B} + \hat{B} \hat{A}}
\end{subequations}
and another one
\begin{subequations}
\SideBySideEquations{%
\mleft[ \hat{A} ; \hat{B} \mright] \coloneqq \hat{A}\hat{B} - \hat{B} \hat{A}}{%
$$E=\hbar\omega\;.$$