Added my personal commands and formatting.
[problempack.git] / problempack.sty
1 % problempack.sty, a package for generating problem/solution sets.
2 % Version 0.3
3 %
4 % see clsguide.pdf for a LaTeX package tutorial
5 % see xkeyval.pdf for a 72 page spiel on xkeyval
6
7 \NeedsTeXFormat{LaTeX2e}
8 \ProvidesPackage{problempack}[2008/04/02]
9
10 \RequirePackage{comment}% show/hide the solution sections
11 \RequirePackage[pdftex]{hyperref} % pdf niceties & active links
12 \RequirePackage{amsmath}% environments for multiline displayed equations, \text{} and other enhancements
13
14 % get some \theorem environment handling (pick one of ntheorem or amsthm)
15 %\RequirePackage{ntheorem}
16 \RequirePackage{amsthm}
17
18 % color text (usenames -> with 68 dvips named colors)
19 \RequirePackage[dvipsnames, usenames]{color}
20 \RequirePackage{xkeyval} % handling x=y-type options
21
22 % non-argument options
23 \DeclareOptionX{nosolutions}{
24   \renewcommand{\Pr@blemSkip}{2\baselineskip}
25   % \bigskip to get a bit of space between problems
26   \excludecomment{solution}
27   %\includecomment{nosolution} % \includecomment clears the environment definition
28 }
29 \DeclareOptionX{solutions}{
30   \renewcommand{\Pr@blemSkip}{0pt}
31   %\includecomment{solution} % \includecomment clears the environment definition
32   \excludecomment{nosolution}
33 }
34 \DeclareOptionX{tight}{
35   % no indentation or parskips
36   \setlength{\parindent}{0pt}
37   \setlength{\parskip}{0pt}
38 }
39 \DeclareOptionX{loose}{
40   % no indentation, reasonable parskips
41   \setlength{\parindent}{0pt}
42   \setlength{\parskip}{0.5\baselineskip}
43 }
44
45 % argument options
46 \DeclareOptionX{author}{\renewcommand{\Pr@blemAuthor}{#1}}
47 \DeclareOptionX{coursetitle}{\renewcommand{\Pr@blemCoursetitle}{#1}}
48 \DeclareOptionX{classtitle}{\renewcommand{\Pr@blemClasstitle}{#1}}
49 \DeclareOptionX{subheading}{\renewcommand{\Pr@blemSubheading}{#1}}
50 \DeclareOptionX{problemskip}{\renewcommand{\Pr@blemSkip}{#1}}
51
52 % argument and unrecognized options (not accessible through \ExecuteOptionsX{})
53 \DeclareOptionX*{
54   \PackageWarning{problempack}{option `\CurrentOption' ignored}
55 }
56
57 % define theorem environments
58 \newtheorem{Pr@blem}{Problem}
59 \newcommand{\Pr@blemSkip}{0pt} % set to 2\baselineskip when nosolutions, to give breathing room between problems
60 \newenvironment{problem}{%
61   \phantomsection%
62   \addtocounter{Pr@blem}{1}% <- temporarily increment Pr@blem
63   \addcontentsline{toc}{section}{Problem \arabic{Pr@blem}}%
64   \addtocounter{Pr@blem}{-1}% <- restore to its initial value
65   \begin{Pr@blem}% <- the Pr@blem counter actually gets implemented here
66 }{%
67   \end{Pr@blem}%
68   \vspace\Pr@blemSkip%
69 }
70
71 % HACK: you can't nest problem* environments, as there's only one PCC command.
72 % not that you should ever need to as far as I can imagine.
73 % Note: using a constant theorem name like ProblemSTAR fails on redefine attempt
74 % Note: you also get matching errors with \begin{Pr@blem#1}\end{Pr@blem\Pr@blemCounter}
75 \newcommand{\Pr@blemCounter}{}
76 \newenvironment{problem*}[1]{%
77   \renewcommand{\Pr@blemCounter}{#1}%
78   \phantomsection%
79   \addcontentsline{toc}{section}{Problem #1}%
80   \newtheorem*{Pr@blem\Pr@blemCounter}{Problem #1}%
81   \begin{Pr@blem\Pr@blemCounter}%
82 }{%
83   \end{Pr@blem\Pr@blemCounter}%
84   \vspace\Pr@blemSkip%
85 }
86
87 %\theoremstyle{definition} % for amsthm.sty
88 \theoremstyle{plain} % for ntheorem.sty
89 %\newtheorem*{solution}{} % problem: starts out with a dot.
90 % solution must be defined here before we process the options,
91 % because TODO
92 % Also, \excludecomment{}ed environments choke on \next when
93 % called from another environment, for example
94 %  \newenvironment{invisableSolution}
95 %  \excludecomment{invisibleSolution}
96 %  \newenvironment{solution}{\begin{invisibleSolution}}{\end{invisibleSolution}}
97 %  \begin{solution}  % <--- chokes on \next
98 \newenvironment{solution}{}{} % null environment wrapper
99
100 % absorb problemskip from problem definition and spit it out after the nosolution region
101 \newenvironment{nosolution}{\vspace{-\Pr@blemSkip}}{\vspace\Pr@blemSkip}
102
103 \newcommand{\Part}[1]{\textcolor{Red}{(#1)}}
104 \newcommand{\ans}[1]{\textcolor{Red}{#1}}
105
106 % set defaults
107 \newcommand{\Pr@blemAuthor}{Trevor King}
108 \newcommand{\Pr@blemCoursetitle}{Phys 101}
109 \newcommand{\Pr@blemClasstitle}{Recitation 1}
110 \newcommand{\Pr@blemSubheading}{Chapter 1}
111 %\ExecuteOptions{solutions} % set up for solutions, but don't initialize, b/c \includecomment is touchy
112 \ExecuteOptionsX{tight}
113
114 % and process package-user given options
115 \ProcessOptionsX\relax
116
117 % finish setting up hyperref
118 \hypersetup{pdfauthor={\Pr@blemAuthor}}
119 \hypersetup{pdfsubject={\Pr@blemCoursetitle}}
120 \hypersetup{pdftitle={\Pr@blemClasstitle}}
121 \hypersetup{pdfstartview=FitH} % zooming to fit the page width.
122 \hypersetup{colorlinks} % don't do the ugly boxes around links
123
124 % You can safely delete/override of the following code without effecting the
125 % core problem/solution environment behavior.
126
127 \renewcommand{\maketitle}{%
128   \begin{center}
129   {\Large \Pr@blemClasstitle} \\
130   \Pr@blemSubheading
131   \end{center}
132 }
133
134 %% include some useful goodies
135 \RequirePackage[pdftex]{graphicx}   % to include images
136 %\DeclareGraphicsRule{*}{mps}{*}{}
137 %\RequirePackage{emp}                % embed MetaPost pictures in LaTeX
138 % you need to add \begin{emp*}\end{emp*} by hand, because emp parser
139 % doesn't realize \end{EMP} might expand to \end{emp} or \end{empfile}.
140 %\newenvironment{EMP}[1]%
141 % {\begin{center}\begin{empfile}[problem#1]\begin{emp}(0,0)}%
142 % {\end{emp}\end{empfile}\end{center}}
143
144
145 %% define a few physics shortcuts
146 %\newcommand{\U}[1]{\text{ #1}}                 % units shortcut
147 %\newcommand{\E}[1]{\ensuremath{\cdot 10 ^{#1}}}        % exponent shortcut
148 %\newcommand{\dg}{\ensuremath{^{\circ}}}         % degree symbol ^o
149 %\newcommand{\vect}[1]{\ensuremath{\mathbf{#1}}} % make vectors bold
150 %\newcommand{\p}[3]{\left#1 #2 \right#3}   % parenthesis, e.g. \p({complicated expr})
151 %
152 %\newcommand{\ihat}{\vect{\hat{i}}}
153 %\newcommand{\jhat}{\vect{\hat{j}}}
154 %\newcommand{\khat}{\vect{\hat{k}}}
155 %\newcommand{\rhat}{\vect{\hat{r}}}
156
157
158 %% finally, set up some simple formatting.
159
160 % fill the page
161 \topmargin -0.5in
162 \headheight 0.0in
163 \headsep 0.0in
164 \textheight 10in
165 \oddsidemargin -0.5in
166 \textwidth 7.5in
167 \pagestyle{empty} % no room for page numbers
168
169 % struts for table spacing
170 %\newcommand{\Tstrut}{\rule{0pt}{2.6ex}}
171 %\newcommand{\Bstrut}{\rule[-1.2ex]{0pt}{0pt}}