Well, I am trying to write a short summary about my template and I have come to a crossroads. In my class definition, I redefined the \section{} command to \section*{} to maintain a certain stylization of my template, but now I want to reference the sections independently, but keep the property that if I write \section{A random title} the title will remain unnumbered.
Let me explain this in more detail:
I redefined the
\section{}command with these lines of code:\let\oldsection\section \renewcommand{\section}[1]{% \oldsection*{#1} \phantomsection \addcontentsline{toc}{section}{#1} }When I use
\ref{A label given to the section}in two different sections, I get the following result:
- I do not need the
\section{}command to be numbered because I have created a mini-summary that contains the name of each section within the chapter as follows:
I think it is not necessary to include the code of this mini-summary, so as not to overload the post with information.
Essentially, I would like help just to figure out how to make this \ref{} work.



\label-\refmechanism works by (a)\label{<arg>}creating an association between<arg>and the most recently incremented LaTeX counter (specifically, the counter has to be incremented via a\refstepcounterinstruction), and (b)\ref{<arg>}resolving to the value of the counter at the time it got associated with<arg>. By using\section*instead of\section, you are going out of your way not to increment the counter calledsection. What do you think\labelshould be associated with? If\ref{<arg>}resolved to "2", what are your readers supposed to make of it? – Mico Mar 04 '23 at 10:26\label{}to associate with the respective section number, but not print it when I used the\section{}, like a "ghost number". – Jimeens Mar 04 '23 at 10:33\section*instead of\section, you're not only not printing the section number, i.e., the value of the counter calledsection, you are also making sure that thesectioncounter isn't incremented to begin with. After all, what would it even mean for a number be associated with a sectioning header that, by design, doesn't have a number associated with it? I've noticed that you've set the tag "hyperref". Why aren't you using that package's\hypertarget/\hyperlinkmechanism to create cross-references to unnumbered objects? – Mico Mar 04 '23 at 10:42\hypertarget/\hyperlinkmechanism to create cross-rereferences to unnumbered "objects", please see the posting How to cross-reference an unnumbered theorem using hyperref and cleveref. – Mico Mar 04 '23 at 10:52\hypertargetis its generality: The mechanism works equally well with unnumbered sections, unnumbered theorems, unnumbered equations (presumably, with\hypertargetin the argument of a cleverly placed\tagor\tag*directive...), etc. You're right that this extra bit of generality isn't needed when the job at hand is to cross-reference a section-level header. – Mico Mar 04 '23 at 11:04\sectionmacro. Instead, just execute\setcounter{secnumdepth}{0}in the preamble. – Mico Mar 04 '23 at 11:23