How to create a chapter or part without starting a new page

In LaTeX, you can create a new chapter or part without starting a new page by \let\cleardoublepage\relax

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
\usepackage{xargs}  % add option arguments to \newcommand

% Create \chapter or \part without starting a new page.
\NewDocumentCommand{\unclear}{m}{
\begingroup
\let\cleardoublepage\relax
#1
\endgroup
}

% Create \mychapter without starting a new page.
% - s: stared version, hide the heading number
% - o: short ToC
% - m: section text
% - o: label
\NewDocumentCommand{\mychapter}{s o m o}{
\begingroup
\let\cleardoublepage\relax
\IfBooleanTF{ #1 }{
\chapter*{ #3 }
}{
\IfValueTF{ #2 }{
\chapter[#2]{ #3 }
}{
\chapter{ #3 }
}
}

\IfValueT{ #4 }{
\label{ #4 }
}
\endgroup
}

Reference