# section numbering including only the lowest sectionning level

I'd like to have in my document the main parts (chapter, section) not numbered, but having numbered subsections and subsubsections. I'd like that the numbers restart in each new unit.

I was trying to change the numbering by adding to preable:

\renewcommand{\thesubsection}{\arabic{subsection}}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}

but the numbering continue in whole document and don't restart in each section, I guess it restarts after each numbered section of a higher level.

What I'd like to achive is to have in the body of document *chapter and *section; subsubsection always numbered and subsection sometimes starred, sometimes not.

Here is minimal working example:

\documentclass{book}
\usepackage{fontspec}
\usepackage{polyglossia}

\setmainlanguage{polish}
\setotherlanguage[locale=mashriq]{arabic}
\setromanfont[Mapping=tex-text]{Linux Libertine O}

\renewcommand{\thesubsection}{\arabic{subsection}}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{0}

\begin{document}

\chapter*{Pierwszy}

\section*{Jakaś część}
\subsection{To też}
\subsubsection{aaa}
\subsubsection{bbb}
\subsection{I to również}
\subsubsection{ccc}
\subsubsection{dddd}

\section*{Inna część}
\subsection*{A to podpunkt}
\subsubsection{aaa}
\subsubsection{bbb}
\subsection*{I to}
\subsubsection{ccc}
\subsubsection{dddd}

\chapter*{Drugi}

\section*{Jakaś część}
\subsection*{To też}
\subsubsection{aaa}
\subsubsection{bbb}
\subsection*{I to również}
\subsubsection{ccc}
\subsubsection{dddd}

\section*{Inna część}
\subsection{A to podpunkt}
\subsubsection{aaa}
\subsubsection{bbb}
\subsection{I to}
\subsubsection{ccc}
\subsubsection{dddd}

\tableofcontents

\end{document}

Maybe I'm trying to achive what I wont with wrong tool. Thanks for any hints.

-
I don't think packages like fontspec and polyglossia are relevant, you can remove them (as well as their options) from your example, so that one doesn't need xetex to compile the MWE. –  T. Verron Dec 5 '12 at 17:00
What should happen to the subsubsection counter when you use \subsection*? Should it reset or not? –  Werner Dec 5 '12 at 17:07
@T.Verron I could remove it if my goal was only compile the MWE, but I need this solution to compile a document where I do need xetex. That's why I'm keeping fontspec and polyglossia here. –  maria Dec 5 '12 at 17:10
@Werner Starred versions give no numbering in the output. And I would like to have subsubsections numbered... –  maria Dec 5 '12 at 17:12
@maria: That doesn't answer the question. What should happen to the counter associated with \subsubsection when you have an unnumbered (or starred) \subsection? Typically, using \subsection would restart the \subsubsection counter, while using \subsection* would not restart the \subsubsection counter. –  Werner Dec 5 '12 at 17:18

I don't really think this is a good idea, but the book is yours. The numbers should help readers in orienting themselves in the book.

But here's a way to do it.

\documentclass{book}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{fancyhdr} % this is necessary
\usepackage{kantlipsum} % this is only to provide mock text

\setmainlanguage{polish}
\setmainfont[Ligatures=TeX]{Linux Libertine O}

\renewcommand{\thesubsection}{\arabic{subsection}}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{0}

\makeatletter
\def\@seccntformat#1{\csname mythe#1\endcsname}
\let\latex@subsection\subsection
\def\subsection{\@ifstar{\refstepcounter{subsection}\latex@subsection*}{\latex@subsection}}
\vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\interlinepenalty\@M
\Huge \bfseries #1\par\nobreak
\vskip 40\p@
}}
\let\latex@l@chapter\l@chapter
\def\l@chapter#1#2{\begingroup\let\numberline\@gobble\latex@l@chapter{#1}{#2}\endgroup}
\makeatother

\pagestyle{fancy}
\fancyhf{}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}}

\begin{document}

\chapter{Pierwszy}

\section{Jakaś część}
\subsection{To też}
\subsubsection{aaa}
\subsubsection{bbb}
\subsection{I to również}
\subsubsection{ccc}
\subsubsection{dddd}

\section{Inna część}
\subsection*{A to podpunkt}
\subsubsection{aaa}
\subsubsection{bbb}
\subsection*{I to}
\subsubsection{ccc}
\subsubsection{dddd}

\chapter{Drugi}

\section{Jakaś część}
\subsection*{To też}
\subsubsection{aaa}
\kant[1]

\subsubsection{bbb}
\kant[1]

\subsection*{I to również}
\subsubsection{ccc}
\kant[1]

\subsubsection{dddd}
\kant

\section{Inna część}
\subsection{A to podpunkt}
\subsubsection{aaa}
\subsubsection{bbb}
\subsection{I to}
\subsubsection{ccc}
\subsubsection{dddd}

\tableofcontents

\end{document}

Some explanations are in order.

1. The easiest and best documented hack is the one with fancyhdr, where the way the headers are defined is set. The hack consists in removing the "Chapter n" or section number bit from the headers by redefining \chaptermark and \sectionmark.

2. Each sectioning command from \section and below executes \@seccntformat{<level>}, where <level> stands for section, subsection and so on. The usual definition is

and I redefine it as

\def\@seccntformat#1{\csname mythe#1\endcsname}

so \mythesection and so on will be executed in turn or nothing at all if the command is not defined. Therefore it's sufficient to define \mythesubsection and \mythesubsubsection.

3. I redefine also \@makechapterhead, removing the part where "Chapter n" is set.

4. \subsection is redefined so that the number is stepped anyway. One might prefer

\def\subsection{%
\@ifstar
{\setcounter{subsubsection}{0}\latex@subsection*}
{\latex@subsection}}

so that the subsection number is not stepped, but only the subsubsection counter is reset to 0.

5. Finally \l@chapter is modified so that \numberline will ignore its argument and the chapter number will not appear in the table of contents.

-
+1 for "not a good idea" –  Brent.Longborough Dec 5 '12 at 17:12
@egreg Thanks a lot, it works now exactly how I wanted! As for letting main parts of document unnumbered, I agree with you, but here I have some special thing to do and it would really be more clear like that. –  maria Dec 5 '12 at 17:33