Here is a minimal example.
\documentclass[a4paper, addpoints]{exam}
\usepackage{etoolbox}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the accumulated answers text
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\answertext}{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% hook to fillin command
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\renewcommand\fillin[1][{}]{%
% copy the contents of fillin definition from the exam class
% we try to append the content to the \answertext string
\xappto\answertext{\thequestion,#1\space}%
\def\fillin@ans{#1}%
\fillin@relay
}
\makeatother
\begin{document}
\section{Questions}
\begin{questions}
\question First Quesiton \fillin[Answers1] is the color of my true love’s hair.
\question Second Question \fillin[Answers2] is the \fillin[Answers3].
\question Third Question \fillin[Answers4] is OK.
\end{questions}
\section{Answers}
\ifprintanswers
% do nothing
\else
% this print the answertext
\answertext
\fi
\end{document}
I have to hook into the \fillin
command to accumulate the answers, and put them in the global variable \answertext
.
But the result is looks like below:
I would like to see like below:
1,Answers1 2,Answers2;Answers3 3,Answers4
I mean it should only show the question number "2" once. Because one question could have many fillin answers. Also, I need a way to calculate the total fillin numbers. (That is, one fillin place has 2 points for the example)