Rename \U to \unit in wtk_cmmds.sty.
[problempack.git] / problempack.sty
1 % problempack.sty, a package for generating problem/solution sets.
2 %
3 % Copyright (C) 2008-2010 W. Trevor King <wking@tremily.us>
4 %
5 % This program is free software; you can redistribute it and/or modify
6 % it under the terms of the GNU General Public License as published by
7 % the Free Software Foundation; either version 2 of the License, or
8 % (at your option) any later version.
9 %
10 % This program is distributed in the hope that it will be useful,
11 % but WITHOUT ANY WARRANTY; without even the implied warranty of
12 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 % GNU General Public License for more details.
14 %
15 % You should have received a copy of the GNU General Public License along
16 % with this program; if not, write to the Free Software Foundation, Inc.,
17 % 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 % see clsguide.pdf for a LaTeX package tutorial
20 % see xkeyval.pdf for a 72 page spiel on xkeyval
21
22 \NeedsTeXFormat{LaTeX2e}
23 \ProvidesPackage{problempack}[2010/10/14 0.4 problempack]
24
25 \RequirePackage{comment}% show/hide the solution sections
26 \RequirePackage[pdftex]{hyperref} % pdf niceties & active links
27 \RequirePackage{amsmath}% environments for multiline displayed equations, \text{} and other enhancements
28
29 % get some \theorem environment handling (pick one of ntheorem or amsthm)
30 %\RequirePackage{ntheorem}
31 \RequirePackage{amsthm}
32
33 % color text (usenames -> with 68 dvips named colors)
34 \RequirePackage[dvipsnames, usenames]{color}
35 \RequirePackage{xkeyval} % handling x=y-type options
36
37 % non-argument options
38 \DeclareOptionX{nosolutions}{
39   \renewcommand{\Pr@blemSkip}{2\baselineskip}
40   % \bigskip to get a bit of space between problems
41   \excludecomment{solution}
42   %\includecomment{nosolution} % \includecomment clears the environment definition
43 }
44 \DeclareOptionX{solutions}{
45   \renewcommand{\Pr@blemSkip}{0pt}
46   %\includecomment{solution} % \includecomment clears the environment definition
47   \excludecomment{nosolution}
48 }
49 \DeclareOptionX{tight}{
50   % no indentation or parskips
51   \setlength{\parindent}{0pt}
52   \setlength{\parskip}{0pt}
53 }
54 \DeclareOptionX{loose}{
55   % no indentation, reasonable parskips
56   \setlength{\parindent}{0pt}
57   \setlength{\parskip}{0.5\baselineskip}
58 }
59
60 % argument options
61 \DeclareOptionX{author}{\renewcommand{\Pr@blemAuthor}{#1}}
62 \DeclareOptionX{coursetitle}{\renewcommand{\Pr@blemCoursetitle}{#1}}
63 \DeclareOptionX{classtitle}{\renewcommand{\Pr@blemClasstitle}{#1}}
64 \DeclareOptionX{subheading}{\renewcommand{\Pr@blemSubheading}{#1}}
65 \DeclareOptionX{problemskip}{\renewcommand{\Pr@blemSkip}{#1}}
66
67 % argument and unrecognized options (not accessible through \ExecuteOptionsX{})
68 \DeclareOptionX*{
69   \PackageWarning{problempack}{option `\CurrentOption' ignored}
70 }
71
72 % define theorem environments
73 %\newcounter{Pr@blem}
74 %\newtheorem{Pr@blem}[Pr@blem]{Problem}
75 \newtheorem{Pr@blem}{Problem}
76 \newcommand{\Pr@blemSkip}{0pt} % set to 2\baselineskip when nosolutions, to give breathing room between problems
77 \newenvironment{problem}{%
78   \phantomsection%
79   \addtocounter{Pr@blem}{1}% <- temporarily increment Pr@blem
80   \addcontentsline{toc}{subsection}{Problem \arabic{Pr@blem}}%
81   \addtocounter{Pr@blem}{-1}% <- restore to its initial value
82   \begin{Pr@blem}% <- the Pr@blem counter actually gets implemented here
83 }{%
84   \end{Pr@blem}%
85   \vspace\Pr@blemSkip%
86 }
87
88 % HACK: you can't nest problem* environments, as there's only one PCC command.
89 % not that you should ever need to as far as I can imagine.
90 % Note: using a constant theorem name like ProblemSTAR fails on redefine attempt
91 % Note: you also get matching errors with \begin{Pr@blem#1}\end{Pr@blem\Pr@blemCounter}
92 \newcounter{XPr@blem}
93 \newenvironment{problem*}[1]{%
94   \phantomsection%
95   \addcontentsline{toc}{subsection}{Problem #1}%
96   \addtocounter{XPr@blem}{1}% <- increment XPr@blem  
97   \expandafter\newtheorem*{XPr@blem\arabic{XPr@blem}}{Problem #1}%
98   \expandafter\begin{XPr@blem\arabic{XPr@blem}}%
99 }{%
100   \expandafter\end{XPr@blem\arabic{XPr@blem}}%
101   \vspace\Pr@blemSkip%
102 }
103
104 %\theoremstyle{definition} % for amsthm.sty
105 \theoremstyle{plain} % for ntheorem.sty
106 %\newtheorem*{solution}{} % problem: starts out with a dot.
107 % solution must be defined here before we process the options,
108 % because TODO
109 % Also, \excludecomment{}ed environments choke on \next when
110 % called from another environment, for example
111 %  \newenvironment{invisableSolution}
112 %  \excludecomment{invisibleSolution}
113 %  \newenvironment{solution}{\begin{invisibleSolution}}{\end{invisibleSolution}}
114 %  \begin{solution}  % <--- chokes on \next
115 \newenvironment{solution}{}{} % null environment wrapper
116
117 % absorb problemskip from problem definition and spit it out after the nosolution region
118 \newenvironment{nosolution}{\vspace{-\Pr@blemSkip}}{\vspace\Pr@blemSkip}
119
120 \newcommand{\Part}[1]{\textcolor{Red}{(#1)}}
121 \newcommand{\ans}[1]{\textcolor{Red}{#1}}
122
123 % set defaults
124 \newcommand{\Pr@blemAuthor}{Trevor King}
125 \newcommand{\Pr@blemCoursetitle}{Phys 101}
126 \newcommand{\Pr@blemClasstitle}{Recitation 1}
127 \newcommand{\Pr@blemSubheading}{Chapter 1}
128 %\ExecuteOptions{solutions} % set up for solutions, but don't initialize, b/c \includecomment is touchy
129 \ExecuteOptionsX{tight}
130
131 % and process package-user given options
132 \ProcessOptionsX\relax
133
134 % finish setting up hyperref
135 \hypersetup{pdfauthor={\Pr@blemAuthor}}
136 \hypersetup{pdfsubject={\Pr@blemCoursetitle}}
137 \hypersetup{pdftitle={\Pr@blemClasstitle}}
138 \hypersetup{pdfstartview=FitH} % zooming to fit the page width.
139 \hypersetup{colorlinks} % don't do the ugly boxes around links
140
141 % setup a simple title
142 \renewcommand{\maketitle}{%
143   \begin{center}
144   {\Large \Pr@blemClasstitle} \\
145   \Pr@blemSubheading
146   \end{center}
147 }