summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/probsoln/probsoln.sty
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-03-13 22:35:46 +0000
committerKarl Berry <karl@freefriends.org>2013-03-13 22:35:46 +0000
commit95080bc66f5d1022cbcfbe7535a87055d02aa568 (patch)
tree78110a9731c73d008803b1243437378b52afc905 /Master/texmf-dist/tex/latex/probsoln/probsoln.sty
parent8b6e07d34f4b46b6c6a049934683348b12ff3fd6 (diff)
probsoln (13mar13)
git-svn-id: svn://tug.org/texlive/trunk@29371 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/probsoln/probsoln.sty')
-rw-r--r--Master/texmf-dist/tex/latex/probsoln/probsoln.sty264
1 files changed, 235 insertions, 29 deletions
diff --git a/Master/texmf-dist/tex/latex/probsoln/probsoln.sty b/Master/texmf-dist/tex/latex/probsoln/probsoln.sty
index 8144c5e1c22..86e685a1327 100644
--- a/Master/texmf-dist/tex/latex/probsoln/probsoln.sty
+++ b/Master/texmf-dist/tex/latex/probsoln/probsoln.sty
@@ -7,7 +7,7 @@
%% probsoln.dtx (with options: `probsoln.sty,package')
%%
%% probsoln.dtx
-%% Copyright 2011 Nicola Talbot
+%% Copyright 2013 Nicola Talbot
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
@@ -21,7 +21,7 @@
%%
%% The Current Maintainer of this work is Nicola Talbot.
%%
-%% This work consists of the files probsoln.dtx and probsoln.ins and the derived files probsoln.sty, sample.tex, sample2.tex, sample3.tex, sample4.tex, sample5.tex, sample6.tex, sample7.tex, sample8.tex, prob-1stprncp.tex, prob-args.tex, prob-easy.tex, prob-easy2.tex, prob-implicit.tex, prob-mchoice.tex, prob-mixed.tex, prob-newdata.tex, prob-nosoln.tex, prob-probspaces.tex, prob-probspaces2.tex, prob-tabmchoice.tex, prob-verb.tex.
+%% This work consists of the files probsoln.dtx and probsoln.ins and the derived files probsoln.sty, sample-exclude.tex, sample.tex, sample2.tex, sample3.tex, sample4.tex, sample5.tex, sample6.tex, sample7.tex, sample8.tex, prob-1stprncp.tex, prob-args.tex, prob-easy.tex, prob-easy2.tex, prob-implicit.tex, prob-mchoice.tex, prob-mixed.tex, prob-newdata.tex, prob-nosoln.tex, prob-probspaces.tex, prob-probspaces2.tex, prob-tabmchoice.tex, prob-verb.tex.
%%
%% \CharacterTable
%% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
@@ -47,9 +47,10 @@
%% Display the problems
%% You may need to change \theenumi back here
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{probsoln}[2011/12/10 v3.02 (NLCT)]
+\ProvidesPackage{probsoln}[2012/08/23 v3.04 (NLCT)]
\RequirePackage{ifthen}
\RequirePackage{amsmath}
+\RequirePackage{etoolbox}
\newif\ifshowanswers
\showanswersfalse
\let\showanswers\showanswerstrue
@@ -72,16 +73,195 @@
\newcommand*{\ProbSolnFragileExt}{vrb}
\newcommand*{\ProbSolnFragileFile}{\jobname}
\newwrite\probsoln@write
+\newcount\probsoln@startyear
+\newcommand*{\SetStartYear}[1]{%
+ \probsoln@startyear=#1\relax
+ \renewcommand\SetStartMonth[1]{%
+ \PackageError{probsoln}{\string\SetStartMonth\space
+ can't be used after \string\SetStartYear}{}}%
+}
+\newcommand*{\GetStartYear}{\probsoln@startyear}
+\newcount\probsoln@startmonth
+\newcommand*{\SetStartMonth}[1]{%
+ \probsoln@startmonth=#1\relax
+ \probsoln@startyear=\year\relax
+ \ifnum\month<\probsoln@startmonth
+ \advance\probsoln@startyear by -1\relax
+ \fi
+}
+\SetStartMonth{9}
+\newwrite\probsoln@prev
+\newwrite\probsoln@used
+\newcount\probsoln@prev@cutoff
+\newcommand*{\@probsoln@usedfilename}{\jobname.prb}
+\newcommand*{\SetUsedFileName}[1]{%
+ \renewcommand*{\@probsoln@usedfilename}{#1}%
+}
+\newcommand*{\ClearUsedFile}[1]{%
+ \probsoln@prev@cutoff=0\relax
+ \@probsoln@readprev{#1}%
+ \@for\@this@db:=\prob@databases\do{%
+ {%
+ \edef\@prev@list{\csname probsoln@prev@list@\@this@db\endcsname}%
+ \ifdefempty{\@prev@list}%
+ {}%
+ {%
+ \@for\@this@label:=\@prev@list\do{%
+ \ifcsundef{@used@problem@\@this@db @\@this@label}%
+ {%
+ \immediate\write\probsoln@prev{%
+ \string\previousproblem{\@this@label}{\@this@db}%
+ {\csname @prev@problem@\@this@db @\@this@label\endcsname}}%
+ }%
+ {}%
+ }%
+ }%
+ }%
+ }%
+ \immediate\closeout\probsoln@prev
+ \immediate\closeout\probsoln@used
+ \@disable@exclude@prev
+}
+\newcommand*{\ExcludePreviousFile}[2][3]{%
+ \probsoln@prev@cutoff=\probsoln@startyear\relax
+ \advance\probsoln@prev@cutoff by -#1\relax
+ \@probsoln@readprev{#2}%
+ \@write@prev
+ \def\ExcludePreviousFile[2][3]{\PackageError{probsoln}{Only one
+ instance of \string\ExcludePreviousFile\space allowed}{You've
+ already used this command. You are only allowed to use it once}}%
+ \def\ClearUsedFile[1]{%
+ \PackageError{probsoln}%
+ {\string\ClearUsedFile\space may not be used after
+ \string\ExcludePreviousFile}{}}%
+}
+\newcommand*{\@probsoln@readprev}[1]{%
+ \@enable@exclude@prev
+ \InputIfFileExists{#1}%
+ {\PackageInfo{probsoln}%
+ {Excluded problem file `#1' found}}%
+ {\PackageInfo{probsoln}%
+ {Excluded problem file `#1' not found. A new one will be
+ created}}%
+ \InputIfFileExists{\@probsoln@usedfilename}%
+ {\PackageInfo{probsoln}%
+ {Current problems file `\@probsoln@usedfilename' found}}%
+ {\PackageInfo{probsoln}%
+ {No current problem file `\@probsoln@usedfilename' found. A new one will be created}}%
+ \immediate\openout\probsoln@prev=#1
+ \immediate\openout\probsoln@used=\@probsoln@usedfilename
+}
+\newcommand*{\probsoln@prev@list@default}{}
+\newcommand*{\@write@prev}{%
+ \@for\@this@db:=\prob@databases\do{%
+ {%
+ \edef\@prev@list{\csname probsoln@prev@list@\@this@db\endcsname}%
+ \ifdefempty{\@prev@list}%
+ {}%
+ {%
+ \@for\@this@label:=\@prev@list\do{%
+ \immediate\write\probsoln@prev{%
+ \string\previousproblem{\@this@label}{\@this@db}%
+ {\csname @prev@problem@\@this@db @\@this@label\endcsname}}%
+ }%
+ }%
+ }%
+ }%
+}
+\newcommand*{\@enable@exclude@prev}{%
+ \renewcommand*{\@add@used@problem}[2]{%
+ \immediate\write\probsoln@used{\string\usedproblem{##1}{##2}{\number\probsoln@startyear}}%
+ \ifcsundef{@prev@problem@##2@##1}%
+ {%
+ \immediate\write\probsoln@prev{%
+ \string\previousproblem{##1}{##2}{\number\probsoln@startyear}}%
+ \expandafter\xdef\csname @prev@problem@##2@##1\endcsname{%
+ \number\probsoln@startyear}%
+ }%
+ {%
+ \expandafter\ifnum\csname @prev@problem@##2@##1\endcsname
+ <\probsoln@startyear
+ \immediate\write\probsoln@prev{%
+ \string\previousproblem{##1}{##2}{\number\probsoln@startyear}}%
+ \expandafter\xdef\csname @prev@problem@##2@##1\endcsname{%
+ \number\probsoln@startyear}%
+ \fi
+ }%
+ }%
+ \renewcommand*{\@fetch@excluded@list}[2]{%
+ \def##1{}%
+ \ifcsdef{probsoln@prev@list@##2}%
+ {%
+ \edef\@prev@list{\csname probsoln@prev@list@##2\endcsname}%
+ \@for\@this@label:=\@prev@list\do{%
+ \ifcsundef{@used@problem@##2@\@this@label}%
+ {%
+ \ifcsempty{##1}%
+ {\edef##1{\@this@label}}%
+ {\edef##1{##1,\@this@label}}%
+ }%
+ {}%
+ }%
+ }%
+ {}%
+ }%
+ \renewcommand*{\@add@newprevlist}[1]{%
+ \expandafter\gdef\csname probsoln@prev@list@##1\endcsname{}%
+ }%
+ \renewcommand*{\close@probsoln@prev}{%
+ \closeout\probsoln@prev
+ \closeout\probsoln@used
+ }%
+}
+\newcommand*{\@disable@exclude@prev}{%
+ \renewcommand*{\@add@used@problem}[2]{}%
+ \renewcommand*{\@fetch@excluded@list}[2]{\def##1{}}%
+ \renewcommand*{\@add@newprevlist}[1]{}%
+ \renewcommand*{\close@probsoln@prev}{}%
+}
+\newcommand*{\@add@used@problem}[2]{}
+\newcommand*{\@fetch@excluded@list}[2]{%
+ \def#1{}%
+}
+\newcommand*{\@add@newprevlist}[1]{}
+\newcommand*{\close@probsoln@prev}{}
+\AtEndDocument{\close@probsoln@prev}
+\newcommand*{\previousproblem}[3]{%
+ \ifnum#3>\probsoln@prev@cutoff
+ \ifcsundef{prob@db@#2}{\prob@newdb{#2}}{}%
+ \expandafter\gdef\csname @prev@problem@#2@#1\endcsname{#3}%
+ \edef\@prev@list{\csname probsoln@prev@list@#2\endcsname}%
+ \ifdefempty{\@prev@list}%
+ {%
+ \expandafter\xdef\csname probsoln@prev@list@#2\endcsname{#1}%
+ }%
+ {%
+ \expandafter\xdef\csname probsoln@prev@list@#2\endcsname{%
+ \@prev@list,#1}%
+ }%
+ \fi
+}
+\newcommand*{\usedproblem}[3]{%
+ \ifnum#3=\probsoln@startyear
+ \expandafter\def\csname @used@problem@#2@#1\endcsname{#3}%
+ \fi
+}
\newcommand*{\prob@db@default}{}
\newcommand*{\prob@databases}{default}
\newcommand*{\prob@db@default@solutions}{}
\newcommand*{\prob@newdb}[1]{%
-\@ifundefined{prob@db@#1}{%
- \expandafter\gdef\csname prob@db@#1\endcsname{}%
- \xdef\prob@databases{\prob@databases,#1}%
- \expandafter\gdef\csname prob@db@#1@solutions\endcsname{}%
- }{%
- \PackageError{probsoln}{Data set `#1' is already defined}{}}}
+ \ifcsundef{prob@db@#1}%
+ {%
+ \expandafter\gdef\csname prob@db@#1\endcsname{}%
+ \xdef\prob@databases{\prob@databases,#1}%
+ \expandafter\gdef\csname prob@db@#1@solutions\endcsname{}%
+ \@add@newprevlist{#1}%
+ }%
+ {%
+ \PackageError{probsoln}{Data set `#1' is already defined}%
+ {Data set names must be unique}%
+ }%
+}
\newcommand*{\prob@currentdb}{default}
\newcommand{\moveproblem}[3]{%
\@moveproblem{#1}{#2}{#3}%
@@ -101,12 +281,14 @@
}%
}
\newcommand*{\@moveproblem}[3]{%
- \expandafter\ifx\csname prob@db@#3\endcsname\@empty
+ \ifcsempty{prob@db@#3}%
+ {%
\expandafter\xdef\csname prob@db@#3\endcsname{#1}%
- \else
+ }%
+ {%
\expandafter\xdef\csname prob@db@#3\endcsname{%
\csname prob@db@#3\endcsname,#1}%
- \fi
+ }%
\edef\do@movedata{%
\noexpand\global\noexpand\let\expandafter\noexpand
\csname prob@data@#3@#1\endcsname=%
@@ -402,6 +584,7 @@ Please specify (e.g. \csname @prob@getargs@eg@\romannumeral#1\endcsname):}%
\def\@prob@currentlabel{#2}%
\def\prob@currentdb{#1}%
\prob@showdraftlabel{#1}{#2}%
+ \@add@used@problem{#2}{#1}%
\let\@useprob@next=\relax
\@ifundefined{prob@data@#1@#2}%
{%
@@ -462,7 +645,8 @@ Please specify (e.g. \csname @prob@getargs@eg@\romannumeral#1\endcsname):}%
\newif\iffirstpass
\firstpasstrue
\newcommand{\loadrandomproblems}[3][default]{%
- \@loadrandomproblems{#1}{#2}{#3}{}%
+ \@fetch@excluded@list{\@excl@list}{#1}%
+ \@loadrandomproblems{#1}{#2}{#3}{\@excl@list}%
}
\newcommand{\loadrandomexcept}[4][default]{%
\@loadrandomproblems{#1}{#2}{#3}{#4}%
@@ -478,8 +662,9 @@ Please specify (e.g. \csname @prob@getargs@eg@\romannumeral#1\endcsname):}%
\input{#3}%
\@probselN=0\relax
\@for\@thislabel:=\prob@selectedlabels\do{%
- \expandafter\DTLifinlist\expandafter
- {\@thislabel}{#4}{}%
+ \edef\@if@in@list{\noexpand\DTLifinlist{\@thislabel}{#4}}%
+ \@if@in@list
+ {}%
{%
\advance\@probselN by 1\relax
\expandafter
@@ -487,13 +672,32 @@ Please specify (e.g. \csname @prob@getargs@eg@\romannumeral#1\endcsname):}%
\@thislabel}%
}%
}%
- \shuffle{@prob@tmp@}{\@probselN}%
- \ifnum\@probselN<#2\relax
- \PackageWarning{probsoln}{You have requested
- \number#2\space\space problem(s) but `#3' only contains
- \number\@probselN\space problems. All problems will be selected}%
+ \edef\@do@excludedlist{#4}%
+ \ifdefempty{\@do@excludedlist}%
+ {}%
+ {\def\@do@excludedlist{(Excluded list: #4.) }}%
+ \ifnum\@probselN=0\relax
+ \PackageWarning{probsoln}{You have requested
+ \number#2\space\space problem(s) but there are no available
+ problems in `#3'. \@do@excludedlist No problems will be selected}%
\else
- \@probselN=#2\relax
+ \shuffle{@prob@tmp@}{\@probselN}%
+ \ifnum\@probselN<#2\relax
+ \ifnum\@probselN=1\relax
+ \PackageWarning{probsoln}{You have requested
+ \number#2\space\space problem(s) but there is only
+ 1 problem available in `#3'. \@do@excludedlist
+ Only 1 problem will be selected}%
+ \else
+ \PackageWarning{probsoln}{You have requested
+ \number#2\space\space problem(s) but there are only
+ \number\@probselN\space problems available in `#3'.
+ \@do@excludedlist
+ Only \number\@probselN\space problems will be selected}%
+ \fi
+ \else
+ \@probselN=#2\relax
+ \fi
\fi
\@probN=0\relax
\def\prob@selectedlabels{}%
@@ -652,31 +856,34 @@ Please specify (e.g. \csname @prob@getargs@eg@\romannumeral#1\endcsname):}%
}%
}
\newcount\@ps@forrand
+\newcount\@ps@forrand@level
\newcommand{\doforrandN}[4]{%
+ \global\advance\@ps@forrand@level by 1\relax
{%
\@ps@forrand=0\relax
\@for#2:=#3\do{%
\advance\@ps@forrand by 1\relax
\expandafter
- \edef\csname @doforrandN@\romannumeral\@ps@forrand\endcsname{#2}%
+ \edef\csname @doforrandN@\number\@ps@forrand@level @\romannumeral\@ps@forrand\endcsname{#2}%
}%
\ifnum\@ps@forrand<#1\relax
- \PackageError{probsoln}{Can't randomly select \number#1 item(s)}{You
- have requested \number#1 item(s), but there
- are only \number\@ps@forrand item(s) in the list}%
+ \PackageError{probsoln}{Can't randomly select \number#1\space item(s)}{You
+ have requested \number#1\space item(s), but there
+ are only \number\@ps@forrand\space item(s) in the list: #3}%
\else
- \shuffle{@doforrandN@}{\@ps@forrand}%
+ \shuffle{@doforrandN@\number\@ps@forrand@level @}{\@ps@forrand}%
\ifnum#1>0\relax
\@ps@forrand=0\relax
\loop
\advance\@ps@forrand by 1\relax
- \edef#2{\csname @doforrandN@\romannumeral\@ps@forrand\endcsname}%
+ \edef#2{\csname @doforrandN@\number\@ps@forrand@level @\romannumeral\@ps@forrand\endcsname}%
#4%
\ifnum\@ps@forrand<#1\relax
\repeat
\fi
\fi
}%
+ \global\advance\@ps@forrand@level by -1\relax
}
\newcommand*{\newproblem}{\@ifstar\@snewproblem\@newproblem}
\newcommand{\@snewproblem}[1][0]{%
@@ -718,7 +925,7 @@ Please specify (e.g. \csname @prob@getargs@eg@\romannumeral#1\endcsname):}%
\ifnum\@enumdepth>\thr@@
\@toodeep
\else
- \advance\@enumdepth\@ne\relax
+ \advance\@enumdepth by 1\relax
\edef\@enumctr{enum\romannumeral\the\@enumdepth}%
\let\@item\@textitem
\def\@itemlabel{%
@@ -730,7 +937,6 @@ Please specify (e.g. \csname @prob@getargs@eg@\romannumeral#1\endcsname):}%
\ignorespaces
}%
{%
- \global\advance\@enumdepth\m@ne\relax
}
\def\@textitem[#1]{#1\space\ignorespaces}
\newcommand*{\correctitemformat}[1]{\fbox{#1}}