# hyperref does not work when section counter is reset

I am preparing a lecture note using the \documentclass lecture. In this document, I have few un-numbered sections (referring them throughout as Unit) which I want to show in the table of contents and the page number of these sections are not-numbered (using \pagenumbering{gobble}). The MWE is as follows:

\documentclass[english,course]{lecture}
\usepackage{blindtext}
\usepackage{enumitem}
\usepackage{lipsum} % Only needed to generate dummy text for sample.tex
%
\title{Main title of the lecture}
\subtitle{Subtitle of the lecture}
\shorttitle{Shortened title} % For headers; if undefined, the usual title will be used
\ccode{Code 7.45} % Most of these data are not compulsory
\subject{Subject of the Talk}
\author{Author's name}
% \date{02}{11}{2134}
% \dateend{07}{11}{2134}
\conference{Lecture hall 7}
\place{University of Physics}

\clearpage
%
% And then begin your document

\begin{document}
\setcounter{page}{1}
\pagenumbering{roman}  %roemische ziffern
\thispagestyle{empty}

% \tableofcontents

\clearpage

%-----------------------------
\setcounter{page}{1}
\pagenumbering{arabic}
%==========================================
\phantomsection
\pagenumbering{gobble} %
\section*{\textbf{UNIT $-$ I : Laws of Thermodynamics}}
\thispagestyle{fancy}
\label{sec:unitone}
\addcontentsline{toc}{section}{\textbf{UNIT $-$ I : Laws of Thermodynamics}\nameref{sec:unitone}}
%
%
\section*{Syllabus}

\begin{itemize}[itemsep=1.0\baselineskip]

\item[$\bullet$] Thermodynamic Description of system: Zeroth Law of thermodynamics and temperature. First law and internal energy, conversion of heat into work, various thermodynamical processes, Applications of First Law: General Relation between $C_p$ \& $C_v$, Work Done during
Isothermal and Adiabatic Processes, Compressibility \& Expansion Coefficient, Reversible \& irreversible processes, Second law \& Entropy, Carnot’s cycle \& theorem, Entropy changes in reversible \& irreversible processes, Entropy temperature diagrams, Third law of thermodynamics, unattainability of absolute zero.
\end{itemize}
\clearpage
% %--------------------------------------------------
\pagenumbering{arabic}
% %--------------------------------------------------
\section{Introduction}
\blindtext[15]
%
\section{Carnot's cycle}
\blindtext[15]
%
\clearpage
%
% =====================
\phantomsection
\pagenumbering{gobble}
\thispagestyle{fancy}
\section*{\textbf{UNIT $-$ II : Thermodynamic Potentials}}
\label{sec:unittwo}
\addcontentsline{toc}{section}{\textbf{UNIT $-$ II : Thermodynamic Potentials}\nameref{sec:unittwo}}
%
%
\section*{Syllabus}

\begin{itemize}[itemsep=1.0\baselineskip]

\item[$\bullet$] Thermodynamic Potentials: Enthalpy, Gibbs, Helmholtz and Internal Energy functions, Maxwell’s relations \& applications Joule Thompson Effect, Clausius Clapeyron Equation, Expression for ($C_p$,$C_v$ ), $C_p/C_v$, $T\,dS$ equations.
\end{itemize}

\clearpage

% %--------------------------------------------------
\pagenumbering{arabic} %
\setcounter{section}{0} % section numbers to restart for a new unit
\addtocounter{page}{6} % last page number is 6;;
% %--------------------------------------------------
\section{Thermodynamic Potentials} % % section number restarts

\blindtext[15]

\vskip7ex
\centering
* * *
%
\end{document}%


Every Unit has got few numbered sections which are shown in ToC with page numbers. These numbered sections restart from 1 after the start of a new Unit. The problem(s) I am having are as follows:

1. The hyperref does not work correctly when the section counter is restarted from 1. The answer to a similar issue did not solve my problem.

2. The page numbering is not continuous once \pagenumbering{gobble} is used. Before the start of numbered section, I have used \pagenumbering{arabic} but that restarts the page numbers. One solution I found is to add \addtocounter{page}{last page number} manually at the beginning of a new numbered section. Is there a better solution than this?

I don't want to download an external class. So some remarks without it

• don't use \pagenumbering{gobble} to suppress the printing of the page number on a page. Use a pagestyle for this. Either define a special style or redefine e.g. the plain style, see the documentation of fancyhdr.

• if you reset the section number you must ensure that that \theHsection stays unique through the document (by default it is \thesection). Redefine it in a suitable way.

• you don't have to plant the \phantomsection everywhere. hyperref creates destinations also for starred sections.

\documentclass[english,course]{article}
\usepackage{blindtext}

\usepackage{fancyhdr}
\pagestyle{fancy}
%new page style, or redefine plain style see docu
\fancypagestyle{specialstyle}[fancy]{\cfoot{no page number here}}
\fancypagestyle{fancy}{\cfoot{\thepage}}

\begin{document}
\pagenumbering{roman}  %roemische ziffern
\thispagestyle{empty}

xxxx
% \tableofcontents

\clearpage
\pagestyle{specialstyle}
\section*{\textbf{UNIT $-$ I : Laws of Thermodynamics}}
...
\section*{Syllabus}
...
\clearpage
\pagestyle{fancy}
\pagenumbering{arabic}

\section{Introduction}
\blindtext[15]

\section{Carnot's cycle}
\blindtext[15]

\clearpage
\pagestyle{specialstyle}

\section*{\textbf{UNIT $-$ II : Thermodynamic Potentials}}

\section*{Syllabus}

\clearpage
\pagestyle{fancy}
\setcounter{section}{0} % section numbers to restart for a new unit
\renewcommand\theHsection{A-\thesection} % something unique

\section{Thermodynamic Potentials} % % section number restarts

\blindtext[15]

\end{document}%