summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/brandeis-problemset/brandeis-problemset.tex
blob: 8151601a130238b3b71440e86c573805fedd7db3 (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
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
\documentclass{ltxdoc}
\usepackage{brandeis-problemset-doc}
\author{Rebecca Turner\thanks{Brandeis University; \email{rebeccaturner@brandeis.edu}}}
\title{The \bps\ Document Class}
\date{2018-12-20}
\begin{document}
\maketitle
\begin{abstract}

	Brandeis University's computer science (``\textsc{cosi}'') courses
	often assign ``problem sets'' which require fairly rigorous
	formatting. The \bps\ document class, which extends
	\ltxclass{article}, provides a simple way to typeset these problem
	sets in \LaTeX.

	Although \bps\ is compatible with all \LaTeX\ flavors, \fontspecok\
	is recommended for \ctan{fontspec} support.

\end{abstract}

\note{The \bps\ document class should be considered experimental; the only
stable \textsc{api} is that of the \env{problem} environment.}
\note{Browse the sources, contribute, or complain at \\
	\https{github.com/9999years/brandeis-problemset}}

\tableofcontents
\vfill
\pagebreak

\section{Default behavior}

\bps\ provides packages and well-formatted constructs (notably the
\env{problem} environment) for problem-set writers. \bps\ will always render
its body copy as a Times variant (\ctan{stix} for plain \LaTeX\ or
\ctan{xits} with \fontspecok) and always contains a useful header (which
contains the page number, author's name, course, instructor, and assignment
due date).

\subsection{Default packages loaded}

\begin{enumerate}
\item \ctan{hyperref}, for a nicely-linked table of contents;
	\cs{href}|{url}{label}|.
\item \ctan{listings}, for verbatim code listings (including the
	\env{assembly}, \env{java}, and \env{pseudocode} environments).
\item \ctan{xcolor}, for gray line numbers in code listings (and perhaps
	colored listings in the future); e.g.\ \cs{color}|{gray}|.
\item \ctan{enumitem} for better control over the margins and spacing of
	the \env{enumerate}, \env{itemize}, and \env{description}
	environments.
\item Math packages: \begin{enumerate}
	\item \ctan{amsmath} for tons of useful math commands, including
		\cs{text}, \cs{intertext}, and \cs{boxed} as well as the \env{bmatrix},
		\env{multiline}, \env{gather}, \env{align}, and
		\env{alignat} environments. See
		\href{http://texdoc.net/texmf-dist/doc/latex/amsmath/amsldoc.pdf}{``User's
		Guide for the \package{amsmath} Package''} for a more
		complete listing.
	\item \ctan{mathtools} for other useful/utilitarian commands.
\end{enumerate}
\item Table packages: \begin{enumerate}
	\item \ctan{multirow} for cells spanning multiple rows.
	\item \ctan{booktabs} for good-by-default tables and the \cs{cline}
		macro.
	\item \ctan{tabu}, the best table package with dynamically resizable
		columns, easy creation of new column types, and more.
\end{enumerate}
\end{enumerate}

\section{Class configuration}

\subsection{Class options}

Class options are limited to configuration options which require the loading
of fonts or other packages; ``string'' settings like the assignment's due
date are configured either with the \cs{problemsetsetup} command or the
commands described in section~\ref{sss:configcommands}.

\begin{Optionlist}
	gantt &  Load packages for the \env{ganttschedule} environment \\
	scheme & Define the \texttt{scheme} language for the \ctan{listings}
		package as well as the \env{scheme} shorthand environment. \\
	antonella & Use Dr.\ Antonella DiLillio's preferred styles (Courier
		for code) \\
	solutions & Include \env{solution} environments in compiled
		document. \\
\end{Optionlist}

\subsection{Setting options after loading \bps}

\begin{macro}{\problemsetsetup}\marg{options}\AfterLastParam Sets global
\bps\ options; see table~\ref{tab:problemset-options} for a list of valid
options.

\begin{table}[h]
	\centering
	\caption{Options for \cs{problemsetsetup}}
	\label{tab:problemset-options}
	\begin{Optionlist}
	course & Course name in full. \\
	coursenumber & Course name shorthand; use \texttt{21a} for
		``\cosi{21a}''. \\
	assignment & Assignment name in full. \\
	number & Assignment name shorthand; use \texttt{3} for ``Problem Set
		3''. \\
	duedate & Due date, e.g.\ \texttt{2018-10-18}; not parsed at all,
		but
		\href{https://en.wikipedia.org/wiki/ISO_8601}{\textsc{iso}
		8601 dates} are highly recommended. \\
	instructor & Course instructor. \\
	codefont & With \fontspecok, pass the given font to \cs{setmonofont}
		and enable Unicode shortcuts for the \env{pseudocode}
		environment. (If you need to specify options to
		\cs{setmonofont}, use \cs{setcodefont}.) \\
	gantt & Load packages for the \env{ganttschedule} environment \\
	antonella & True/false (default: false; if no value specified,
		assumes true); use Dr.\ Antonella DiLillio's preferred
		styles (Courier for code) \\
	solutions & Include \env{solution} environments in compiled
		document. \\
	\end{Optionlist}
\end{table}
\end{macro}

\subsubsection{Configuration commands}%
\label{sss:configcommands}

\bps\ additionally provides a number of configuration commands for setting a
single opption with similar interfaces as the \TeX\ macros \cs{author},
\cs{title}, and \cs{date}.

\begin{macro}{\duedate}\marg{date} sets the due date in full.\end{macro}
\begin{macro}{\instructor}\marg{name} sets the instructor name.\end{macro}
\begin{macro}{\course}\marg{name} sets the course name in full.\end{macro}
\begin{macro}{\coursenumber}\marg{number} sets the course name by number; e.g.
	|\coursenumber{21a}| gives a course of ``\cosi{21a}''.\end{macro}
\begin{macro}{\assignment}\marg{name} sets the assignment name in full.\end{macro}
\begin{macro}{\problemsetnumber}\marg{number} sets the assignment name by
	number; e.g. |\problemsetnumber{3}| gives an assignment of ``Problem
	Set 3''.\end{macro}

\begin{macro}{\setcodefont}\oarg{fontspec options}\marg{font
name}\AfterLastParam Sets the monospaced font to \meta{font name} and uses
it for shortcuts in the \env{pseudocode} environment.

\end{macro}

\subsection{Practical usage}

You may find it useful to define a customized document class for each
course. There's no reason to install these to some system-wide directory; it
makes sense for them to live in the same directory as the problem set source
files. For instance, \filename{cosi21a.cls} might read:

\begin{latexfile}{cosi21a.cls}
\LoadClass[antonella]{brandeis-problemset}

% set course/author data
\problemsetsetup{
	instructor=Dr.\ Antonella DiLillio,
	coursenumber=21a,
}
\author{Rebecca Turner}

% get a prettier code font -- these can be pretty big so they're not loaded
% by default
\setcodefont[
  Extension = .otf,
  UprightFont = *-Regular,
  BoldFont = *-Bold,
]{FiraMono}
\end{latexfile}

and then \filename{ps1.tex} might read:

\begin{latexfile}{ps1.tex}
\documentclass{cosi21a}
% stuff specific to this assignment
\problemsetnumber{1}
\duedate{2018-10-29}
\begin{document}
% etc.
\end{document}
\end{latexfile}

See section~\ref{sec:example} for a more complete example.

\section{User commands and environments}

\bps\ provides a number of commands for typesetting problems.

\begin{macro}{problem}\oarg{options}\AfterLastParam Defines a problem. A
problem is set 1~inch from the left margin (although this amount may be
customized by modifying the \cs{problemindent} length) and begins a new
page.

\begin{Optionlist}
title & A problem title, to be displayed after ``Problem'' and the problem's
	number.\\
number & A problem number; if given, the problem-number counter
	will not advance. The number must be robust, because it goes inside
	a \cs{section}. \\
pagebreak & True/false (default: true). Add a pagebreak before the problem? \\
label & Adds a custom label to the problem with \cs{label} that can be used
	with \cs{ref} \\
part & Indicates that this problem starts a new ``part'' of the assignment
	\\
partlabel & Adds a custom label to this part; see \option{label} \\
\end{Optionlist}

Vertical material is allowed in a~\env{problem}.
\end{macro}

\begin{macro}{solution}

Defines a solution for a problem; a solution prints in blue and is excluded
from the compiled document entirely unless the \option{solutions} package
option is given.

In this way, the same \texttt{.tex} file can serve as both a postable assignment
prompt and an answer key.

\note{The style of solutions is customizable by redefining
	\cs{solutionstyle}; it's defined to \cs{color}|{blue}| by default.}

\end{macro}

\begin{macro}{\subproblem}\oarg{description}\AfterLastParam Prints a sub-problem, i.e.\ a
\cs{subsection}. It doesn't do very much at the moment.
\end{macro}

\begin{macro}{\Th}\oarg{colspec}\marg{header}\AfterLastParam Prints a table-header in bold.
By default, the header is left-aligned, but arbitrary alignments can be
specified with \meta{colspec}. \cs{Th} is backed by \cs{multicolumn}.
\end{macro}

\begin{macro}{pseudocode}\oarg{keywords}\AfterLastParam Prints
pseudocode.\footnote{Designed for \cosi{21a} as taught by Dr.\ Antonella
DiLillo}

Several ``shortcuts,'' which replace a source-code sequence like
\texttt{->} with a symbol like $\rightarrow$, are shown in
table~\ref{tab:pseudocode}.

These shortcuts display in \cs{pseudocodesymbolfont} (default:
\cs{ttfamily}), which may be redefined if you prefer something else. The
easiest way to change \cs{pseudocodesymbolfont} is with \cs{setcodefont}. If
you use the \option{antonella} option with \fontspecok, \bps\ will load
\ctan{lm-math} and display the symbols seen in table~\ref{tab:pseudocode},
which look significantly better with Courier than \textsc{stix}' symbols.

\begin{table}[h]
	\centering
	\caption{Shortcuts provided by the \env{pseudocode} environment}
	\label{tab:pseudocode}
	\begin{tabular}{>{\ttfamily}lll}
	\Th{Input} & \Th{Display} & \Th{Codepoint} \\
	<-         & ←            & U+2190 \\
	->         & →            & U+2192 \\
	(/)        & $\emptyset$  & U+2205 \\
	inf        & $\infty$     & U+221E \\
	!=         & $\ne$        & U+2260 \\
	>=         & $\ge$        & U+2265 \\
	<=         & $\le$        & U+2264 \\
	\end{tabular}
\end{table}

\todo{Improve the font selection mechanism; maybe provide a command for each
	symbol?}
\note{If your \TeX\ engine doesn't support \textsc{utf}-8 input, the
	shortcuts might appear totally blank or garbled. Good luck! It will surely
	work with \fontspecok.}

\begin{latexcode}
% the optional [Bar] makes [Bar] bold like the other keywords
\begin{pseudocode}[Bar]
Bar(a, n)
    Input:  two integers, a and n
    Output: a^n
    k <- n # k is a counter
    b <- 1
    c <- a
    while k > 0 do
        if k mod 2 = 0 then
            k <- k/2
            c <- c * c
        else
            k <- k - 1
            b <- b * c
    return b
\end{pseudocode}
\end{latexcode}
\end{macro}

\begin{macro}{assembly}\oarg{extra options}\AfterLastParam typesets assembly
code.\footnote{Designed for \cosi{131a} as taught by Dr.\ Liuba Shrira}
Several considerations are taken into account; most notably, line numbers
are printed as \texttt{x + n}, where $n$ starts at 0 and counts by 4; the
line number actually indicates the instruction's location in memory as an
offset from the program start. Additionally, all valid instructions are
treated as keywords and styled appropriately.

Any extra options are passed directly to the \ctan{listings} package.

\begin{latexcode}
\begin{assembly}
        LOAD  R4, $200       ; sum addr
        LOAD  R1, =0         ; sum
        LOAD  R2, =0         ; i
        LOAD  R3, =0         ; j
        BR    OUTER          ; we know i < 10
INNER:  ADD   R1, R3         ; sum += j
        INC   R3             ; j++
OUTER:  BLT   R3, R2, INNER  ; while j < i goto inner
        INC   R2             ; i++
        LOAD  R3, =0         ; j = 0
        BLT   R2, =10, OUTER ; while i < 10
        STORE R1, @R4        ; store sum into sum address
        HALT
\end{assembly}
\end{latexcode}
\end{macro}

\begin{macro}{java}\oarg{extra options}\AfterLastParam Tragically-common
shorthand environment for a listing of Java code.

Any extra options are passed directly to the \ctan{listings} package.
\end{macro}

\begin{macro}{scheme}\oarg{extra options}\AfterLastParam Shorthand
environment for a listing of Scheme code, useful for \cosi{121b}. Requires
the \option{scheme} package option to be loaded.

Any extra options are passed directly to the \ctan{listings} package.
\end{macro}

\begin{macro}{ganttschedule}\marg{total cell count}\oarg{title}\AfterLastParam
An environment for drawing Gantt charts indicating process scheduling. The
mandatory argument indicates how small the grid should be; \texttt{19}
subdivides the line into 19 cells.

To use the \env{ganttschedule} environment, make sure to use the
\option{gantt} package option.

Within a \env{ganttschedule}, use the \cs{burst} command to indicate an
active process (i.e.\ a process burst).

\begin{macro}{\burst}\marg{pid}\marg{burst length}\AfterLastParam
Draw a burst for process \marg{pid} of time length \meta{burst length}.
\end{macro}

\note{These aren't really Gantt charts, but that's what Dr.\ Shrira calls
	them, so that's what they're called here.}
\cprotect\note{Because \env{ganttschedule} relies on \ctan{tikz}, \ctan{fp},
	and \ctan{calc}, it can add significantly to document compile times. If
	you intend to use the \env{ganttschedule} environment, make sure to use
	the \option{gantt} class option or set \option{gantt} in
	\cs{problemsetsetup}. If you fail to include the \option{gantt} option,
	you will see an error message:

\begin{latexcode}
! Package brandeis-problemset Error: ganttschedule enviornment not loaded in preamble.

See the brandeis-problemset package documentation for explanation.
Type  H <return>  for immediate help.
l.4 \burst
          {1}{1}
? H
Did you mean to use the 'gantt' option for the brandeis-problemset document class?

\end{latexcode}
}

\begin{latexcode}
\begin{ganttschedule}{19}
	\burst{2}{1}
	\burst{4}{1}
	\burst{3}{2}
	\burst{5}{5}
	\burst{1}{10}
\end{ganttschedule}
\end{latexcode}
\end{macro}

\subsection{General formatting commands}

\begin{macro}{\ac}\marg{acronym}\AfterLastParam
Typesets an acronym. The \meta{acronym} should be lowercase (e.g.\
\cs{ac}|{cpu}| rather than \cs{ac}|{CPU}|). Currently, \cs{ac} simply
delegates to \cs{textsc}. In the future, I'd like to support a bit of
letterspacing; ``for abbreviations and acronyms in the midst of normal text,
use spaced small caps.''\footnote{\textit{The Elements of Typographic Style} by
Robert Bringhurst, 2nd.\ ed, \S\ 3.2.2}
\end{macro}

\begin{macro}{\Sc}\marg{text}\AfterLastParam
An abbreviation for \cs{textsc}\end{macro}
\begin{macro}{\Rm}\marg{text}\AfterLastParam
An abbreviation for \cs{textrm}\end{macro}
\begin{macro}{\Up}\marg{text}\AfterLastParam
An abbreviation for \cs{textup}\end{macro}
\begin{macro}{\Bf}\marg{text}\AfterLastParam
An abbreviation for \cs{textbf}\end{macro}
\begin{macro}{\It}\marg{text}\AfterLastParam
An abbreviation for \cs{textit}\end{macro}
\begin{macro}{\Tt}\marg{text}\AfterLastParam
An abbreviation for \cs{texttt}\end{macro}

\section{Example}\label{sec:example}

A brief example usage of \bps\ follows. For a longer, more in-depth example,
see
\href{https://github.com/9999years/brandeis-problemset/blob/master/example.tex}{\filename{example.tex}
in the \bps\ repository.}

\begin{latexcode}
\documentclass[gantt]{brandeis-problemset}
\author{Rebecca Turner}
\problemsetsetup{
	coursenumber=21a,
	instructor=Dr.\ Liuba Shrira,
	duedate=2018-10-20,
	number=3,
}
\newcommand{\io}{\ac{io}}
\newcommand{\cpu}{\ac{cpu}}
\begin{document}

\begin{problem}
	Write an assembly program!
\end{problem}

\begin{assembly}
        LOAD  R1, $200      ; A = (program location) + 200
        LOAD  R2, =1        ; i = 1
\end{assembly}

\begin{problem}
	What does this algorithm do? Analyze its worst-case running time and
	express it using big-O notation.

\begin{pseudocode}[Foo]
Foo(a, n)
	Input:  two integers, a and n
	Output: a^n
	k <- 0
	b <- 1
	while k < n do
		k <- k + 1
		b <- b * a
	return b
\end{pseudocode}
\end{problem}

$\Rm{Foo}(a, n)$ computes $a^n$, and will run in $O(n)$ time always.

\begin{problem}[number=5.4]
	Consider the following set of processes, with the length of the
	\cpu\ burst given in milliseconds:

	\begin{center}
		\begin{tabu} to 0.25\linewidth{X[1,$]rr}
			\Th{Process} & \Th{Burst time} & \Th{Priority} \\
			P_1 & 10 & 3 \\
			P_2 & 1 & 1 \\
			P_3 & 2 & 3 \\
			P_4 & 1 & 4 \\
			P_5 & 5 & 2 \\
		\end{tabu}
	\end{center}%$

	Draw a Gantt chart to illustrate the execution of these processes
	using the \ac{sjf} scheduling algorith.
\end{problem}

\begin{ganttschedule}{19}
	\burst{2}{1}
	\burst{4}{1}
	\burst{3}{2}
	\burst{5}{5}
	\burst{1}{10}
\end{ganttschedule}
\end{document}
\end{latexcode}

\begin{changelog}[author=Rebecca Turner]

\begin{version}[v=0.4.0]
\added
	\item \env{solution} environment and \option{solutions} class
		option.
	\item \env{scheme} shorthand environment and \option{scheme} class
		option.
\fixed
	\item Boolean class options being overwritten by keys defined for
		\cs{problemsetsetup}.
	\item Title-formatting errors
\removed
	\item Assignment- and course-specific class options
		\option{duedate}, \option{assignment}, \option{instructor},
		and \option{course}. These settings should be configured
		with either \cs{problemsetsetup} or their specific commands.
		(\cs{duedate}, \cs{instructor}, etc.).
\end{version}

\begin{version}[v=0.3.0, date=2018-10-24]
\added
	\item changelog.
	\item support for \cs{part}s and referencing problems.
	\item options to \env{problem} environment: \option{part},
		\option{label}, and \option{partlabel}.
	\item \cs{maketitle} (contrast with \cs{maketitlepage}).
\end{version}

\begin{version}[v=0.2.0, date=2018-10-20]
\changed
	\item Class renamed to from \ltxclass{problemset} to \bps.
\added
	\item license header.
	\item \env{ganttschedule} environment.
	\item keywords to pseudocode environment: \texttt{and}, \texttt{or},
		\texttt{nil}, and \texttt{len}.
	\item \cs{ac} command for acronyms.
	\item package example.
\end{version}

\shortversion{v=0.1.0, date=2018-10-19,
	changes=Initial beta as \ltxclass{problemset}.}
\end{changelog}

\pagebreak\PrintIndex\listoftables
\end{document}