[Tex/LaTex] How to remove “zero” preceding section number

numberingsectioningsections-paragraphstable of contents

\documentclass[11pt]{book}
\usepackage[svgnames]{xcolor}
\makeatletter
\let\stdl@section\l@section
\renewcommand*{\l@section}[2]{%
  \stdl@section{\textcolor{blue}{#1}}{\textcolor{blue}{#2}}}
\let\stdl@subsection\l@subsection
\renewcommand*{\l@subsection}[2]{%
  \stdl@subsection{\textcolor{DarkGreen}{#1}}{\textcolor{DarkGreen}{#2}}}
\makeatother
\setcounter{tocdepth}{2}
\begin{document}
\tableofcontents

\chapter*{chapter1}
\addcontentsline{toc}{chapter}{Chapter1}
\section{Section One}
\subsection{Subsection One}
\subsection{Subsection Two}
\section{Section Two}
\subsection{Subsection One}
\subsection{Subsection Two}
\end{document}

Now it has a preceding zero in front of the section numbers. How can I get rid of zero. For reference I am attaching an image as well. enter image description here

Best Answer

this will get rid of the zero and period in both the toc and the body of the document:

\makeatletter
\renewcommand{\thesection}{%
  \ifnum\c@chapter<1 \@arabic\c@section
  \else \thechapter.\@arabic\c@section
  \fi
}
\makeatother

this assumes that the chapter counter is already properly defined, as it is in the book and report classes.