Recent news (2017-02-08): Added aliases example to the glossaries-extra.sty gallery.

# probsoln package FAQ

 Search: Category: All datatool datetime datetime2 flowfram flowframtk fmtcount glossaries private-enemy probsoln regular expression Search Tips

This is the FAQ for the probsoln package. See also the package documentation.

## Unexpected Output

### I have lots of blank space before the first problem when using \selectrandomly

This is probably because you have lots of extraneous white space in your database. \selectrandomly will input the entire file, so any extra space will be included. Try commenting out the extra space using %.

As from version 3.0, you can first load the problems using \loadselectedproblems, and then iterate through the data set using \foreachproblem, so you may find it easier to load the problems in the preamble where the space between problem definitions won't matter. (Spaces occurring within problem definitions will still matter.) Then in the document you can iterate through the data set.

Top

## Error Messages

Each label identifier used in defproblem or \newproblem must be unique. Check to make sure you haven't used the same label more than once. Also check to make sure you haven't loaded the same file more than once.

Top

### Label ... undefined

You need to define a problem before you can use it. Check to make sure you haven't mis-spelt it, and check to make sure you have used the file in which it is defined either via \input, \loadallproblems or \loadselectedproblems. If you have used \loadrandomproblems, you shouldn't try referencing a problem since there's a chance it may not have been selected.

Top

### Requested number too large

You have asked for more problems than are defined within the specified file. All problems in that file will be selected.

Top

### Can't randomly select n item(s)

You have asked to randomly select n items from a list that has less than n elements. For example, the following will generate this error:
\doforrandN{10}{\file}{file1,file2,file3}{%

In this case the list, file1,file2,file3 has only 3 elements, but the user has asked for 10 elements. If you type "h" at the LaTeX prompt, it will tell you how many items it thinks there are in the list. Remember that each item must be separated by a comma.

Top

### Lonely \item-perhaps missing list environment

Each problem selected using \selectrandomly is proceeded by \PSNitem which by default is defined as \item, and should therefore be placed in one of the list environments, such as enumerate. Alternatively, redefine \PSNitem.

As from v3.0, you can iterate through a data set using \foreachproblem and which doesn't use \PSNitem as it leaves it up to you to decide how to format the problems in the body of the loop.

Top

### Something's wrong-perhaps a missing \item

This error occurs when you have a list type of environment with out any items. So if the data set is empty (i.e. you haven't defined any problems yet, or you have loaded all the problems into a different data set) then the following code
\begin{enumerate}
\foreachproblem{\item\thisproblem}
\end{enumerate}

will produce this error message (because the body of the loop never gets implemented because there aren't any problems).

Top

### I get an error when I put a command definition in my database when using \selectrandomly

\selectrandomly inputs the database twice, so any command definition will be read twice, causing an error. You can use the switch \iffirstpass to prevent the error. For example:
\iffirstpass
\newcommand{\mycmd}{}
\fi

However it is generally not a good idea to put anything other than problem definitions (\newproblem or defproblem) within the database. Note that if you use \loadallproblems, \loadselectedproblems or \loadrandomproblems, the file will be loaded within a group, so any commands in the file that occur outside of problem definitions will only have a local effect.

Top

### The solution environment is already defined

As from version 2.03, the probsoln package will not define the solution environment if it has already been defined.

Top

### Missing } inserted

Assuming you don't have a missing end group token, this can be caused if you try to put verbatim text inside the body of onlyproblem or onlysolution. See also I get an error when using verbatim text.

Top

### I get an error when using verbatim text

Remember that you can't use verbatim text in command arguments (see Why doesn't verbatim work within...?). You also can't use verbatim text within the environments defproblem, onlysolution or onlyproblem since they have to gather their contents and pass the contents in the argument of a command.

Top

## General Queries

### How do I substitute the word "Solution" for something else?

Redefine \solutionname. For example:
\renewcommand{\solutionname}{La soluci\'on}


Top

### How do I change the way the word "Solution" is formatted?

Redefine the solution environment (as from version 2.01). For example:
\renewenvironmemt{solution}{\par\textsf{\solutionname}}{}


Top

### How do I insert something at the end of each problem?

As from v3.0, you can use \foreachproblem to iterate through each problem in the data set. It's then up to you to decide how to format each problem. For example, if you want each problem to be in a separate item of a numbered list, followed by a horizontal line:
\begin{enumerate}
\foreachproblem{\item\thisproblem\par\hrulefill}
\end{enumerate}


Top

### How do I stop \selectrandomly from using \item?

As from version 3.0, you can first load the randomly selected problems using \loadrandomproblems and then iterate through the data set using \foreachproblem. It's then up to you to format the problems. For example, suppose you want multiple choice style questions formatted in a tabular style environment with the question in the first column and possible answers in the subsequent columns. Then you could define the problems in the following style:
\begin{defproblem}{sample}%
What is $2+3$? & 1 & 5 & 10 & 42
\end{defproblem}

Then load the problems (say you want to randomly select 10 problems from myproblems.tex):
\loadrandomproblems{10}{myproblems}

Now display the problems:
\begin{tabular}{lllll}
\bfseries Question & \bfseries A & \bfseries B & \bfseries C &
\bfseries D\\
\foreachproblem{\thisproblem\\}%
\end{tabular}

(If the table is likely to be longer than a page, then use longtable or supertabular instead of tabular.)

Top

### How do I align my problems in a table instead of a list?

See How do I stop \selectrandomly from using \item?.

Top

### How do I determine whether or not the answers are being displayed?

Use the boolean variable showanswers. For example:
Problem Sheet 1\ifthenelse{\boolean{showanswers}}{ (Solutions)}{}

As from version 3.0, you can also use the environments onlyproblem and onlysolution.

Top

### How can I define a problem without a solution (e.g. an essay style question)?

As from version 3.0, you can just use the defproblem environment. For example:
\begin{defproblem}{inheritance}%
Describe what is meant by the term \emph{inheritance} in
object-oriented programming. Use examples.%
\end{defproblem}

Or, as from version 2.03, you can use \newproblem*. For example:
\newproblem*{inheritance}{Describe what is meant by the term
\emph{inheritance} in object-oriented programming. Use examples.}


Top

### How do I select all problems from a database in the order in which they were defined?

As from version 3.0, you can load all problems in a file using \loadallproblems and then iterate through the data set using \foreachproblem. Or, as from version 2.02, you can use the command \selectallproblems. For example, if your problems are defined in the file probs.tex:
\begin{enumerate}
\selectallproblems{probs}
\end{enumerate}

As with \selectrandomly, \selectallproblems uses \PSNitem at the start of each problem.