Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show number of used exercises #79

Open
thorstengrothe opened this issue Oct 1, 2018 · 5 comments
Open

Show number of used exercises #79

thorstengrothe opened this issue Oct 1, 2018 · 5 comments
Labels
resolved Questions solved not by commits, but by a good answer or workaround.

Comments

@thorstengrothe
Copy link

Is there a command showing the number of used exercises in a \buildset?

@Strauman
Copy link
Owner

Strauman commented Oct 2, 2018

Not builtin, but can be made with the following

\documentclass{article}
\usepackage{exercisebank}
% ... preamble stuff
\newcounter{numexercises}
% Use a hook. There are many of them and they are documented
% This would trigger once per problem in a file
% For a partproblem, you'd do e.g. \At\BeginPartproblem{}
\At\BeginProblem{\global\stepcounter{numexercises}}
\begin{document}
    \buildsets{list,of,sets}
    \thenumexercises %<- Contains the number of exercises.
\end{document}

If you'd need to use this inside the exercises or before the \buildsets is run, you can
make a command to "remember" the count over several runs. That is you could do

\documentclass{article}
\usepackage{exercisebank}
% Commands to "remember" the count for multiple runs
\makeatletter
\gdef\later#1{
  \providecommand#1{}
}
\gdef\setforlater#1#2{
    \immediate\write\@auxout{\string\gdef\string#1{#2}}%
}
\makeatother
% define a "remembering" \exercisecount
\later\exercisecount
%... preamble stuff
\newcounter{numexercises}
% Use a hook. There are many of them and they are documented
% This would trigger once per problem in a file
% For a partproblem, you'd do e.g. \At\BeginPartproblem{}
\At\BeginProblem{\global\stepcounter{numexercises}}
\begin{document}
    \exercisecount %<- Contains the number of exercises (after the first build).
    \buildsets{list,of,sets}
    % Tell \exercisecount to remember the numexercisescounter
    \setforlater\exercisecount{\thenumexercises}
\end{document}

If you're building using e.g. latexmk, this will just work out of the box, but if you're manually running, say, pdftex, then you have to run pdftex multiple times for the latter to work.

Edit: forgot \makeatletter

@Strauman Strauman added Feature request Request new functionalities and features resolved Questions solved not by commits, but by a good answer or workaround. and removed Feature request Request new functionalities and features labels Oct 2, 2018
@thorstengrothe
Copy link
Author

Ah, that was exactly my desire - I need the command before the buildset is run, I will try it!
Thank you for the fast response!

P. S. In the next few weeks I will have a lot of exams for my courses and I'm planning to do them all with exercisebank, I think reality is the best test for this package. When I'm done I will report my experiences!

Thorsten

@thorstengrothe
Copy link
Author

The command works until this line, (see my comment in the code):

...
\begin{document}
    \exercisecount 
    \buildsets{list,of,sets}
     % \setforlater\exercisecount{\thenumexercises} --> uncommenting this leads to an error
\end{document}

This is the error message:

bildschirmfoto_2018-10-02_20-15-11

@Strauman
Copy link
Owner

Strauman commented Oct 3, 2018

Forgot \makeatletter and \makeatother. Updated. Try now!

@thorstengrothe
Copy link
Author

Works perfectly now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolved Questions solved not by commits, but by a good answer or workaround.
Projects
None yet
Development

No branches or pull requests

2 participants