I created my own counter and an environment named problem. The counter increments on the level of a chapter, not section. When I label, e.g. \label{prb:3} and refer to it later in the text by \ref{prb:3}, instead of inserting the true problem number that was linked to that label, section number within which the problem lies gets inserted. That obiously makes a serious trouble.
Although I checked some similar previous questions on this problem, I have not recognized something that helps my case. For example, using Problem~\hyperref[prb:3]{prb:3} prints Problem prb:3, while it should, for example, be Problem 5-8.
Essentially, my \label and \ref command should link to my problem number and not to the section number within which the problem lies.
I believe there are more than enough LaTeX experts that can help me set up and resolve this case, preferably without complicated definitions.
Here is some MWE:
\documentclass[a4paper,11pt, oneside]{book}
\usepackage[utf8]{inputenc}
%%% my custom counter `problem` and the environment, which increments on the chapter level
\newcounter{problem}
\newenvironment{problem}{
\vspace{10pt}\noindent\stepcounter{problem}\\
{\bf\thechapter-\theproblem}\hspace{10pt}
}{}
\begin{document}
\chapter{First Chapter}
\section{Section 11}
\begin{problem}
Problem~1-1. \label{prb 11} % Problem 1-1
\end{problem}
\section{Section 12}
\begin{problem}
Problem 1-2. \label{prb 12} % Problem 1-2
\end{problem}
\begin{problem}
Problem 1-3. \label{prb 13} \\ % Problem 1-3
\end{problem}
\noindent Referring to Problem~1-3 by \ref{prb 13} incorrectly refers to Problem~1.2 because Problem~1-3 is in Section~\ref{prb 13} (that is: Section 1.1). \ \
\setcounter{problem}{0}
\chapter{Second Chapter}
\section{Section 21}
\begin{problem}
Problem 2-1. \label{prb 21} % Problem 2-1
\end{problem}
\begin{problem}
Problem 2-2. \label{prb 22} % Problem 2-2
\end{problem}
\begin{problem}
Problem 2-3. \label{prb 23} \\ % Problem 2-3
\end{problem}
\noindent Now referring to Problem~2-3 by \ref{prb 23} erroneously prints as Problem~2.1 because Problem~2-3 is within Section~\ref{prb 23} (that is: Section 2.1). \ \
So, not only is the number incorrect, but also the format. Instead of having chapter-problem# format, it has section# format. \
The question is: how can I make the \verb|\label| and \verb|\ref| not refer to a Section number, but to the Problem number within a particular chapter?
\end{document}

\begin{problem} some text \end{problem}That block then produces the problem numbers in the sequence 1-1, 1-2 etc, as indicated above. Using the syntax you suggested at the end as\renewcommand\theproblemactually read 1-1-1 instead of 1-1. I see in your snippet it reads well, but I got it inadequate in the text. I'll test it again and report. – MSJ Aug 17 '22 at 09:13When the \verb|\label| is used within the main file (as was in the MWE), the cross-referencing works well and \verb|\ref{prb_12}| CORRECTLY gives 1-2.
In contrast, when the label is defined within the outer file named \verb|prb_13| and included using the \verb|\input| command, the cross-referencing does not work well and \verb|\ref{prb_13}| gives 1.1, which is not the problem number, but the section number.
No room here to include that example.
– MSJ Aug 17 '22 at 13:20prb_13.tex. Unfortunately, we don't know what may be in it. Please advise. – Mico Aug 17 '22 at 14:24prb_13.tex, for the sake of this MWE, just contains the following:\label{prb_13} \begin{problem} Problem 1-3 % some sample text \end{problem}– MSJ Aug 17 '22 at 18:53problemenvironments: In both cases,\labelcomes between\begin{problem}and\end{problem}-- and cross-referencing works just fine. Why are you doing things differently when you place the self-containedproblemenvironment in an external file? I.e., why do you suddenly place\labelbefore\begin{problem}? For sure, if you place\label{prb_13}after instead of before\begin{problem}, everything will be just fine in terms of cross-referencing capabilities. – Mico Aug 17 '22 at 19:05\chapter{One} \section{One} \input{file1}while file1 contains: `\begin{problem} \input{prb_1} \end{problem}
\begin{solution} % another environment w/out counter \input{sol_1} \end{solution}`
where some line in
– MSJ Aug 17 '22 at 21:25sol_1has \ref{prb_1}. I had \label as the 1st line of prb_1 - didn't help. I now tried to have \label within the \begin{problem}. The outcome is the same: correct problem number, but w/out chapter num.\input. If\labeloccurs before\begin{problem}infile1.tex, then LaTeX has no choice but to associate the argument of\labelwith the counter that was most recently incremented via\refstepcounter; by your description, this happens to be thesectioncounter. You must place\labelbetween\begin{problem}and\end{problem}if you want LaTeX to associate the argument of\labelwith theproblemenvironment. – Mico Aug 17 '22 at 21:38\inputstatements. You do seem to strongly resist the suggestion to just place the\labelstatements inside theproblemenvironments; I honestly don't understand this apparent reluctance to follow a particular suggestion. If the formatting issues persist, do feel free to post a new query, in which you explain in full detail what you're doing and what you're trying to achieve. – Mico Aug 17 '22 at 22:54