Latest news 2021-09-06: new blog post "Legacy Documents and TeX Live Docker Images".

Feature Tracker

ID 51🔗
Date: 2021-03-03 17:46:33
Status Open
Category probsoln
Summary Provisions for a default problem

Sign in to subscribe to notifications about this report.

Description

Modification to make \useproblem fallback on a default label if the supplied one isn't defined.
\documentclass{article}

\usepackage{probsoln}
\usepackage{substr}

%% modify probsoln to allow the use of a default problem label
\makeatletter
\newcommand*{\defproblabel}{}
\renewcommand{\useproblem}[2][default]{%
	\def\@prob@currentlabel{#2}%
	\def\prob@currentdb{#1}%
	\prob@showdraftlabel{#1}{#2}%
	\@add@used@problem{#2}{#1}%
	\let\@useprob@next=\relax
	%% undefined label?
	\@ifundefined{prob@data@#1@#2}%
		{%
		%% is a default problem label defined?
		%% if so, use it, otherwise throw an error message
		\@ifundefined{prob@data@#1@\defproblabel}%
			{\PackageError{probsoln}%
			{Problem \defproblabel and Problem ‘#2’ are not defined in data set ‘#1’}{}%
			}%
			{%
			\def\@useprob@next{\csname prob@data@#1@\defproblabel\endcsname}%
			}%
		}%
		{%
		\def\@useprob@next{\csname prob@data@#1@#2\endcsname}%
		}%
	\@useprob@next
	}
\makeatother

%% exercises
\begin{defproblem}{exercises}
\item This is exercise 1 on the topic.
\item This is exercise 2 on the topic.
\end{defproblem}

%% exam questions
\begin{defproblem}{exam-topic1-default}
This is the default question for topic 1 on any exam.
\end{defproblem}
\begin{defproblem}{exam-topic1-A}
This is the question for topic 1 for exam A.
\end{defproblem}
\begin{defproblem}{exam-topic1-B}
This is the question for topic 1 on exam B.
\end{defproblem}

%% document

\begin{document}

Show the exercises for this topic here.

\begin{enumerate}
\foreachproblem{%
	\IfSubStringInString{exercises}{\thisproblemlabel}
		{\thisproblem}
		{\relax}
	}
\end{enumerate}

Show how this topic is tested across four different exams.

\renewcommand*{\defproblabel}{exam-topic1-default}
\begin{enumerate}
\item Exam A \useproblem{exam-topic1-A}
\item Exam B \useproblem{exam-topic1-B}
\item Exam C \useproblem{exam-topic1-C}
\item Exam D \useproblem{exam-topic1-D}
\end{enumerate}

\end{document}
I use a command \newcommand{\theSet}{A} in the preamble. I can substitute \useproblem{exam-topic1-\theSet} to make different versions of the exam. In this way, I need to only make a DEFAULT problem. It will be used automatically regardless of the letter designation for \theSet.

MWE

No mwe.tex

Evaluation

Comments

0 comments.


Add Comment

Name (optional):

Are you human? Please confirm the feature request ID (which can be found at the top of this page) or login if you have an account.

Comment:

You can use the following markup:

Block:

[pre]Displayed verbatim[/pre]
[quote]block quote[/quote]

In line:

[tt]code[/tt]
[file]file/package/class name[/file]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url] [sup]superscript[/sup]
[sub]subscript[/sub]

Ordered list:
[ol]
[li]first item[/li]
[li]second item[/li]
[/ol]

Unordered list:
[ul]
[li]first item[/li]
[li]second item[/li]
[/ul]

You can use the Preview button to review your message formatting before submitting.

Page permalink: https://www.dickimaw-books.com/featuretracker.php?key=51