1 % problempack.sty, a package for generating problem/solution sets.
4 % Copyright (C) 2008-2009 W. Trevor King <wking@drexel.edu>
6 % This program is free software; you can redistribute it and/or modify
7 % it under the terms of the GNU General Public License as published by
8 % the Free Software Foundation; either version 2 of the License, or
9 % (at your option) any later version.
11 % This program is distributed in the hope that it will be useful,
12 % but WITHOUT ANY WARRANTY; without even the implied warranty of
13 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 % GNU General Public License for more details.
16 % You should have received a copy of the GNU General Public License along
17 % with this program; if not, write to the Free Software Foundation, Inc.,
18 % 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 % see clsguide.pdf for a LaTeX package tutorial
22 % see xkeyval.pdf for a 72 page spiel on xkeyval
24 \NeedsTeXFormat{LaTeX2e}
25 \ProvidesPackage{problempack}[2008/04/02]
27 \RequirePackage{comment}% show/hide the solution sections
28 \RequirePackage[pdftex]{hyperref} % pdf niceties & active links
29 \RequirePackage{amsmath}% environments for multiline displayed equations, \text{} and other enhancements
31 % get some \theorem environment handling (pick one of ntheorem or amsthm)
32 %\RequirePackage{ntheorem}
33 \RequirePackage{amsthm}
35 % color text (usenames -> with 68 dvips named colors)
36 \RequirePackage[dvipsnames, usenames]{color}
37 \RequirePackage{xkeyval} % handling x=y-type options
39 % non-argument options
40 \DeclareOptionX{nosolutions}{
41 \renewcommand{\Pr@blemSkip}{2\baselineskip}
42 % \bigskip to get a bit of space between problems
43 \excludecomment{solution}
44 %\includecomment{nosolution} % \includecomment clears the environment definition
46 \DeclareOptionX{solutions}{
47 \renewcommand{\Pr@blemSkip}{0pt}
48 %\includecomment{solution} % \includecomment clears the environment definition
49 \excludecomment{nosolution}
51 \DeclareOptionX{tight}{
52 % no indentation or parskips
53 \setlength{\parindent}{0pt}
54 \setlength{\parskip}{0pt}
56 \DeclareOptionX{loose}{
57 % no indentation, reasonable parskips
58 \setlength{\parindent}{0pt}
59 \setlength{\parskip}{0.5\baselineskip}
63 \DeclareOptionX{author}{\renewcommand{\Pr@blemAuthor}{#1}}
64 \DeclareOptionX{coursetitle}{\renewcommand{\Pr@blemCoursetitle}{#1}}
65 \DeclareOptionX{classtitle}{\renewcommand{\Pr@blemClasstitle}{#1}}
66 \DeclareOptionX{subheading}{\renewcommand{\Pr@blemSubheading}{#1}}
67 \DeclareOptionX{problemskip}{\renewcommand{\Pr@blemSkip}{#1}}
69 % argument and unrecognized options (not accessible through \ExecuteOptionsX{})
71 \PackageWarning{problempack}{option `\CurrentOption' ignored}
74 % define theorem environments
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}{%
79 \addtocounter{Pr@blem}{1}% <- temporarily increment Pr@blem
80 \addcontentsline{toc}{section}{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
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 \newcommand{\Pr@blemCounter}{}
93 \newenvironment{problem*}[1]{%
94 \renewcommand{\Pr@blemCounter}{#1}%
96 \addcontentsline{toc}{section}{Problem #1}%
97 \newtheorem*{Pr@blem\Pr@blemCounter}{Problem #1}%
98 \begin{Pr@blem\Pr@blemCounter}%
100 \end{Pr@blem\Pr@blemCounter}%
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,
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
117 % absorb problemskip from problem definition and spit it out after the nosolution region
118 \newenvironment{nosolution}{\vspace{-\Pr@blemSkip}}{\vspace\Pr@blemSkip}
120 \newcommand{\Part}[1]{\textcolor{Red}{(#1)}}
121 \newcommand{\ans}[1]{\textcolor{Red}{#1}}
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}
131 % and process package-user given options
132 \ProcessOptionsX\relax
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
141 % You can safely delete/override of the following code without effecting the
142 % core problem/solution environment behavior.
144 \renewcommand{\maketitle}{%
146 {\Large \Pr@blemClasstitle} \\
151 %% include some useful goodies
152 \RequirePackage[pdftex]{graphicx} % to include images
153 %\DeclareGraphicsRule{*}{mps}{*}{}
154 %\RequirePackage{emp} % embed MetaPost pictures in LaTeX
155 % you need to add \begin{emp*}\end{emp*} by hand, because emp parser
156 % doesn't realize \end{EMP} might expand to \end{emp} or \end{empfile}.
157 %\newenvironment{EMP}[1]%
158 % {\begin{center}\begin{empfile}[problem#1]\begin{emp}(0,0)}%
159 % {\end{emp}\end{empfile}\end{center}}
162 %% define a few physics shortcuts
163 %\newcommand{\U}[1]{\text{ #1}} % units shortcut
164 %\newcommand{\E}[1]{\ensuremath{\cdot 10 ^{#1}}} % exponent shortcut
165 %\newcommand{\dg}{\ensuremath{^{\circ}}} % degree symbol ^o
166 %\newcommand{\vect}[1]{\ensuremath{\mathbf{#1}}} % make vectors bold
167 %\newcommand{\p}[3]{\left#1 #2 \right#3} % parenthesis, e.g. \p({complicated expr})
169 %\newcommand{\ihat}{\vect{\hat{i}}}
170 %\newcommand{\jhat}{\vect{\hat{j}}}
171 %\newcommand{\khat}{\vect{\hat{k}}}
172 %\newcommand{\rhat}{\vect{\hat{r}}}
175 %% finally, set up some simple formatting.
182 \oddsidemargin -0.5in
184 \pagestyle{empty} % no room for page numbers
186 % struts for table spacing
187 %\newcommand{\Tstrut}{\rule{0pt}{2.6ex}}
188 %\newcommand{\Bstrut}{\rule[-1.2ex]{0pt}{0pt}}