How to show multi-choice answer key at the end of the document?

I want to show the answer keys at the end of the (multiple-choice) exam page. I have a bank of questions and answers (always the first answer in the bank is assumed to be the right choice), and some macros to shuffle the questions and their answers. All files are attached (here). The output is also shown bellow. the problem is that I cannot show the correct answers at the end of the page.

• What have you done so far? Could you show us a minimal working code to demonstrate? – Steven B. Segletes Dec 22 '14 at 18:51
• I have shared my codes. I can not fill the final answer key. – remo Dec 22 '14 at 19:14
• I would highly recommend against some of the naming conventions you've adopted. For example, you have quite a number of macros named \pgf.... This makes it very hard to figure out what going on since naming in this manner suggests that these are macros which come with the pgf suite. Such personalized macros should be named in a manner to indicate that they are your own. Also, it's just a lot of work for someone else to read through and try to figure out what you're doing. – A.Ellett Dec 22 '14 at 22:55

There are various packages out there to help you build exams and quizzes. I'm not really familiar with them because I've built my own. Here's a very simplified version of what I use:

\documentclass{article}

\makeatletter

\newcounter{ae@prob@cnt}

\newcommand\problem[1][a]{%%
\stepcounter{ae@prob@cnt}%%
\edef\ae@tmp{\theae@prob@cnt/#1}%%
\else
\fi
Problem \theae@prob@cnt\hspace{1em}%%%
}

\def\ae@continue{}%%
\ae@parse@pair#1\@nil
\ifx\relax#2
\else
\fi
\ae@continue}

\def\ae@parse@pair#1/#2\@nil{%%
#1\hspace{0.25cm}#2\par}

\makeatother

\begin{document}

\problem[a] This is a question

\problem[b] This is another question

\problem[d] This is the penultimate question

\problem[c] My favorite question.

\end{document}


UPDATE

Here's a modified version of the above:

\makeatletter
\typeout{===>#1:#2}%%
\edef\ae@tmp{#1/#2}%%
\else
\fi}

\def\ae@continue{}%%
\ae@parse@pair#1\@nil
\ifx\relax#2
\else
\fi
\ae@continue}

\def\ae@parse@pair#1/#2\@nil{%%
#1\hspace{0.25cm}#2\par}

\makeatother


Save it in a file called buildanswerkey.tex and load it in your commandsPerm.tex file.

In commandsPerm.tex, I've rewritten a few of the lines as follows:

%%-----------------------------------------
\pgfmathrandomitemwithoutreplacement\j{tmp}
\ifx\j\javab \questionhaspoints{\thequestion = 1} \fi
%%-----------------------------------------
\pgfmathrandomitemwithoutreplacement\j{tmp}
\ifx\j\javab \questionhaspoints{\thequestion = 2} \fi
%%-----------------------------------------
\pgfmathrandomitemwithoutreplacement\j{tmp}
\ifx\j\javab \questionhaspoints{\thequestion = 3} \fi
%%-----------------------------------------
\pgfmathrandomitemwithoutreplacement\j{tmp}

Then when you compile your file, you get an answer key. I didn't bother to figure out how you intended to create your answer key, but by calling \presentanswerkey before exiting your mcquestions environment, then you'll get a correct key: