LaTeX skeleton structure

I found this LaTeX skeleton on the TEX StackExchange Site by a user named XPort (opens in new window).

I thought it was quite useful so I reproduced it here to help you get started. It wasn’t used in the final product I created but it gave me an idea of how to go about building a LaTeX project for technical documentation.

Step 1 - Create Project Directories

Divide your project into at least the following subdirectories:

Step 2 - Create your own document class based on book class

Create a document class file to store LaTeX design settings. Name it mybook.cls and save it to the root of the MyProject directory. Then, add the following content to the file. Descriptions are provided following this file.

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
\ProvidesClass{mybook}[2011/06/07 v 0.01 my own class (hv)]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\ProcessOptions\relax
\LoadClass
[
%other default options go  here
]{book}

\newcommand\ContentsPath{Contents/}
\newcommand\ChapterPath{\ContentsPath}
\newcommand\SectionPath{\ChapterPath}
\newcommand\SubSectionPath{\SectionPath}

\@ifclassloaded{book}
{
    \newcommand\IncludeChapter[1]
    {
        \renewcommand\ChapterPath{\ContentsPath#1/}
        \include{\ContentsPath#1}
    }
    \newcommand\IncludeOnlyChapter[1]
    {
        \includeonly{\ContentsPath#1}
    }
}{}


\newcommand\InputSection[1]
{
    \renewcommand\SectionPath{\ChapterPath#1/}
    \input{\ChapterPath#1}
}

\newcommand\InputSubSection[1]
{
    \renewcommand\SubSectionPath{\SectionPath#1/}
    \input{\SectionPath#1}
}

\newcommand\InputSubSubSection[1]
{
    \input{\SubSectionPath#1}
}


\@ifclassloaded{book}
{
    \newcommand\Chapter[1]
    {
        \chapter{#1}
        %\addcontentsline{toc}{chapter}{#1}
    }
}{}

\newcommand\Section[1]
{
    \section{#1}%
    %\addcontentsline{toc}{section}{#1}
}

\newcommand\SubSection[1]
{
    \subsection{#1}
    %\addcontentsline{toc}{subsection}{#1}
}

\newcommand\SubSubSection[1]
{
    \subsubsection{#1}
    %\addcontentsline{toc}{subsubsection}{#1}
}

\RequirePackage{xcolor}

\RequirePackage{listings}
\lstdefinestyle{Common}
{
        breaklines=true,
        tabsize=3,
        showstringspaces=false,
        aboveskip=0pt,
        belowskip=0pt,
        extendedchars=\true,
        language=PHP,
        frame=single,   
        %===========================================================
        framesep=3pt,%expand outward.
        framerule=0.4pt,%expand outward.
        xleftmargin=3.4pt,%make the frame fits in the text area.
        xrightmargin=3.4pt,%make the frame fits in the text area.
        %===========================================================
        rulecolor=\color{Red}%
}

\lstdefinestyle{ThemeA}
{
        style=Common,
        backgroundcolor=\color{Yellow!10},
        basicstyle=\scriptsize\color{Black}\ttfamily,
        keywordstyle=\color{Orange},
        identifierstyle=\color{Cyan},
        stringstyle=\color{Red},
        commentstyle=\color{Green}
}

\newcommand{\IncludeCode}[2][style=ThemeA]
{
    \lstinputlisting[#1,caption={\href{#2}{#2}}]{#2}
}

\RequirePackage[colorlinks=true,bookmarksnumbered=true,bookmarksopen=true]{hyperref}
\RequirePackage[all]{hypcap}

\RequirePackage{makeidx}
\makeindex

\endinput

The following subtopics gives an explanation of the class file.

1
2
3
4
5
6
  \ProvidesClass{mybook}[2020/01/01 my own class (hv)]
  \DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
  \ProcessOptions\relax
  \LoadClass [
  %other default options go here
  ]{book}
1
2
3
4
\newcommand\ContentsPath{Contents/}
\newcommand\ChapterPath{\ContentsPath}
\newcommand\SectionPath{\ChapterPath}
\newcommand\SubSectionPath{\SectionPath}
1
2
3
4
5
6
7
8
9
10
11
12
\@ifclassloaded{book}
{
  \newcommand\IncludeChapter[1]
  {
    \renewcommand\ChapterPath{\ContentsPath#1/}
    \include{\ContentsPath#1}
  }
  \newcommand\IncludeOnlyChapter[1]
  {
    \includeonly{\ContentsPath#1}
    }
}{}
1
2
3
4
5
\newcommand\InputSection[1]
{
  \renewcommand\SectionPath{\ChapterPath#1/}
  \input{\ChapterPath#1}
}
1
2
3
4
5
\newcommand\InputSubSection[1]
{
  \renewcommand\SubSectionPath{\SectionPath#1/}
  \input{\SectionPath#1}
}
1
2
3
4
\newcommand\InputSubSubSection[1]
{
  \input{\SubSectionPath#1}
}
1
2
3
4
5
6
7
8
\@ifclassloaded{book}
{
  \newcommand\Chapter[1]
  {
    \chapter{#1}
    %\addcontentsline{toc}{chapter}{#1}
  }
}{}
1
2
3
4
5
\newcommand\Section[1]
{
  \section{#1}%
  %\addcontentsline{toc}{section}{#1}
}
1
2
3
4
5
\newcommand\SubSection[1]
{
  \subsection{#1}
  %\addcontentsline{toc}{subsection}{#1}
}
1
2
3
4
5
\newcommand\SubSubSection[1]
{
  \subsubsection{#1}
  %\addcontentsline{toc}{subsubsection}{#1}
}
1
\RequirePackage{xcolor}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
\RequirePackage{listings}
\lstdefinestyle{Common}
{
  breaklines=true,
  tabsize=3,
  showstringspaces=false,
  aboveskip=0pt,
  belowskip=0pt,
  extendedchars=\true,
  language=PHP,
  frame=single,  
  %===========================================================
  framesep=3pt,%expand outward.
  framerule=0.4pt,%expand outward.
  xleftmargin=3.4pt,%make the frame fits in the text area.
  xrightmargin=3.4pt,%make the frame fits in the text area.
  %===========================================================
  rulecolor=\color{Red}% }
1
2
3
4
5
6
7
8
9
10
\lstdefinestyle{ThemeA}
{
  style=Common,
  backgroundcolor=\color{Yellow!10},
  basicstyle=\scriptsize\color{Black}\ttfamily,
  keywordstyle=\color{Orange},
  identifierstyle=\color{Cyan},
  stringstyle=\color{Red},
  commentstyle=\color{Green}
}
1
2
3
4
\newcommand{\IncludeCode}[2][style=ThemeA]
{
  \lstinputlisting[#1,caption={\href{#2}{#2}}]{#2}
}
1
2
\RequirePackage[colorlinks=true,bookmarksnumbered=true,bookmarksopen=true]{hyperref}
\RequirePackage[all]{hypcap}
1
\RequirePackage{makeidx} \makeindex
1
\endinput

Step 3 - Create the main input file main.tex

This is a critical file. It is the main input file which you will compile to generate the project. It is called main.tex.

Create in the root of MyProject the main.tex file, then add the following content to the file.

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
\documentclass[dvipsnames,cmyk,12pt]{mybook}
\usepackage[a4paper,vmargin=15mm,hmargin=10mm]{geometry}

\title{Introduction to LaTeX}
\author{Your Name}
\date{\today}

%\IncludeOnlyChapter{Variables}

\begin{document}
\frontmatter
        \maketitle
        \thispagestyle{empty}
        \tableofcontents
    \lstlistoflistings
\mainmatter
        \part{Part 1}
                \IncludeChapter{Variables}
                \IncludeChapter{Array}
        \part{Part 2}   
                \IncludeChapter{Interface}
                \IncludeChapter{SubClass}
        \appendix\renewcommand{\chaptername}{\appendixname}
        \part{Appendix}
                \IncludeChapter{YourAppendix}
\backmatter
        \printindex
\end{document}

Step 4 - Create a Variables file

Create a file for chapter Variables called Variables.tex and save it to MyProject\Contents

1
2
3
\Chapter{Variables}
\InputSection{Declaration}
\InputSection{Instantiation}

Step 5 - Create Variables Directory

Create a directory within the MyProject\Contents\ and name it Variables.

Step 6 - Create a Declaration file

Create a file to hold a Declaration section and call it Declaration.tex. Then save it in MyProject\Contents\Variables.

1
2
3
\Section{Declaration}

\IncludeCode[style=ThemeA]{Codes/Declaration.php}

Step 7 - Start creating your topics

You can now start writing your topics for the project. Remember to save the files as .tex file and save to the MyProject\Content\ directory.

Finalize - Generate your ouput

Here is an ouput from this skeleton project.

Output from the LaTeX skeleton project

Output from the LaTeX skeleton project.