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