X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=problempack.sty;h=b08fcc729df3a87abc045e380979c342ae5672c1;hb=434dd0d9b3688b06009db0f89cb1e9b6ac058cbb;hp=e7479c23a49ff67499aa93af4a9f06017f3a34ce;hpb=76499f7b75a742ed728db0c49170d7525794811a;p=problempack.git diff --git a/problempack.sty b/problempack.sty index e7479c2..b08fcc7 100644 --- a/problempack.sty +++ b/problempack.sty @@ -1,72 +1,108 @@ % problempack.sty, a package for generating problem/solution sets. % +% Copyright (C) 2008-2010 W. Trevor King +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License along +% with this program; if not, write to the Free Software Foundation, Inc., +% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + % see clsguide.pdf for a LaTeX package tutorial +% see xkeyval.pdf for a 72 page spiel on xkeyval \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{problempack}[2008/04/02] +\ProvidesPackage{problempack}[2010/10/14 0.4 problempack] \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 + +% get some \theorem environment handling (pick one of ntheorem or amsthm) +%\RequirePackage{ntheorem} +\RequirePackage{amsthm} + % color text (usenames -> with 68 dvips named colors) \RequirePackage[dvipsnames, usenames]{color} +\RequirePackage{xkeyval} % handling x=y-type options -% 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}{ +% non-argument options +\DeclareOptionX{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}{ +\DeclareOptionX{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} +\DeclareOptionX{tight}{ + % no indentation or parskips + \setlength{\parindent}{0pt} + \setlength{\parskip}{0pt} +} +\DeclareOptionX{loose}{ + % no indentation, reasonable parskips + \setlength{\parindent}{0pt} + \setlength{\parskip}{0.5\baselineskip} +} + +% argument options +\DeclareOptionX{author}{\renewcommand{\Pr@blemAuthor}{#1}} +\DeclareOptionX{coursetitle}{\renewcommand{\Pr@blemCoursetitle}{#1}} +\DeclareOptionX{classtitle}{\renewcommand{\Pr@blemClasstitle}{#1}} +\DeclareOptionX{subheading}{\renewcommand{\Pr@blemSubheading}{#1}} +\DeclareOptionX{problemskip}{\renewcommand{\Pr@blemSkip}{#1}} + +% argument and unrecognized options (not accessible through \ExecuteOptionsX{}) +\DeclareOptionX*{ + \PackageWarning{problempack}{option `\CurrentOption' ignored} } % define theorem environments +%\newcounter{Pr@blem} +%\newtheorem{Pr@blem}[Pr@blem]{Problem} \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} +\newenvironment{problem}{% + \phantomsection% + \addtocounter{Pr@blem}{1}% <- temporarily increment Pr@blem + \addcontentsline{toc}{subsection}{Problem \arabic{Pr@blem}}% + \addtocounter{Pr@blem}{-1}% <- restore to its initial value + \begin{Pr@blem}% <- the Pr@blem counter actually gets implemented here +}{% + \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} +\newcounter{XPr@blem} +\newenvironment{problem*}[1]{% + \phantomsection% + \addcontentsline{toc}{subsection}{Problem #1}% + \addtocounter{XPr@blem}{1}% <- increment XPr@blem + \expandafter\newtheorem*{XPr@blem\arabic{XPr@blem}}{Problem #1}% + \expandafter\begin{XPr@blem\arabic{XPr@blem}}% +}{% + \expandafter\end{XPr@blem\arabic{XPr@blem}}% + \vspace\Pr@blemSkip% +} -\theoremstyle{definition} +%\theoremstyle{definition} % for amsthm.sty +\theoremstyle{plain} % for ntheorem.sty %\newtheorem*{solution}{} % problem: starts out with a dot. % solution must be defined here before we process the options, % because TODO @@ -84,73 +120,28 @@ \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. +% set defaults +\newcommand{\Pr@blemAuthor}{Trevor King} +\newcommand{\Pr@blemCoursetitle}{Phys 101} +\newcommand{\Pr@blemClasstitle}{Recitation 1} +\newcommand{\Pr@blemSubheading}{Chapter 1} %\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}} +\ExecuteOptionsX{tight} % and process package-user given options -\ProcessOptions\relax +\ProcessOptionsX\relax % finish setting up hyperref -\hypersetup{pdfauthor={\author}} -\hypersetup{pdfsubject={\coursetitle}} -\hypersetup{pdftitle={\classtitle}} +\hypersetup{pdfauthor={\Pr@blemAuthor}} +\hypersetup{pdfsubject={\Pr@blemCoursetitle}} +\hypersetup{pdftitle={\Pr@blemClasstitle}} \hypersetup{pdfstartview=FitH} % zooming to fit the page width. +\hypersetup{colorlinks} % don't do the ugly boxes around links -% You can safely delete/override of the following code without effecting the -% core problem/solution environment behavior. - +% setup a simple title \renewcommand{\maketitle}{% \begin{center} - {\Large Recitation 1} \\ - \subheading + {\Large \Pr@blemClasstitle} \\ + \Pr@blemSubheading \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}}