1 % problempack.sty, a package for generating problem/solution sets.
3 % Copyright (C) 2008-2010 W. Trevor King <wking@drexel.edu>
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.
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.
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.
19 % see clsguide.pdf for a LaTeX package tutorial
20 % see xkeyval.pdf for a 72 page spiel on xkeyval
22 \NeedsTeXFormat{LaTeX2e}
23 \ProvidesPackage{problempack}[2010/10/14 0.4 problempack]
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
29 % get some \theorem environment handling (pick one of ntheorem or amsthm)
30 %\RequirePackage{ntheorem}
31 \RequirePackage{amsthm}
33 % color text (usenames -> with 68 dvips named colors)
34 \RequirePackage[dvipsnames, usenames]{color}
35 \RequirePackage{xkeyval} % handling x=y-type options
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
44 \DeclareOptionX{solutions}{
45 \renewcommand{\Pr@blemSkip}{0pt}
46 %\includecomment{solution} % \includecomment clears the environment definition
47 \excludecomment{nosolution}
49 \DeclareOptionX{tight}{
50 % no indentation or parskips
51 \setlength{\parindent}{0pt}
52 \setlength{\parskip}{0pt}
54 \DeclareOptionX{loose}{
55 % no indentation, reasonable parskips
56 \setlength{\parindent}{0pt}
57 \setlength{\parskip}{0.5\baselineskip}
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}}
67 % argument and unrecognized options (not accessible through \ExecuteOptionsX{})
69 \PackageWarning{problempack}{option `\CurrentOption' ignored}
72 % define theorem environments
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}{%
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
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}
93 \newenvironment{problem*}[1]{%
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}}%
100 \expandafter\end{XPr@blem\arabic{XPr@blem}}%
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 % setup a simple title
142 \renewcommand{\maketitle}{%
144 {\Large \Pr@blemClasstitle} \\