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

Counting points from random exercises #27

Closed
cgnieder opened this issue Mar 7, 2018 · 1 comment
Closed

Counting points from random exercises #27

cgnieder opened this issue Mar 7, 2018 · 1 comment
Assignees
Labels
bug error in the code

Comments

@cgnieder
Copy link
Owner

cgnieder commented Mar 7, 2018

\documentclass{article}
\usepackage{xsim}

\DeclareExerciseCollection{foo}

\usepackage{filecontents,lipsum}
\begin{filecontents*}{foo.tex}
\begin{exercise}[points=1]
  foo one \lipsum[4]
\end{exercise}
\begin{solution}
  foo one \lipsum[4]
\end{solution}
\begin{exercise}[points=2]
  foo two \lipsum[4]
\end{exercise}
\begin{solution}
  foo two \lipsum[4]
\end{solution}
\begin{exercise}[points=3]
  foo three \lipsum[4]
\end{exercise}
\begin{solution}
  foo three \lipsum[4]
\end{solution}
\end{filecontents*}

\begin{document}

\collectexercises{foo}
\input{foo.tex}
\collectexercisesstop{foo}

\printrandomexercises[collection=foo]{1}

% prints 6 instead of either 1, 2, or 3:
Total: \printtotalpoints

\end{document}
@cgnieder cgnieder self-assigned this Mar 7, 2018
@cgnieder cgnieder added the bug error in the code label Mar 7, 2018
@ptoche
Copy link

ptoche commented Mar 8, 2018

As initially reported here: https://tex.stackexchange.com/questions/419046/xsim-incorrect-number-of-questions-and-total-of-points

This is a follow up on https://tex.stackexchange.com/questions/383207, where the xsim package is used to create a collection of questions with unique IDs and where the questions are then inserted by ID.

How can I get the correct number of points and questions when some questions are declared in the collection but not subsquently inserted in the document?

The commands \numberofquestions and \printtotalpoints correctly compute the number and points inside the collection, but I would like to have a count for the inserted questions only. In the screenshot: 1 question is inserted for 50 points, but the counter shows 2 questions for 100 points.

What am I doing wrong?

enter image description here

\documentclass{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{filecontents} % for self-contained example
\begin{filecontents}{bank.tex}
\begin{question}[ID={Q1}, points={50}, tags={difficult}]
First Question: Select one of the following solutions:
\begin{enumerate}
\item A
\item B
\item C
\item D
\item E
\end{enumerate}
\end{question}
\begin{answer}
Solution to First Question
\end{answer}

\begin{question}[ID={Q2}, points={50}, tags={bonus}]
Second Question: Select one of the following solutions:
\begin{enumerate}
\item A
\item B
\item C
\item D
\item E
\end{enumerate}
\end{question}
\begin{answer}
Solution to Second Question
\end{answer}
\end{filecontents}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{xsim}
\usepackage[most]{tcolorbox}

\newcommand*\includeQuestion[1]{%
\XSIMexpandcode{\printexercise{question}{\GetExerciseIdForProperty{ID}{#1}}}%
}

\newcommand*\includeSolution[1]{%
\XSIMexpandcode{\printsolution{question}{\GetExerciseIdForProperty{ID}{#1}}}%
}

\DeclareExerciseEnvironmentTemplate{tcb}
{%
    \tcolorbox[breakable,
        drop shadow,
        beforeafter skip = 1\baselineskip,
        fonttitle   = \bfseries,
        fontupper = \normalsize,
        valign = top,
        colframe = \IfInsideSolutionF{green!20!white}\IfInsideSolutionT{blue!20!white},
        colback = \IfInsideSolutionF{green!3!white}\IfInsideSolutionT{blue!3!white},
        coltext = black,
        coltitle = black,
        boxrule = 1pt,
        width = \linewidth,
        left = 2mm,
        title =
        \IfInsideSolutionT{\XSIMmixedcase{\XSIMtranslate{solution}}~to~}%
        \XSIMmixedcase{\XSIMtranslate{question}}~\GetExerciseProperty{counter}%
        \IfInsideSolutionF{%  
          \IfExercisePropertySetT{tags}{%
            \textbf{~~(\ListExerciseTags{tags}{, })}}%
          \IfExercisePropertySetT{points}{%
            \hfill[\GetExerciseProperty{points}
            \IfExerciseGoalSingularTF{points}
              {\XSIMtranslate{point}}
              {\XSIMtranslate{points}}]%
          }%
        }%
    ]%
}{\endtcolorbox}

\DeclareExerciseType{question}{
    exercise-env = question,
    solution-env = answer,
    exercise-name = question, % used with headings=true
    solution-name = solution,  % used with headings=true
    exercise-template = tcb,
    solution-template = tcb
}

\DeclareExerciseCollection{myCollection}


\begin{document}

\collectexercises{myCollection}
\input{bank.tex}
\collectexercisesstop{myCollection}

\section*{Instructions}
\noindent Total number of questions: \numberofquestions. \par
\noindent Total points: \printtotalpoints.

\section*{Questions}

\includeQuestion{Q1}
\includeSolution{Q1}

%\includeQuestion{Q2}
%\includeSolution{Q2}

\end{document}

cgnieder added a commit that referenced this issue Feb 20, 2020
Repository owner deleted a comment from TorbjornT Feb 20, 2020
Repository owner deleted a comment from ptoche Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug error in the code
Projects
None yet
Development

No branches or pull requests

2 participants