Generalprobsoln | Problems without Solutions

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
rafapa
Posts: 4
Joined: Wed Jul 13, 2011 11:05 pm

probsoln | Problems without Solutions

Post by rafapa »

I'm trying to use Nicola Talbot's probsoln package. I have problems with solutions included but I also have problems without solution. I am using

Code: Select all

\hideanswers
\loadallproblems[tema01]{tema1.tex}
\begin{enumerate}
\foreachproblem[tema01]{\item\label{\thisproblemlabel}\thisproblem}
end{enumerate}

\section*{Soluciones}
\showanswers
\begin{enumerate}
\foreachproblem[tema01]{\item\thisproblem}
\end{enumerate}
Following the FAQ of probsoln I define problems without solutions with:

Code: Select all

\begin{defproblem}{inheritance}%
Describe what is meant by the term \emph{inheritance} in
object-oriented programming. Use examples.%
\end{defproblem}
and problems with solutions with:

Code: Select all

\begin{defproblem}{t01:02}%
\begin{onlyproblem}%
 Velocidad de una molecula%
\end{onlyproblem}%
\begin{onlysolution}%
0.0791.
\end{onlysolution}%
\end{defproblem}
The problem with this setup is that in the solution part the enunciate of the problem is displayed. I would like something like:

Problems:

1. text 1
2. text 2
3. text 3
4. text 4

Solutions:

1. solution 1
2. solution 2
4. solution 4

Where the problem number three has no solution.
I mean, if the solution is empty no number should be printed. I have tried defining:

Code: Select all

\begin{defproblem}{inheritance}%
\begin{onlyproblem}%
Describe what is meant by the term \emph{inheritance} in
object-oriented programming. Use examples.%
\end{onlyproblem}%
\begin{onlysolution}%
\end{onlysolution}%
\end{defproblem}
In this way I get

Solutions:

1. solution 1
2. solution 2
3.
4. solution 4

Is there a way to avoid the display of the item with no solution?

Thanks in advance for the attention
Last edited by cgnieder on Tue Sep 15, 2015 8:40 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

probsoln | Problems without Solutions

Post by nlct »

The new version (3.01) now has a command called \foreachsolution that works like \foreachproblem but only iterates through problems that contain the onlysolution environment.

Regards
Nicola Talbot
rafapa
Posts: 4
Joined: Wed Jul 13, 2011 11:05 pm

probsoln | Problems without Solutions

Post by rafapa »

Thanks a lot for the new foreachsolution command.

It almost works.

Please try the following modified sample7.tex

Code: Select all

\documentclass{article}

\usepackage{tikz}
\usepackage{probsoln}
\usepackage{paralist}

\loadallproblems{prob-mixed}

\begin{document}
\section{Exercises}
\begin{enumerate}[\bfseries 1.]
  \foreachproblem{\item\label{q-\thisproblemlabel} \thisproblem}
\end{enumerate}

\section{Solutions}
\showanswers

\begin{enumerate}[\bfseries 1.]
  \foreachsolution{\item[\ref{q-\thisproblemlabel}] \thisproblem}
\end{enumerate}
\end{document}
I have added the package paralist in order to use the [\bfseries 1.] option to the enumerate environment. The problem is that the foreachproblem part use the option but the foreachsolution does not.
If I change to

Code: Select all

\begin{enumerate}
  \foreachsolution{\item[{\bfseries \ref{q-\thisproblemlabel}.}] \thisproblem}
\end{enumerate}
It seems to work ok.

Anyway I thank you again.
Last edited by cgnieder on Tue Sep 15, 2015 8:41 pm, edited 1 time in total.
User avatar
nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

probsoln | Problems without Solutions

Post by nlct »

In \foreachsolution you've used the optional argument of \item which overrides the format set at the start of the environment. An alternative is to set the counter before \item so that you don't need the optional argument. You can use the refcount package:

Code: Select all

\documentclass{article}

\usepackage{tikz}
\usepackage{probsoln}
\usepackage{paralist}
\usepackage{refcount}

\loadallproblems{prob-mixed}

\makeatletter
\newcommand{\setproblemcounter}{%
  \setcounterref{\@enumctr}{q-\thisproblemlabel}%
  \addtocounter{\@enumctr}{-1}%
}
\makeatother

\begin{document}
\section{Exercises}
\begin{enumerate}[\bfseries 1.]
\foreachproblem{\item\label{q-\thisproblemlabel} \thisproblem}
\end{enumerate}

\section{Solutions}
\showanswers

\begin{enumerate}[\bfseries 1.]
\foreachsolution{\setproblemcounter \item \thisproblem}
\end{enumerate}
\end{document}
Regards
Nicola Talbot
rafapa
Posts: 4
Joined: Wed Jul 13, 2011 11:05 pm

probsoln | Problems without Solutions

Post by rafapa »

First,
a big thank you.

My version of refcount is:

Code: Select all

Package: refcount 2010/12/01 v3.2 Data extraction from references (HO)
After compiling your example the following error appears:

Code: Select all

! Undefined control sequence.
\rc@set ...safe@activestrue\endcsname \rc@refused 
                                                  {#4}\expandafter \rc@@set ...
l.27 ...ion{\setproblemcounter \item \thisproblem}
Searching in comp.text.tex I have found a workaround suggested by refcount's author.

Code: Select all

\makeatletter
\let\rc@refused\refused
\makatother 
Thanks again.


Rafael
Last edited by cgnieder on Tue Sep 15, 2015 8:41 pm, edited 1 time in total.
Post Reply