problempack.sty version 0.0
authorWilliam Trevor King <wking@thor.yang.physics.drexel.edu>
Thu, 6 Aug 2009 13:02:52 +0000 (09:02 -0400)
committerWilliam Trevor King <wking@thor.yang.physics.drexel.edu>
Thu, 6 Aug 2009 13:02:52 +0000 (09:02 -0400)
problempack.sty [new file with mode: 0644]

diff --git a/problempack.sty b/problempack.sty
new file mode 100644 (file)
index 0000000..e7479c2
--- /dev/null
@@ -0,0 +1,156 @@
+% problempack.sty, a package for generating problem/solution sets.
+%
+% see clsguide.pdf for a LaTeX package tutorial
+
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{problempack}[2008/04/02]
+
+\RequirePackage{comment}% show/hide the solution sections
+\RequirePackage[pdftex]{hyperref} % pdf niceties & active links
+\RequirePackage{amsmath}% environments for multiline displayed equations, \text{} and other enhancements
+\RequirePackage{amsthm} % for \theorem environment handling
+% color text (usenames -> with 68 dvips named colors)
+\RequirePackage[dvipsnames, usenames]{color}
+
+% define some option-processing macros
+\def\Pr@blemOptKey#1=#2 {#1}
+\def\Pr@blemOptArg#1=#2 {#2}
+\newcommand{\Pr@blemOptSetup}[1]{%
+  \expandafter\edef \csname\Pr@blemOptKey#1 \endcsname {\Pr@blemOptArg#1 }%
+}
+% some unit tests ;)
+%\typeout{\Pr@blemOptKey abcd=efg = abcd}
+%\typeout{\Pr@blemOptArg abcd=efg = efg}
+%\Pr@blemOptSetup{abcd=efg}
+%\typeout{\abcd = efg}
+%\def\x{ABCD=EFG}
+%\expandafter\Pr@blemOptSetup\expandafter{\x }
+%\typeout{\ABCD = EFG}
+
+% Our current method is limited by:
+%  option name == control sequence, and 
+%  no error messages on goofy option names
+%  \edef not protected like \newcommand, so could silently clobber something
+%   important.
+
+% non-agrument options
+\DeclareOption{nosolutions}{
+  \renewcommand{\Pr@blemSkip}{2\baselineskip}
+  % \bigskip to get a bit of space between problems
+  \excludecomment{solution}
+  %\includecomment{nosolution} % \includecomment clears the environment definition
+}
+\DeclareOption{solutions}{
+  \renewcommand{\Pr@blemSkip}{0pt}
+  %\includecomment{solution} % \includecomment clears the environment definition
+  \excludecomment{nosolution}
+}
+% argument and unrecognized options (not accessible through \ExecuteOptions{})
+\DeclareOption*{
+  \typeout{ping \CurrentOption}  
+  \expandafter\Pr@blemOptSetup\expandafter{\CurrentOption}
+  \typeout{Unrecognized option \CurrentOption}
+}
+
+% define theorem environments
+\newtheorem{Pr@blem}{Problem}
+\newcommand{\Pr@blemSkip}{0pt} % set to 2\baselineskip when nosolutions, to give breathing room between problems
+\newenvironment{problem}{\begin{Pr@blem}}{\end{Pr@blem}\vspace\Pr@blemSkip}
+
+% HACK: you can't nest problem* environments, as there's only one PCC command.
+% not that you should ever need to as far as I can imagine.
+% Note: using a constant theorem name like ProblemSTAR fails on redefine attempt
+% Note: you also get matching errors with \begin{Pr@blem#1}\end{Pr@blem\Pr@blemCounter}
+\newcommand{\Pr@blemCounter}{}
+\newenvironment{problem*}[1]%
+  {\renewcommand{\Pr@blemCounter}{#1}\newtheorem*{Pr@blem\Pr@blemCounter}{Problem #1}\begin{Pr@blem\Pr@blemCounter}}%
+  {\end{Pr@blem\Pr@blemCounter}\vspace\Pr@blemSkip}
+
+\theoremstyle{definition}
+%\newtheorem*{solution}{} % problem: starts out with a dot.
+% solution must be defined here before we process the options,
+% because TODO
+% Also, \excludecomment{}ed environments choke on \next when
+% called from another environment, for example
+%  \newenvironment{invisableSolution}
+%  \excludecomment{invisibleSolution}
+%  \newenvironment{solution}{\begin{invisibleSolution}}{\end{invisibleSolution}}
+%  \begin{solution}  % <--- chokes on \next
+\newenvironment{solution}{}{} % null environment wrapper
+
+% absorb problemskip from problem definition and spit it out after the nosolution region
+\newenvironment{nosolution}{\vspace{-\Pr@blemSkip}}{\vspace\Pr@blemSkip}
+
+\newcommand{\Part}[1]{\textcolor{Red}{(#1)}}
+\newcommand{\ans}[1]{\textcolor{Red}{#1}}
+
+% set defaults ('x,y,z' not 'x, y, z')
+%  problem: for '\ExecuteOptions{wierd}',
+%  the option 'wierd' is not handled by '\DeclareOption*{}', but is '\relax'ed
+%  this means that we have to initialize any x=y-type options by hand.
+%\ExecuteOptions{solutions} % set up for solutions, but don't initialize, b/c \includecomment is touchy
+\Pr@blemOptSetup{author={Trevor King}}
+\Pr@blemOptSetup{coursetitle={Phys 101}}
+\Pr@blemOptSetup{classtitle={Recitation 1}}
+\Pr@blemOptSetup{subheading={Chapter 1}}
+
+% and process package-user given options
+\ProcessOptions\relax
+
+% finish setting up hyperref
+\hypersetup{pdfauthor={\author}}
+\hypersetup{pdfsubject={\coursetitle}}
+\hypersetup{pdftitle={\classtitle}}
+\hypersetup{pdfstartview=FitH} % zooming to fit the page width.
+
+% You can safely delete/override of the following code without effecting the
+% core problem/solution environment behavior.
+
+\renewcommand{\maketitle}{%
+  \begin{center}
+  {\Large Recitation 1} \\
+  \subheading
+  \end{center}
+}
+
+%% include some useful goodies
+\usepackage[pdftex]{graphicx}   % to include images
+\DeclareGraphicsRule{*}{mps}{*}{}
+\usepackage{emp}                % embed MetaPost pictures in LaTeX
+% you need to add \begin{emp*}\end{emp*} by hand, because emp parser
+% doesn't realize \end{EMP} might expand to \end{emp} or \end{empfile}.
+%\newenvironment{EMP}[1]%
+% {\begin{center}\begin{empfile}[problem#1]\begin{emp}(0,0)}%
+% {\end{emp}\end{empfile}\end{center}}
+
+
+%% define a few physics shortcuts
+\newcommand{\U}[1]{\text{ #1}}                 % units shortcut
+\newcommand{\E}[1]{\ensuremath{\cdot 10 ^{#1}}}        % exponent shortcut
+\newcommand{\dg}{\ensuremath{^{\circ}}}         % degree symbol ^o
+\newcommand{\vect}[1]{\ensuremath{\mathbf{#1}}} % make vectors bold
+
+\newcommand{\ihat}{\vect{\hat{i}}}
+\newcommand{\jhat}{\vect{\hat{j}}}
+\newcommand{\khat}{\vect{\hat{k}}}
+\newcommand{\rhat}{\vect{\hat{r}}}
+
+
+%% finally, set up some simple formatting.
+
+% fill the page
+\topmargin -0.5in
+\headheight 0.0in
+\headsep 0.0in
+\textheight 10in
+\oddsidemargin -0.5in
+\textwidth 7.5in
+\pagestyle{empty} % no room for page numbers
+
+% no indentation or parskips
+\setlength{\parindent}{0pt}
+\setlength{\parskip}{0pt}
+
+% struts for table spacing
+\newcommand{\Tstrut}{\rule{0pt}{2.6ex}}
+\newcommand{\Bstrut}{\rule[-1.2ex]{0pt}{0pt}}