LaTeX forum ⇒ Generalprobsoln | Problems without Solutions Topic is solved

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

probsoln | Problems without Solutions

Postby rafapa » Wed Jul 13, 2011 11:30 pm

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

  1. \hideanswers
  2. \loadallproblems[tema01]{tema1.tex}
  3. \begin{enumerate}
  4. \foreachproblem[tema01]{\item\label{\thisproblemlabel}\thisproblem}
  5. end{enumerate}
  6.  
  7. \section*{Soluciones}
  8. \showanswers
  9. \begin{enumerate}
  10. \foreachproblem[tema01]{\item\thisproblem}
  11. \end{enumerate}


Following the FAQ of probsoln I define problems without solutions with:

  1. \begin{defproblem}{inheritance}%
  2. Describe what is meant by the term \emph{inheritance} in
  3. object-oriented programming. Use examples.%
  4. \end{defproblem}


and problems with solutions with:

  1. \begin{defproblem}{t01:02}%
  2. \begin{onlyproblem}%
  3. Velocidad de una molecula%
  4. \end{onlyproblem}%
  5. \begin{onlysolution}%
  6. 0.0791.
  7. \end{onlysolution}%
  8. \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:

  1. \begin{defproblem}{inheritance}%
  2. \begin{onlyproblem}%
  3. Describe what is meant by the term \emph{inheritance} in
  4. object-oriented programming. Use examples.%
  5. \end{onlyproblem}%
  6. \begin{onlysolution}%
  7. \end{onlysolution}%
  8. \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.
Reason: added code markup

Tags:

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

Postby nlct » Tue Aug 23, 2011 4:24 pm

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

Postby rafapa » Wed Aug 31, 2011 6:52 pm

Thanks a lot for the new foreachsolution command.

It almost works.

Please try the following modified sample7.tex

  1. \documentclass{article}
  2.  
  3. \usepackage{tikz}
  4. \usepackage{probsoln}
  5. \usepackage{paralist}
  6.  
  7. \loadallproblems{prob-mixed}
  8.  
  9. \begin{document}
  10. \section{Exercises}
  11. \begin{enumerate}[\bfseries 1.]
  12. \foreachproblem{\item\label{q-\thisproblemlabel} \thisproblem}
  13. \end{enumerate}
  14.  
  15. \section{Solutions}
  16. \showanswers
  17.  
  18. \begin{enumerate}[\bfseries 1.]
  19. \foreachsolution{\item[\ref{q-\thisproblemlabel}] \thisproblem}
  20. \end{enumerate}
  21. \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

  1. \begin{enumerate}
  2. \foreachsolution{\item[{\bfseries \ref{q-\thisproblemlabel}.}] \thisproblem}
  3. \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.
Reason: added code markup

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

Postby nlct » Thu Sep 01, 2011 12:05 pm

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:
  1. \documentclass{article}
  2.  
  3. \usepackage{tikz}
  4. \usepackage{probsoln}
  5. \usepackage{paralist}
  6. \usepackage{refcount}
  7.  
  8. \loadallproblems{prob-mixed}
  9.  
  10. \makeatletter
  11. \newcommand{\setproblemcounter}{%
  12. \setcounterref{\@enumctr}{q-\thisproblemlabel}%
  13. \addtocounter{\@enumctr}{-1}%
  14. }
  15. \makeatother
  16.  
  17. \begin{document}
  18. \section{Exercises}
  19. \begin{enumerate}[\bfseries 1.]
  20. \foreachproblem{\item\label{q-\thisproblemlabel} \thisproblem}
  21. \end{enumerate}
  22.  
  23. \section{Solutions}
  24. \showanswers
  25.  
  26. \begin{enumerate}[\bfseries 1.]
  27. \foreachsolution{\setproblemcounter \item \thisproblem}
  28. \end{enumerate}
  29. \end{document}


Regards
Nicola Talbot

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

Postby rafapa » Sun Sep 04, 2011 5:22 pm

First,
a big thank you.

My version of refcount is:
  1. Package: refcount 2010/12/01 v3.2 Data extraction from references (HO)


After compiling your example the following error appears:

  1. ! Undefined control sequence.
  2. \rc@set ...safe@activestrue\endcsname \rc@refused
  3. {#4}\expandafter \rc@@set ...
  4. l.27 ...ion{\setproblemcounter \item \thisproblem}


Searching in comp.text.tex I have found a workaround suggested by refcount's author.

  1. \makeatletter
  2. \let\rc@refused\refused
  3. \makatother


Thanks again.


Rafael
Last edited by cgnieder on Tue Sep 15, 2015 8:41 pm, edited 1 time in total.
Reason: added code markup


Return to “General”

Who is online

Users browsing this forum: No registered users and 4 guests