[Tex/LaTex] Package amsmath Error: Multiple \label’s

amsmatherrorsoverset

Sorry about the previous errors in the code.

Could any one help with the numbering in the \overset or \underset in equations?

I need to add number above/below certain variables in the equations because I have so many variables. And the equations are very long. I consider to use the counter to auto-number the variables in equations. I tried the following code, but it seems that the \overset and \underset conflicts with the label of equation.

I got the following errors:

Package amsmath Error: Multiple \label's: label 'Eq1' will be lost. Y & = \overset{\dln{aaa}}{\boxed{a}}

Does anyone please help me with it. Thanks a lot. The code is here:

\documentclass{article}

\usepackage{amssymb}
\usepackage{amsmath}


\newcounter{rtaskno}
\DeclareRobustCommand{\dln}[1]{%
    \refstepcounter{rtaskno}%
    \thertaskno\label{#1}}

\begin{document}

Here is the equation:\\

\begin{equation}\label{Eq1} % I need the Eq. number
\begin{aligned} % I need the aligned equation
Y & = \overset{\dln{aaa}}{\boxed{a}} x_1  \\ % I need the aaa to be auto numbered
& + \underset{2}{\boxed{b}} x_2  % I need the bbb to be auto numbered
\end{aligned}
\end{equation}

Here is how to refer \dln{aaa}. % I need to refer the number indexed by aaa

\end{document}

This is what I want:
enter image description here

Best Answer

enter image description here

\documentclass{article}



\usepackage{amssymb}
\usepackage{amsmath}

\makeatletter
\def\zzlabel#1{\ifmeasuring@\else\ltx@label{#1}\fi}
\makeatletter


\newcounter{rtaskno}
\DeclareRobustCommand{\dln}[1]{%
    \refstepcounter{rtaskno}%
    \thertaskno\zzlabel{#1}}

\begin{document}

Here is the equation:% never \\ at and of paragraph
\begin{equation}\label{Eq1} % I need the Eq. number
\begin{aligned} % I need the aligned equation
Y & = \overset{\dln{aaa}}{\boxed{a}} x_1  \\ % I need the aaa to be auto numbered
& + \underset{\dln{bbb}}{\boxed{b}} x_2  % I need the bbb to be auto numbered
\end{aligned}
\end{equation}

Here is how to refer aaa: \ref{aaa}. % I need to refer the number indexed by aaa

Here is how to refer bbb: \ref{bbb}. % I need to refer the number indexed by aaa

\end{document}