I am using the empheq/tcolorbox packages to put colored boxes around my equations but would like to place the equation numbers in the right margin.
In the past, I have used the following code to put equation numbers in the right margin and it has worked outside of the empheq environment. If I use it within empheq, I get no equation numbers but the references exist.
\makeatletter
\let\mytagform@=\tagform@
\def\tagform@#1{\maketag@@@{\hbox{\rlap{\hspace{0.5in}(\ignorespaces#1\unskip\@@italiccorr)}}}\kern1sp}
\renewcommand{\eqref}[1]{{\mytagform@{\ref{#1}}}}
\makeatother
Below is a MWE. \margtrueplaces equation numbers in margin while \margfalse will exhibit the "normal" behavior.
\documentclass{article}
\usepackage{showframe}
\usepackage{amsmath}
\usepackage{empheq}
\usepackage[most]{tcolorbox}
\newif\ifmarg
\margtrue
\ifmarg
\makeatletter
\let\mytagform@=\tagform@
\def\tagform@#1{\maketag@@@{\hbox{\rlap{\hspace{0.5in}(\ignorespaces#1\unskip\@@italiccorr)}}}\kern1sp}
\renewcommand{\eqref}[1]{{\mytagform@{\ref{#1}}}}
\makeatother
\fi
\begin{document}
An equation with number in the right margin.
\begin{gather}
F = ma.
\end{gather}
And now an equation within an \verb|empheq| environment.
\begin{empheq}[box=\tcbhighmath]{gather}
F = ma.
\end{empheq}
\end{document}
The \margtrue behavior is shown below. Note the second equation does not have any equation number displayed.
The \margfalse behavior is shown below. Note the second equation does have an equation number displayed (not in margin though).


