About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account

Randomly Selecting Problems Not Used in the Past Two Years

This example requires mth101.dbtex. If you use make, there's also a Makefile. If you don't use make, the file problems.dbtex can be created using:
datatooltk --in mth101.dbtex --merge Label mth101-years.dbtex --shuffle --filter-and --filter Year ne 2012 --filter Year ne 2013 --truncate 5 --output problems.dbtex
This file needs to be created before building the document. The years should be changed as appropriate if the current year is no longer 2014.
\documentclass{article}

\usepackage{etoolbox}
\usepackage{datatool}

\newbool{showanswers}
\booltrue{showanswers}

\DTLloaddbtex{\problemDB}{mth101.dbtex}

\InputIfFileExists{mth101-years.dbtex}
{}% file exists
{\DTLnewdb{mth101-years}}% file doesn't exist

\begin{document}
\begin{center}\bfseries\Large
Assignment~1\ifbool{showanswers}{ (Solution Sheet)}{}
\end{center}

\dtlexpandnewvalue
\begin{enumerate}
\DTLforeach*{\problemDB}
 {\Label=Label,\Question=Question,\Answer=Answer}%
 {%
   \item \Question
   % add this label to the new database:
   \DTLnewrow{mth101-years}% add new row
   \DTLnewdbentry{mth101-years}{Label}{\Label}%
   \DTLnewdbentry{mth101-years}{Year}{\number\year}%
   \ifbool{showanswers}{\par\textbf{Solution: }\Answer}{}%
 }
\end{enumerate}

\DTLsaverawdb{mth101-years}{mth101-years.dbtex}
\end{document}

Download assignmentsheet1.tex or assignmentsheet1.pdf.

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs