forked from btonks/calculus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.cls
319 lines (305 loc) · 13.3 KB
/
calc.cls
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
\pdfminorversion=4 % force pdf 1.4 output; http://tex.stackexchange.com/questions/95973/is-pdftex-1-40-13-outputting-malformed-pdfs
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{calc}
\LoadClass[9pt]{book}
\RequirePackage{mytocloft,titlesec,titletoc,multicol,makeidx,wrapfig,fancyhdr,calc,amssymb,fancyvrb,ifthen,framed,alphalph,cancel,url,learn-cmd-syntax,navigator}
\RequirePackage{color}%see pdftex mailing list, 2004 May 22-23
\renewcommand{\sfdefault}{phv}
\RequirePackage[EULERGREEK]{sansmath}
\RequirePackage[leqno]{amsmath}
\StartSaveCommands % for learn-cmd-syntax
\RequirePackage{lmmath}
\newcommand{\lmserifmath}{\mathversion{normal}\everymath{}\everydisplay{}}
% ========================== low-level stuff =========================================
\newcommand{\eqquad}{}
% I used to have flying punctuation after displayed math, e.g.,
% x=7 \qquad .
% I decided that looked bad, so I replaced the qquads with this do-nothing macro.
\newcommand{\zerosizebox}[3]{
\makebox[0mm][l]{%
\hspace{#1}%
\raisebox{0mm}[0mm][0mm]{% used to have #2 as 1st arg, but it went the wrong direction!
\makebox[0mm][l]{%
\begin{minipage}{8.5in}
\vspace{#2}#3
\end{minipage}%
}%
}%
}%
}%
\newcommand{\anonymousinlinefig}[1]{\includegraphics{\chapdir/figs/#1}}
% ========================== lengths =========================================
%----------- page layout ----------------
\setlength{\marginparwidth}{0mm}
\setlength{\textwidth}{4.3in}
\setlength{\textheight}{7.0in}
\setlength{\pdfpagewidth}{6in}
\setlength{\pdfpageheight}{9in}
\setlength{\hoffset}{-.25in}
\setlength{\voffset}{-.3in}
\setlength{\topmargin}{0in}
\setlength{\oddsidemargin}{.25in}
\setlength{\evensidemargin}{0mm}
%---------- my custom stuff for figures ------------
\newlength{\figwidth}
\setlength{\figwidth}{53mm}
\newlength{\smallfigwidth}
\setlength{\smallfigwidth}{35mm}
%---------- floats --------------------
\newlength{\defaultfloatsep}
\setlength{\defaultfloatsep}{10 pt plus 1 pt}
\setlength{\floatsep}{\defaultfloatsep}
\setlength{\textfloatsep}{\defaultfloatsep}
\setlength{\intextsep}{\defaultfloatsep}
%------------ equation spacing ---------------------
\newcommand{\myeqnspacing}{
\setlength{\abovedisplayskip}{4mm plus 1mm minus 3mm}
\setlength{\belowdisplayskip}{4mm plus 1mm minus 3mm}
\setlength{\abovedisplayshortskip}{0mm plus 1mm}
\setlength{\belowdisplayshortskip}{2mm plus 1mm minus 1mm}
}
\myeqnspacing
%------------ misc---------------------
\setlength{\parindent}{0mm}
\setlength{\parskip}{2mm plus 1mm}
\newlength{\myfooterspace}
\setlength{\myfooterspace}{5mm}
%============================= homework ==================================================
\newcommand{\givecredit}[1]{\hwaddtrailingstuff{\footnotesize{[#1]}}}
\newcommand{\thompson}{\givecredit{Thompson, 1919}}
\newcommand{\granville}{\hwaddtrailingstuff{\footnotesize{[Granville, 1911]}}}
\newcounter{hwctr}[chapter]
\newenvironment{hwsection}{
\setcounter{secnumdepth}{0} % Don't number this section.
\renewcommand{\printthesection}{} % Footers should read ``Problems,'' not ``Section X.Y Problems''
\hwcaptions % figures in hw section don't have a, b, c, labels
\setcounter{figure}{0} %
\hfill\clearpage %
\section{Problems} %
\setcounter{secnumdepth}{2} % Start numbering sections again.
% The \setcounter{secnumdepth} stuff is the way the author of titlesec suggests doing
% this. Using section* messes up footers & toc.
%\hwtopboilerplate\par
}%
{%
\vfill\normalcaptions
}
\newcommand{\hwdifficulty}{0}
% ... This needs to be a global variable because I only display the symbol in \end{hw},
% which doesn't have access to #1.
\newsavebox{\hwtrailingstuff}
\newcommand{\currenthwlabel}{}
\newenvironment{hw}[1][1]
{\refstepcounter{hwctr}\noindent\textbf{\thehwctr}%
\renewcommand{\hwdifficulty}{#1}%
\quad}
{%
\hwaddtrailingstuff{%
\displayhwdifficulty{\hwdifficulty}
}%
\hwflushtrailingstuff
}
\newenvironment{hwwithsoln}[2][1]
{\refstepcounter{hwctr}\noindent\textbf{\thehwctr}\label{hw:#2}%
\renewcommand{\hwdifficulty}{#1}%
\quad
\hwsoln{soln:#2}
}
{%
\hwaddtrailingstuff{%
\displayhwdifficulty{\hwdifficulty}
}%
\hwflushtrailingstuff
}
\newcommand{\hwhint}[1]{\hwaddtrailingstuff{\hwtriangle\ Hint, p. \pageref{#1}}}
\newcommand{\hwans}[1]{\hwaddtrailingstuff{\hwtriangle\ Answer, p. \pageref{#1}}}
\newcommand{\hwsoln}[1]{\hwaddtrailingstuff{\hwtriangle\ \footnotesize{Solution, p. \pageref{#1}}}}
\newcommand{\answercheck}{\hwaddtrailingstuff{\hwcheckmark}}
%
\newcommand{\hwtriangle}{$\triangleright$}
\newcommand{\hwcheckmark}{\scriptsize\raisebox{1mm}{$\surd$}\normalsize}
%
\newcommand{\hwflushtrailingstuff}[1][3]{\ifthenelse{\boolean{hwhavetrailing}}{\hwfill{#1}\usebox{\hwtrailingstuff}\hwcleartrailingstuff}{}}
%
\newcommand{\hwcleartrailingstuff}{\sbox{\hwtrailingstuff}{}\setboolean{hwhavetrailing}{false}}
%
\newcommand{\hwaddtrailingstuff}[1]{\sbox{\hwtrailingstuff}{\usebox{\hwtrailingstuff}\quad{}#1}%
\setboolean{hwhavetrailing}{true}}
%
\newcommand{\hwfill}[1]{\hspace*{\fill}\nolinebreak[#1]\nopagebreak[1]\hspace*{\fill}}
\newcommand{\displayhwdifficulty}[1]{\ifthenelse{\equal{#1}{2}}{$\star$}{}}
%============================= indented blocks ==================================================
\definecolor{shadecolor}{gray}{.9} % for framed.sty
\newlength{\saveleftskip}
\newenvironment{indentedblock}%
{%
\setlength{\saveleftskip}{\leftskip}%
\addtolength{\leftskip}{7mm}%
\noindent\hspace{-1.5mm}% kludge !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}{%
\par \setlength{\leftskip}{\saveleftskip} \par%
}
\newenvironment{important}[1][]%
{\begin{shaded}\ifthenelse{\equal{#1}{}}{}{\textit{#1}\\*}}%
{\end{shaded}}
\newenvironment{lessimportant}[1][]%
{%
\setlength{\saveleftskip}{\leftskip}%
\addtolength{\leftskip}{10mm}%
\noindent\ifthenelse{\equal{#1}{}}{}{\textbf{#1}\\*}%
}{%
\par \setlength{\leftskip}{\saveleftskip} \par%
}
%============================= examples ==================================================
\newcounter{egctr}
\definecolor{egrulegray}{gray}{.6}
\newlength{\egrulehspace}
\setlength{\egrulehspace}{.5mm}
\newlength{\egrulelen}
\setlength{\egrulelen}{53mm}
\newcommand{\egrule}[1]{\makebox[0mm][l]{\color{egrulegray}\rule{#1}{0.5pt}}}
\newcommand{\egvrule}{\makebox[0mm][l]{\color{egrulegray}\rule{0.5pt}{2mm}}}
\newcommand{\egbothrules}[1]{\makebox[0mm][l]{\hspace{-0.5mm}\raisebox{1.5mm}{\egvrule}\raisebox{3.5mm}{\egrule{#1}}}}
\newcommand{\egtit}[2]{\egbothrules{#1}\textit{\hspace{\egrulehspace}#2\hfill{}Example \theegctr}}
\newcommand{\baretit}[1]{\egbothrules{\egrulelen}\textit{\hspace{\egrulehspace}#1}}
\newenvironment{eg}[1][]
{%
\refstepcounter{egctr}%
\small\sffamily
\noindent\egtit{\egrulelen}{#1}\\*\noindent%
\protect\sansmath%
}
{%
\lmserifmath
}
\newcommand{\egquestion}{\noindent\ensuremath{\triangleright}\ }
\newcommand{\eganswer}{\noindent\ensuremath{\triangleright}\ }
%============================= self-checks and hw answers ==================================================
\newcounter{scctr}[chapter]
\newcommand{\whichsc}{}
\newcommand{\hwanssection}[1]{\vspace{4mm}\noindent\formatlikesection{#1}}
\newcommand{\beginsolutions}[1]{\pagebreak[3]\vspace{2mm}\noindent\formatlikesubsection{Solutions for chapter #1}\\*}
\newcommand{\beginscanswers}[1]{\pagebreak[3]\vspace{2mm}\noindent\formatlikesubsection{Answers to self-checks for chapter #1}\\*}
\newcommand{\hwsolnhdr}[1]{\noindent\textbf{page \pageref{hw:#1}, problem \ref{hw:#1}:}\ \label{soln:#1}}
\newcommand{\scanshdr}[1]{\noindent\textbf{page \pageref{sc:#1}, self-check \ref{sc:#1}:}\ \label{scans:#1}}
\newcommand{\scansref}[1]{$\triangleright$\ Answer, p. \pageref{scans:#1}}
\newenvironment{selfcheck}[1]
{%
\refstepcounter{scctr}\label{sc:#1}\renewcommand{\whichsc}{#1}%
\small\sffamily
\noindent\egbothrules{\egrulelen}\textit{\hspace{\egrulehspace}Self-Check\hfill{}}\\*\noindent%
\protect\sansmath%
}
{%
\hfill\scansref{\whichsc}\lmserifmath%
}
%============================= code listings ==================================================
\newcounter{listingline}
\setcounter{listingline}{1}
\newcommand{\formatline}[1]{{\footnotesize #1\ }}
% ii = input line
% nn = numbered input line
% cc = continuation of an input line
% oo = output line
\newcommand{\ii}{\ }
\newcommand{\nn}{\formatline{\arabic{listingline}}\addtocounter{listingline}{1}}
\newcommand{\cc}{\formatline{\ \ \ \ \ \ }}
\newcommand{\oo}[1]{\formatline{\ \ \ \ }\textit{#1}}
\DefineVerbatimEnvironment{Code}{Verbatim}{commandchars=\\\{\},gobble=2}
\newcommand{\restartLineNumbers}{\setcounter{listingline}{1}}
\newcommand{\startcodeeg}{\nolinebreak[4]\vspace{-7mm}\nolinebreak[4]}
\newcommand{\finishcodeeg}{\vspace{-2mm}}
%============================= figures ==================================================
\newcounter{figctr}[chapter] % for my roll-your-own captions
\newcommand{\formatlikecaption}[1]{%
\small{\protect\sansmath\sf{#1}\lmserifmath} %
}
\newcommand{\docaptionnorefstep}[3][l]{%
\break%
\ifthenelse{\equal{#1}{r}}{\hspace*{\fill}}{}
\parbox{#3}{\formatlikecaption{\figurelabel#2}}
}
\newcommand{\docaption}[3]{% alignment, filename, width
\refstepcounter{figctr}%
\docaptionnorefstep[#1]{#2}{#3}%
}
\newcommand{\dofig}[4]{ % placement, filename, caption, width
\noindent{}%
\begin{figure}[#1]%
\hfill\includegraphics[width=#4]{\chapdir/figs/#2}\\
\docaption{r}{#3}{#4} %
\label{fig:#2} %
\end{figure}%
}
\newcommand{\dofigwide}[4]{ % placement, filename, caption, width
\noindent{}%
\begin{figure*}[#1]%
\hfill\includegraphics[width=\textwidth]{\chapdir/figs/#2}\\
\docaption{r}{#3}{\textwidth} %
\label{fig:#2} %
\end{figure*}%
}
\newcommand{\fig}[3][h]{\dofig{#1}{#2}{#3}{\figwidth}}
\newcommand{\widefig}[3][h]{\dofigwide{#1}{#2}{#3}{\figwidth}}
\newcommand{\smallfig}[3][h]{\dofig{#1}{#2}{#3}{\smallfigwidth}}
% Letters for figure number, and no "Figure .." in caption:
\newcommand{\hwcaptions}{\def\figurelabel{}}
\newcommand{\normalcaptions}{\def\figurelabel{\thefigctr\hspace{1mm}{\scriptsize{/}}\hspace{1mm}}}
\normalcaptions
\renewcommand{\thefigctr}{\alphalph{\value{figctr}}}
\newcommand{\figref}[1]{\formatfigref{\ref{fig:#1}}}
\newcommand{\subfigref}[2]{\figref{#1}/#2}
% In DP, we use italics for figref, but in LM that would look too much like an algebra
% symbol, so no italics.
\newcommand{\formatfigref}[1]{#1}
%============================= titlesec stuff ===================================
\definecolor{secnumgray}{gray}{.55}
\newcommand{\showsecnum}[1]{\color{secnumgray}#1}
\titleformat{\chapter}
{\normalfont\Huge\bfseries\sffamily\raggedright}{\thechapter}{5mm}
{\Huge}
\titlespacing{\chapter}{0mm}{0mm}{5mm} % left margin, space before, space after
\titleformat{\section}
{\normalfont\Large\bfseries\sffamily\raggedright}{\showsecnum{\thesection}}{0.6em}{}
\titlespacing{\section}{0mm}{0mm}{0mm} % left margin, space before, space after
\titleformat{\subsection}
{\normalfont\normalsize\bfseries\sffamily\raggedright\protect\sansmath}{\lmserifmath}{0em}{}
\titleformat{\subsubsection}
{\normalfont\normalsize\slshape\raggedright}{\thesubsubsection}{1em}{}
\newcommand{\formatlikesection}[1]{{\Large\bfseries\sffamily\raggedright{}#1}\normalsize}
\newcommand{\formatlikesubsection}[1]{{\bfseries\sffamily\raggedright{}#1}\normalsize}
\newcommand{\printthesection}{Section\ \thesection} % for titlesec, hw environment
%==============================toc==================================
\newcommand{\link}[2]{\jumplink{anchor-#1}{#2}} % navigator package
\newcommand{\brieftocentry}[3][\quad]% #1=\hfill (LM and Me.) or \quad (other books), #2=label, #3=title,
{\link{#2}{\ref{#2}} & \link{#2}{#3} #1 \link{#1}{\pageref{#2}}}
%For the following, see the documentation for tocloft.sty:
%titletoc stuff:
\newcommand{\formatchtoc}[3]{%
\titlecontents{chapter}[0mm]{\addvspace{#3}\sffamily}%
{\contentsmargin{0mm}#1\thecontentslabel\enspace#1}%
{\contentsmargin{0mm}#1}{#2}[]%
}
\contentsmargin{6mm}
\titlecontents{section}[0mm]{\sffamily}
{\contentsmargin{0mm}\thecontentslabel\enspace}
{}{\titlerule*[4mm]{.}\contentspage}
% In the following, titlecontents* is titletoc's way of saying I want subsections listed in a single paragraph.
\titlecontents*{subsection}[1.5em]{\small}{}%
{}{, \thecontentspage}[.---][.]
\titlecontents{subsubsection}[]{}{}{}{}[]
% Brief contents:
\titlecontents{briefchapter}[0mm]{\Large\sffamily{}}
{}{}
{}
%========================= graphicx package=========================
\usepackage{graphicx}
%========================= AtBeginDocument stuff=========================
\AtBeginDocument{
\newboolean{hwhavetrailing}
%------------------------------- pdf stuff
\DeclareGraphicsExtensions{.pdf,.jpg,.png}
\newcommand{\chapdir}{glub}
}
\StopSaveCommands % for learn-cmd-syntax
\WriteSaveCommands % for learn-cmd-syntax