I am having trouble with \ref after redefining \section. I am working with a template given to me and previously they were changing the definition of \thesection to make the section headings appear as required. This in turn messed up equation numbering because I need "section.equation" and "section.subsection.equation" equation numbering (so the \thesection definition was coming through here). Instead, I returned \thesection to default defined in article.cls and set up the following for \section, \subsection, and \subsubsection.
\def\section{\@ifstar\@mysection\@@mysection}
\def\subsection{\@ifstar\@mysubsection\@@mysubsection}
\def\subsubsection{\@ifstar\@mysubsubsection\@@mysubsubsection}
\newcommand{\@@mysection}[1]{%
\vskip 24pt%
\hspace{-3.5ex \@plus -1ex \@minus -.2ex}%
\stepcounter{section}%
\if@app%
\bgroup%
\Large\bfseries\Alph{section}. #1 \newline
\egroup
\numberwithin{equation}{section}
\renewcommand{\theequation}{\Alph{section}.\arabic{equation}}
\else%
\def\thesection{\@arabic\c@section}%
\bgroup%
\Large\bfseries\@arabic\c@section. #1 \newline
\egroup
\numberwithin{equation}{section}
\renewcommand{\theequation}{\arabic{section}.\arabic{equation}}
\fi
}
\newcommand{\@mysection}[1]{%
\vskip 24pt%
\hspace{-3.5ex \@plus -1ex \@minus -.2ex}%
\bgroup%
\Large\bfseries #1 \newline
\egroup
}
\newcommand{\@@mysubsection}[1]{%
\vskip 18pt%
\hspace{-3.5ex \@plus -1ex \@minus -.2ex}%
\stepcounter{subsection}%
\if@app%
\bgroup%
\large\bfseries\Alph{section}.\arabic{subsection}. #1 \newline
\egroup
\setcounter{equation}{0}
\numberwithin{equation}{subsection}
\renewcommand{\theequation{\Alph{section}.\arabic{subsection}.\arabic{equation}}
\else %
\bgroup%
\large\bfseries\@arabic\c@section.\@arabic\c@subsection. #1 \newline
\egroup
\setcounter{equation}{0}
\numberwithin{equation}{subsection}
\renewcommand{\theequation}{\arabic{section}.\arabic{subsection}.\arabic{equation}}
\fi
}
\newcommand{\@mysubsection}[1]{%
\vskip 24pt%
\hspace{-3.5ex \@plus -1ex \@minus -.2ex}%
\bgroup%
\large\bfseries #1 \newline
\egroup
}
\newcommand{\@@mysubsubsection}[1]{%
\vskip 18pt%
\hspace{-3.5ex \@plus -1ex \@minus -.2ex}%
\stepcounter{subsubsection}%
\if@app%
\bgroup%
\normalsize\bfseries\Alph{section}.\arabic{subsection}.\arabic{subsubsection}. #1 \newline
\egroup
\setcounter{equation}{0}
\numberwithin{equation}{subsubsection}
\renewcommand{\theequation}{\Alph{section}.\arabic{subsection}.\arabic{subsubsection}.\arabic{equation}}
\else %
\bgroup%
\normalsize\bfseries\@arabic\c@section.\@arabic\c@subsection.\@arabic\c@subsubsection. #1 \newline
\egroup
\setcounter{equation}{0}
\numberwithin{equation}{subsubsection}
\renewcommand{\theequation}{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}.\arabic{equation}}
\fi
}
\newcommand{\@mysubsubsection}[1]{%
\vskip 24pt%
\hspace{-3.5ex \@plus -1ex \@minus -.2ex}%
\bgroup%
\normalsize\bfseries #1 \newline
\egroup
}
The trouble is that whenever I reference a section, subsection, or subsubsection with \ref, nothing is printed. If I use \hyperref[sec:4]{4} (for example) it works. What am I doing wrong?

\stepcounterby\refstepcounter, but without seeing a compilable document, this is guessing only. The labelling mechanism 'relies' on\refstepcounter. The explicit\setcounter{equation}statements are strange. – Dec 29 '17 at 22:00\stepcounterwasn't what I was supposed to be using. – Jacob House Dec 29 '17 at 22:12\@@mysubsectionmacro and change the three\stepcounters to\refstepcounter. That should straighten out things. Perhaps a better question would be how you came up with these definitions in the first place. Maybe something better can be done (there seems to be a lot of code duplication, even if it's just conditioning on whether or not you're in the appendix -\if@app). – Werner Dec 29 '17 at 22:13\sectionetc. fromarticle– Dec 29 '17 at 22:17\thesectionto achieve the desired effect but this impacted equation numbering so here we are... Before it's all said and done I may try to rework it entirely to reduce all the duplicate code as suggested by @Werner. – Jacob House Dec 29 '17 at 22:20\thesectionhas multiple side effects. Change\@seccntformatrather. – Dec 29 '17 at 22:22\hspace{-3.5ex \@plus -1ex \@minus -.2ex}%instructions could (in fact: should) be replaced by\noindent... – Mico Dec 29 '17 at 22:32\refstepcountercomes too early for theappendixcode (\if@app), besides that, all that is inside a group, so a change of\thesectionwould not work outside – Dec 29 '17 at 22:51\if@app \renewcommand{\thesection}{\Alph{section}} \fibefore\refstepcounter{section}in your\@@mysectionmacro – Dec 29 '17 at 22:53