[Tex/LaTex] Adding title pages into document with \input

inputtitlestitletoc

The code below works if I do not include \input{ChapterHeading.tex}, but I would like to include this if possible?

\documentclass{article}

\begin{document}
\input{title.tex}
\tableofcontents
\clearpage
\input{ChapterHeading.tex}
\chapter{(Chapter One)} \input{Introduction.tex}
\chapter{Chapter Two} \input{rv-NSS.tex}
\end{document}

and this is the ChapterHeading.tex file

\documentclass{book}
\usepackage{graphics}

\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\Large\raggedleft}
{\MakeUppercase{\chaptertitlename}%
\rlap{ \resizebox{!}{1.5cm}{\thechapter} \rule{5cm}{1.5cm}}}
{10pt}{\Huge}
\titlespacing*{\chapter}{0pt}{30pt}{20pt}


 \setcounter{chapter}{0}
 \begin{document}
 \pagenumbering{gobble}
 \chapter{Introduction}
 \end{document}

Best Answer

If you put the preamble of ChapterHeading.tex in HeadingPreamble.tex, you may achieve:

\documentclass{article}

\input{HeadingPreamble.tex}

\begin{document}
\input{title.tex}
\tableofcontents
\clearpage
\input{ChapterHeading.tex}
\chapter{(Chapter One)} \input{Introduction.tex}
\chapter{Chapter Two} \input{rv-NSS.tex}
\end{document}

HeadingPreamble.tex file

\usepackage{graphics}

\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\Large\raggedleft}
{\MakeUppercase{\chaptertitlename}%
\rlap{ \resizebox{!}{1.5cm}{\thechapter} \rule{5cm}{1.5cm}}}
{10pt}{\Huge}
\titlespacing*{\chapter}{0pt}{30pt}{20pt}

\setcounter{chapter}{0}

ChapterHeading.tex file

\pagenumbering{gobble}

It is sensible to just remove ChapterHeading.tex, so the main document would be:

\documentclass{article}

\input{HeadingPreamble.tex}

\begin{document}
\input{title.tex}
\tableofcontents
\clearpage
\pagenumbering{gobble}
\chapter{(Chapter One)} \input{Introduction.tex}
\chapter{Chapter Two} \input{rv-NSS.tex}
\end{document}
Related Question