I am using custom counters for numbering examples and problems. The counters use chapter numbering followed by the problem number. For example, first problem in chapter 3 would be 3.1 and so on. In some of the problems I want to number the equations using this number "3.1" which is automatically generated by the counter. For example, first equation of 3.1 should read "P.3.1.1" P to indicate equation belongs to a problem, so that this numbering is distinct from the main numbering of equations. I can use the tag option to number it manually, extracting parts of the tag from thechapter and theprob counters. I was not able to automate the last part of the tag requirement, that is the last number. Another related question that comes next is how to refer to such equation tags uniquely if they are created with input from automated counters?
MWE of how I have implemented the counter and what I want.
\documentclass{book} \usepackage{amsmath} \newcounter{prob} \newcommand{\prob}{ \stepcounter{prob} {\textbf{Problem~\thechapter.\arabic{prob}.~ }}} % resets the problem counter after every chapter \makeatletter \@addtoreset{prob}{chapter} \makeatother \begin{document} \chapter{Intro} \prob This is a sample problem and it should be numbered 1.1. I want this equation to be numbered according to the number of the problem. This equation below should be numbered P.1.1. \begin{equation} A = B + C \tag{P.\thechapter.\theprob.1} \end{equation} Another equation in this problem should be labelled P.1.1.2. \begin{equation} D = E + F \tag{P.\thechapter.\theprob.2} \end{equation} Right now I am doing this manually, but how can one automate the last counter within the problem. Is there a simpler way to achieve this. And more importantly how to use \texttt{ref} with this \texttt{tag}. As if we use another problem, the \texttt{tag} will remain same. For example, let us consider another problem \prob This is another sample problem and it should be numbered 1.2. The equation below will be labelled as P.1.2.1, though the syntax for the tag is same. \begin{equation} P = Q + R \tag{P.\thechapter.\theprob.1} \end{equation} How can one create unique syntax for these tags which can be used in \texttt{ref}. \end{document} Edit: I have managed to create a new counter which produces the required result.
\newcounter{ptag}[prob] \newcommand{\ptag}{ \stepcounter{ptag} {\textbf{P.\thechapter.\theprob.\arabic{ptag}}}} Using this inside the problem environment as \tag{\ptag} gives the required result. But the question of how to uniquely refer to this equation tag using \ref is not clear to me.

\newcounter{prob}[chapter]will reset the prob counter whnever the chapter counter changes.\renewcommand{\theprob}{\thechapter.arabic{prob}}will handle the formatting for\refetc.\ptagwhich will give the required output (See the edit). However question remains how to use it with\refas all the instances will be given by\tag{\ptag}.\label{a}to one of your equations and put somewhere\ref{a}, this produces "P.1.1.1" (or similar).