-
Notifications
You must be signed in to change notification settings - Fork 0
/
purdue-ece-lab.sty
201 lines (174 loc) · 6.8 KB
/
purdue-ece-lab.sty
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
% Made largely over the course of the 2021 fall semester as students in ECE 2k7 by Bryce Berger and Robert Sammelson
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{purdue-ece-lab}[Unofficial Latex Package for ECE labs]
% caption editing
\RequirePackage[labelfont=bf]{caption}
% code highlighting
\RequirePackage{listings}
% better tables
% \RequirePackage{longtable,booktabs,multirow}
% SI units
\RequirePackage{siunitx}
% table of contents management
\RequirePackage{tocloft}
% circuit diagrams
\RequirePackage[siunitx,american,RPvoltages]{circuitikz}
% plots
\RequirePackage{pgfplots}
% option parsing
\RequirePackage{pgfopts}
% header
\RequirePackage{fancyhdr}
% access to the floating point unit, for \error etc
\RequirePackage{xfp}
% for getting the name of the section, needed for \label inside circuit and environments
\RequirePackage{nameref}
% hyperlinks/references/etc
\RequirePackage{hyperref}
\pgfqkeys{/lab}
{
.is family
,title/.initial = lab title not set
,labnum/.initial = 0
,author/.initial = author not set
,author/.store in = \lab@author
,partner/.store in = \lab@partner
,course/.initial = course not set
}
\ProcessPgfOptions{/lab}
% author setup
% conditional to check if partner was given
\ifx\lab@partner\undefined\author{\small Author\vspace{-.5ex}\\\large\lab@author}\else\author{\small Author\vspace{-.5ex}\\\large\lab@author\and\small Lab Partner\vspace{-.5ex}\\\large\lab@partner}\fi
% header and footer setup
\fancyhf{}
\ifx\lab@partner\undefined\rhead{\lab@author}\else\setlength{\headheight}{24.0pt}\addtolength{\topmargin}{-12.0pt}\rhead{\begin{tabular}{rr}\lab@author\\\lab@partner\end{tabular}}\fi
\lhead{Lab \pgfkeysvalueof{/lab/labnum}: \pgfkeysvalueof{/lab/title}}
\cfoot{\thepage}
\pagestyle{fancy}
% title setup
\title{\sc \pgfkeysvalueof{/lab/course} \vspace{2ex}\\\normalsize Lab \pgfkeysvalueof{/lab/labnum}\\\Large \pgfkeysvalueof{/lab/title}}
% SIunitx, pgf, and tikz setup
\sisetup{retain-explicit-plus, table-format=-3.3, output-complex-root=\ensuremath{j}, complex-root-position=before-number}
\usetikzlibrary{arrows, intersections}
\pgfplotsset{compat=newest}
\ctikzset{multipoles/dipchip/width=2.5, multipoles/dipchip/pin spacing=1}
% table of contents
\hypersetup{colorlinks,linktoc=all,citecolor=black,filecolor=black,linkcolor=black,urlcolor=black}
\cftsetindents{section}{0em}{3.8em}
\cftsetindents{subsection}{3.8em}{3.8em}
% list of plots
\newcommand{\listplotsname}{List of Plots}
\newlistof{plots}{plt}{\listplotsname}
\renewcommand{\cftplttitlefont}{\bfseries\Large}
\providecommand*{\plotsautorefname}{Plot}
% list of circuits
\newcommand{\listcircuitsname}{List of Circuits}
\newlistof{circuits}{cir}{\listcircuitsname}
\renewcommand{\cftcirtitlefont}{\bfseries\Large}
\providecommand*{\circuitsautorefname}{Circuit}
% task and subtask environments
\renewcommand{\thesection}{\pgfkeysvalueof{/lab/labnum}.\arabic{section}}
\newcommand{\task}[2][]{\newpage\setcounter{section}{#2}\addtocounter{section}{-1}\section{#1}}
\newcommand{\subtask}[2][]{\setcounter{subsection}{#2}\addtocounter{subsection}{-1}\subsection{#1}}
\newcommand{\objective}{\paragraph{Objective}}
\newcommand{\conclusion}{\paragraph{Conclusion}}
% plot environment
\NewDocumentEnvironment{plot}{s +b}
{
\global\let\tempcaptionshort\relax
\IfBooleanT{#1}
% if star provided, use previous number as reference
% have to do -1 because \refstepcounter either way
{\addtocounter{plots}{-1}}
\refstepcounter{plots}
\begin{center}
\begin{tikzpicture}
% define label command
% long because hyperref
\def\label##1{\@bsphack\protected@write\@auxout{}{\string\newlabel{##1}{{\@currentlabel}{\thepage}{\@currentlabelname}{plots.\theplots}{}}}\@esphack}
% define caption command
% \def\caption##1{\global\def\tempcaption{##1}}
\renewcommand{\caption}[2][]{
\global\def\tempcaption{##2}
\global\def\tempcaptionshort{##1}}
#2
\end{tikzpicture}
\ifx\tempcaption\undefined
\global\def\tempcaption{}
\else
\if
\relax\tempcaption\relax\@makecaption{Plot \theplots}{}
\else
\@makecaption{Plot \theplots}{\tempcaption}
\fi
\fi
\end{center}
\IfBooleanF{#1}
% test for optional argument of caption
{\if\relax\tempcaptionshort\relax
\addcontentsline{plt}{figure}{\protect\numberline{\theplots}\tempcaption}
\else
\addcontentsline{plt}{figure}{\protect\numberline{\theplots}\tempcaptionshort}
\fi}
}
{\global\let\tempcaption\undefined\global\let\tempcaptionshort\undefined}
% circuit environment
\NewDocumentEnvironment{circuit}{s +b}
{
\global\let\tempcaptionshort\relax
\IfBooleanT{#1}
% if star provided, use previous number as reference
% have to do -1 because \refstepcounter either way
{\addtocounter{circuits}{-1}}
\refstepcounter{circuits}
\begin{center}
\begin{circuitikz}
% define label command
% long because hyperref
\def\label##1{\@bsphack\protected@write\@auxout{}{\string\newlabel{##1}{{\@currentlabel}{\thepage}{\@currentlabelname}{circuits.\thecircuits}{}}}\@esphack}
% define caption command
% \def\caption##1{\global\def\tempcaption{##1}}
\renewcommand{\caption}[2][]{
\global\def\tempcaption{##2}
\global\def\tempcaptionshort{##1}}
#2
% ending code starts here
\end{circuitikz}
% make caption, compatible with captions package
\ifx\tempcaption\undefined
\global\def\tempcaption{}
\else
\if
\relax\tempcaption\relax\@makecaption{Circuit \thecircuits}{}
\else
\@makecaption{Circuit \thecircuits}{\tempcaption}
\fi
\fi
\end{center}
% start test for toc
\IfBooleanF{#1}
% test for optional argument of caption
{\if\relax\tempcaptionshort\relax
\addcontentsline{cir}{figure}{\protect\numberline{\thecircuits}\tempcaption}
\else
\addcontentsline{cir}{figure}{\protect\numberline{\thecircuits}\tempcaptionshort}
\fi}
}
{\global\let\tempcaption\undefined\global\let\tempcaptionshort\undefined}
% colors for code
\definecolor{numbers}{rgb}{0.50, 0.50, 0.50}
\definecolor{comment}{rgb}{0.00, 0.60, 0.00}
\definecolor{string}{rgb} {0.58, 0.00, 0.82}
\definecolor{keyword}{rgb}{0.00, 0.00, 1.00}
% \definecolor{identifier}{rgb}{0.00, 0.00, 0.00} % black
% \inputcode[optional lst arguments]{filename.ext}
\lstset{frame=tb, language=python,aboveskip=3mm, belowskip=3mm, showstringspaces=false, columns=flexible, basicstyle={\small\ttfamily}, numbers=left, numberstyle=\footnotesize\color{numbers}, keywordstyle=\color{keyword}, commentstyle=\color{comment}, stringstyle=\color{string}, breaklines=true, breakatwhitespace=true, tabsize=4}
\makeatletter
\newcommand\inputcode[2][]{%
\filename@parse{\detokenize{#2}}
\lstinputlisting[title = \texttt{\filename@base.\filename@ext}, #1]{#2}}
\makeatother
% \error{actual}{expected}
\newcommand{\error}[2]{\fpeval{round(abs((#1 - #2)/#2 * 100),2)}}
% \efficiency{useful}{total}
\newcommand{\efficiency}[2]{\fpeval{round(abs(#1/(#1 + #2) * 100),2)}}