% AMC unified answer sheet example

\documentclass[a4paper]{article}

\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{multicol}
\usepackage{tikz}

\usepackage[separateanswersheet]{automultiplechoice}

\geometry{hmargin=2cm}

\makeatletter

% layout
\fancypagestyle{AMCpagePartial}{%
  \fancyhf{}%
  % corner circles
  \fancyhead[L]{\AMC@LR{\he@dbas{\leavevmode\m@rque{positionHG}}}}%
  \fancyhead[R]{\AMC@LR{\he@dbas{\leavevmode\m@rque{positionHD}}}}%
  \fancyfoot[L]{\AMC@LR{\leavevmode\m@rque{positionBG}}}%
  \fancyfoot[R]{\AMC@LR{\leavevmode\m@rque{positionBD}}}%
  % header: binary boxes, *except subject number*, that will be given by
  % the student.
  \fancyhead[C]{\AMC@LR{\he@dhaut{%
        \AMCIDBoxesB\AMCIDBoxesC
      }}}%
  \fancyhfoffset[EOLR]{5mm}%
  % foot
  \fancyfoot[C]{\AMC@note}%
  % no head and foot rules
  \renewcommand{\headrulewidth}{0pt}%
  \renewcommand{\footrulewidth}{0pt}%
}

% Subject pages: corner circles are not needed
\fancypagestyle{AMCpageSujet}{%
  \fancyhf{}%
  \fancyhead[L]{}%
  \fancyhead[R]{}%
  \fancyfoot[L]{}%
  \fancyfoot[R]{}%
  % head: whatever you want
  \fancyhead[C]{\AMC@LR{\he@dhaut{%
        \texttt{version \the\AMCid@etud{} page \thepage}
      }}}%
  \fancyhfoffset[EOLR]{5mm}%
  \fancyfoot[C]{\AMC@note}%
  \renewcommand{\headrulewidth}{0pt}%
  \renewcommand{\footrulewidth}{0pt}%
}

% These two commands show a binary encoding of the subject number: AA
% with filled ones, and AO with empty ones to be filled by the student
\newcommand\AMCIDBoxesAA{\AMC@binaryCode{style={shape=oval,size=5mm,rule=.2mm},id=0,ndigits=\AMC@NCBetud,hsep=2mm}{\the\AMCid@etud}}
\newcommand\AMCIDBoxesAO{\AMC@binaryCode{style={shape=oval,size=5mm,rule=.2mm},id=1,ndigits=\AMC@NCBetud,hsep=2mm}{0}}

% Identification data: student name, student number, subject number.
\def\identification{
  \noindent\AMCzone[id]{identification\thepage}{%
    \fbox{%
      \begin{minipage}{\linewidth}
        \noindent Please darken the characters from your student ID:\\[1.2ex]
        \AMCcodeGrid[h,multi]{id}{ABCDEFGHJKLMNPQRSTUVWXYZ,0123456789}
        
        \noindent Please copy here the pattern corresponding to your subject: \AMCIDBoxesAO
      \end{minipage}%
    }%
  }%
}

% Number of binary digits for the subject number: the number of
% different subject versions must be less or equal than 2^NCBetud-1.
\def\AMC@NCBetud{6}

% Command that allows to set the same check number for each different subject.
\def\initCheck{\AMCid@check=27}

\makeatother

\begin{document}

\AMCrandomseed{1237893}

\def\AMCformQuestion#1{\makebox[1.3em][l]{#1}}    

% QUESTIONS
\setdefaultgroupmode{withoutreplacement}

\element{general}{
  \begin{question}{q01}
    q01 text
    \begin{choices}
      \correctchoice{correct}
      \wrongchoice{wrong 1}
      \wrongchoice{wrong 2}
      \wrongchoice{wrong 3}
      \wrongchoice{wrong 4}
    \end{choices}
  \end{question}
}

\element{general}{
  \begin{question}{q02}
    q02 text
    \begin{choices}
      \correctchoice{correct}
      \wrongchoice{wrong 1}
      \wrongchoice{wrong 2}
      \wrongchoice{wrong 3}
      \wrongchoice{wrong 4}
    \end{choices}
  \end{question}
}

\element{general}{
  \begin{question}{q03}
    q03 text
    \begin{choices}
      \correctchoice{correct}
      \wrongchoice{wrong 1}
      \wrongchoice{wrong 2}
      \wrongchoice{wrong 3}
      \wrongchoice{wrong 4}
    \end{choices}
  \end{question}
}

\element{general}{
  \begin{question}{q04}
    q04 text
    \begin{choices}
      \correctchoice{correct}
      \wrongchoice{wrong 1}
      \wrongchoice{wrong 2}
      \wrongchoice{wrong 3}
      \wrongchoice{wrong 4}
    \end{choices}
  \end{question}
}


\pagestyle{AMCpageSujet}

\exemplaire{5}{

\begin{minipage}{.4\linewidth}
  \centering\large\bf TEST
\end{minipage}

\begin{minipage}{.5\linewidth}
  Subject pattern t copy on your answer sheet:

  \AMCIDBoxesAA
\end{minipage}

\vspace{2ex}

\insertgroup{general}

\AMCcleardoublepage    

\initCheck
\AMCformBegin

\pagestyle{AMCpagePartial}

%%% début de l'en-tête de la feuille de réponses

\identification

\vspace*{5mm}

{\large\bf Answer sheet}

\vspace{1ex}

\begin{multicols}{4}
\AMCform
\end{multicols}

}

\end{document}