summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/unifront/unifront.sty
blob: 81179aafb4b1db658db0d93a9dab14a6efef5e11 (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
%% unifront.sty
%% Copyright 2023 Weifan Wei
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
%   https://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2008 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Weifan Wei
%
% This work consists of the files unifront-manual.tex and unifront.sty.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{unifront}[2023/05/07 v1.0 Unique front structure]

%  Package requirements
\RequirePackage{xcolor}
\RequirePackage{calc}

% Page setup
\setlength{\oddsidemargin}{0.25 in}
\setlength{\evensidemargin}{-0.1 in}
\setlength{\topmargin}{-0.7 in}
\setlength{\textwidth}{6.1 in}
\setlength{\textheight}{9.5 in}
\setlength{\headsep}{0.4 in}
\setlength{\parindent}{0 in}
\setlength{\parskip}{0 in}

% Global variables
\newcommand{\front@size}{0.97\textwidth}
\newcommand{\bars@vertical@size}{1ex}

% Colour setup
\definecolor{my@red}{RGB}{255, 0, 0}
\definecolor{my@blue}{RGB}{26, 140, 255}
\definecolor{my@yellow}{RGB}{255, 255, 0}
\definecolor{my@gray}{RGB}{191, 191, 191}

% Default colour
\newcommand{\bar@colour}{my@blue}
\newcommand{\bar@other@half}{my@gray}

% The options of this package
\DeclareOption{red}{%
    \renewcommand{\bar@colour}{my@red}%
    \PackageInfo{unifront}{bar's colour has been set to red}%
}
\DeclareOption{blue}{%
    \renewcommand{\bar@colour}{my@blue}%
    \PackageInfo{unifront}{bar's colour has been set to blue}%
}
\DeclareOption{yellow}{%
    \renewcommand{\bar@colour}{my@yellow}%
    \PackageInfo{unifront}{bar's colour has been set to yellow}%
}
\DeclareOption{help}{%
    \PackageWarningNoLine{unifront}{Go to https://github.com/weifanw/unifront for more information}
    \PackageInfo{unifront}{bar's colour has been set to yellow}%
}
\DeclareOption*{%
    \PackageWarning{unifront}{Unknown Colour ‘\CurrentOption’, You can choose from 'red', 'blue', 'yellow', 'help'}%
    \PackageInfo{unifront}{bar's colour retain the default}%
}
\ProcessOptions\relax

% Print content line
\newcounter{chapter@counter}
\newcounter{section@counter}[chapter]
\newcounter{subsection@counter}[section]
\newcounter{odd@even}

\newcommand{\print@chapter@line}[1]{%
    \contentsline{chapter}{%
        \numberline{\thechapter@counter}#1%
    }{%
        \pageref{#1}%
    }\\
    \PackageInfo{unifront}{content line '#1' has been generate}%
}
\newcommand{\print@section@line}[1]{%
    \contentsline{section}{%
        \numberline{\ref{#1}}#1%
    }{%
        \pageref{#1}%
    }\\
    \PackageInfo{unifront}{content line '#1' has been generate}%
}
\newcommand{\print@subsection@line}[1]{%
    \contentsline{subsection}{%
        \numberline{\ref{#1}}#1%
    }{%
        \pageref{#1}%
    }\\
    \PackageInfo{unifront}{content line '#1' has been generate}%
}

% Count current elements
\newcommand{\count@chapters}[2]{%
    \refstepcounter{chapter@counter}%
    \currentchapter{#2}%
}
\newcommand{\count@sections}[2]{%
    \refstepcounter{section@counter}%
    \currentsections{#2}%
}
\newcommand{\count@subsections}[2]{%
    \refstepcounter{subsection@counter}%
    \currentsubsections{#2}%
}

% Get current elements
\newcommand{\currentchapter}[1]{%
    \ifodd\theodd@even{%
        \PackageInfo{unifront}{print chapter's content line '#1' }%
        \print@chapter@line{#1}%
    }%
    \fi
    \@ifnextchar\bgroup{%
        \PackageInfo{unifront}{count chapter '#1' }%
        \count@chapters{#1}%
    }{%
        \refstepcounter{chapter@counter}%
    }%
}
\newcommand{\currentsections}[1]{%
    \ifodd\theodd@even{%
        \PackageInfo{unifront}{print section's content line '#1' }%
        \print@section@line{#1}%
    }%
    \fi
    \@ifnextchar\bgroup{%
        \PackageInfo{unifront}{count section '#1' }%
        \count@sections{#1}%
    }{%
        \refstepcounter{section@counter}%
    }%
}
\newcommand{\currentsubsections}[1]{%
    \ifodd\theodd@even{%
        \PackageInfo{unifront}{print subsection's content line '#1' }%
        \print@subsection@line{#1}%
    }\fi
    \@ifnextchar\bgroup{%
        \PackageInfo{unifront}{count subsection '#1' }%
        \count@subsections{#1}%
    }{%
        \refstepcounter{subsection@counter}%
    }%
}

% Print the corresponding progress bar
\newcommand{\progress@bar}[2]{%
    \textcolor{\bar@colour}{%
        \rule{\front@size * #1 / \real{#2}}{\bars@vertical@size}%
    }%
    \textcolor{\bar@other@half}{%
        \rule{\front@size - \front@size * #1 / \real{#2}}{\bars@vertical@size}%
    }%
    \setcounter{chapter@counter}{1}%
}

% Generate the corresponding front page
\newcommand{\newtitle}[3]{%
    \title{#1}%
    \clearpage
    \pagestyle{myheadings}%
    \thispagestyle{empty}%
    \begin{center}%
    \begin{tabular}{p{\front@size}}%
    \maketitle\\
    \setcounter{odd@even}{2}#3%
    \progress@bar{\value{chapter@counter}}{#2}\\
    \setcounter{odd@even}{1}%
    #3%
    \end{tabular}%
    \end{center}%
    \PackageInfo{unifront}{new report #1's front page has been generate}%
    \newpage%
    \setcounter{page}{1}%
}
\newcommand{\newchapter}[3]{%
    \clearpage
    \thispagestyle{plain}%
    \begin{center}%
    \begin{tabular}{p{\front@size}}%
    \chapter{#1}\\\label{#1}%
    \setcounter{odd@even}{2}#3%
    \progress@bar{\value{section@counter}}{#2}\\
    \setcounter{odd@even}{1}%
    {\bf\Large#3}%
    \end{tabular}%
    \end{center}%
    \markboth{#1}{#1}%
    \PackageInfo{unifront}{new chapter #1's front page has been generate}%
}
\newcommand{\newsection}[3]{%
    \clearpage
    \thispagestyle{plain}%
    \begin{center}%
    \begin{tabular}{p{\front@size}}%
    \section{#1}\label{#1}%
    \setcounter{odd@even}{2}#3%
    \progress@bar{\value{subsection@counter}}{#2}\\
    \setcounter{odd@even}{1}%
    \bf#3%
    \end{tabular}%
    \end{center}%
    \PackageInfo{unifront}{new section #1's front page has been generate}%
}
\newcommand{\newsubsection}[1]{%
    \subsection{#1}\label{#1}%
}
\endinput