%Stellenbosch UNiversity Bilingual Question Paper Template
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{SUNEngBQP}[%
% 2003/11/14 - v0.1 - by Peter-Jan Randewijk
%
% 2004/03/22 - v0.2 - by Peter-Jan Randewijk
%
% 2004/09/10 - v0.3 - by Peter-Jan Randewijk
% -- AnswerOnPaper package option added
% -- \answerinclude{<....>} -- added
% -- \answerinfo{<afrikaans info>}{<english info>} -- added
% -- \answerlines{<no of lines>} -- modified to be dependant on the AnswerOnPaper option
% -- \answerbox{<variable name>} -- modified to be dependant on the AnswerOnPaper option
% -- \answerdrawing{<height of grid>} -- modified to be dependant on the AnswerOnPaper option
%
% 2005/01/17 - v0.4 - by Peter-Jan Randewijk
% -- \subquestioninfo{<afrikaans info>}{<english info>} -- added
% -- \answerinfo{<afrikaans info>}{<english info>} -- modified to have an indent
% -- \PageBreakAnswerOnPaper -- added to add a ``\newpage'' only if AnswerOnPaper is set
% -- \PageBreakQuestionsOnly -- added to add a ``\newpage'' only if AnswerOnPaper is NOT set
% -- \PageBreakAlways -- added as an alias for ``\newpage'', to always add a ``\newpage''
%
% 2005/02/21 - v0.5 - by Peter-Jan Randewijk
% -- \PaperTypeDateTimeTotal{<afrikaans description>}{<english description>}{<afrikaans date>}{<english date>}{<hand in time>} -- modified for Homework Assignments or Tasks
% -- \PaperTypeDateDurationTotal{<afrikaans description>}{<english description>}{<afrikaans date>}{<english date>}{<duration>} -- changed the name from ``\PaperTypeDateTimeTotal''
%     to be more descriptive
% 2005/05/16 - v0.6 - by Peter-Jan Randewijk
% -- \subqlabel{<subq:label>} -- added to reference subquestion numbers using \ref{subq:label}
% -- \Caption{<afrikaan label>}{<english label>} -- added to number Figures
% 2005/07/26 - v0.7 - by Peter-Jan Randewijk
% -- \PageBreakAnswerOnPaper -- code slightly modified
% -- \PageBreakQuestionsOnly -- code slightly modified
]%

\RequirePackage[afrikaans,english]{babel}
\RequirePackage{calc}
\RequirePackage{caption}
\RequirePackage{hhline}
\RequirePackage{ifthen}
\RequirePackage{fancyhdr}
\RequirePackage{multicol}
\RequirePackage{lastpage}
\RequirePackage{longtable}

\newboolean{OnPaper}
\setboolean{OnPaper}{false}

\DeclareOption{AnswerOnPaper}{\setboolean{OnPaper}{true}}
%\ExecuteOptions{AnswerOnPaper}
\ProcessOptions

\selectlanguage{english}

\newcounter{questionnumber}
\newcounter{subquestionnumber}[questionnumber]
\newcounter{subsubquestionnumber}[subquestionnumber]
\newcounter{subanswernumber}[subquestionnumber]
\newcounter{questiontotal}[questionnumber]
\newcounter{papertotal}
\newcounter{i}
\newcounter{InstructionCounter}

\newlength{\FullColOuterWidth}
\setlength{\FullColOuterWidth}{\textwidth-\arrayrulewidth}
\newlength{\HalfColOuterWidth}
\setlength{\HalfColOuterWidth}{0.5\textwidth-\arrayrulewidth}
\newlength{\ThirdColOuterWidth}
\setlength{\ThirdColOuterWidth}{\textwidth/3-\arrayrulewidth}
\newlength{\QuarterColOuterWidth}
\setlength{\QuarterColOuterWidth}{0.25\textwidth-\arrayrulewidth}
\newlength{\EighthColOuterWidth}
\setlength{\EighthColOuterWidth}{0.125\textwidth-\arrayrulewidth}
\newlength{\ColLeftInnerMarg}
\setlength{\ColLeftInnerMarg}{2mm}
\newlength{\ColRightInnerMarg}
\setlength{\ColRightInnerMarg}{2mm}
\newlength{\FullColInnerWidth}
\setlength{\FullColInnerWidth}{\FullColOuterWidth-\ColLeftInnerMarg-\ColRightInnerMarg}
\newlength{\HalfColInnerWidth}
\setlength{\HalfColInnerWidth}{\HalfColOuterWidth-\ColLeftInnerMarg-\ColRightInnerMarg}
\newlength{\ThirdColInnerWidth}
\setlength{\ThirdColInnerWidth}{\ThirdColOuterWidth-\ColLeftInnerMarg-\ColRightInnerMarg}
\newlength{\QuarterColInnerWidth}
\setlength{\QuarterColInnerWidth}{\QuarterColOuterWidth-\ColLeftInnerMarg-\ColRightInnerMarg}
\newlength{\EighthColInnerWidth}
\setlength{\EighthColInnerWidth}{\EighthColOuterWidth-\ColLeftInnerMarg-\ColRightInnerMarg}

\newlength{\markscolumnwidth}
\newlength{\questioncolumnwidth}
\newlength{\numbercolumnwidth}
\newlength{\subquestioncolumnwidth}
\newlength{\questionsepwidth}
\newlength{\questionmarwidth}
\newlength{\subquestionspacing}
\newlength{\subsubquestionspacing}
\newlength{\leftquestionpreheadingwidth}
\newlength{\leftquestionheadingwidth}
\newlength{\rightquestionpreheadingwidth}
\newlength{\rightquestionheadingwidth}
\newlength{\templength}

\setlength{\questionsepwidth}{5mm}
\setlength{\questionmarwidth}{3mm}
\setlength{\subquestionspacing}{3mm}
\setlength{\subsubquestionspacing}{1.5mm}

\settowidth{\markscolumnwidth}{\bf{[99]}}
\setlength{\questioncolumnwidth}{0.5\textwidth-0.5\questionsepwidth-\markscolumnwidth}
\settowidth{\numbercolumnwidth}{(x)~}
\setlength{\subquestioncolumnwidth}{\questioncolumnwidth-\numbercolumnwidth}

\setlength{\parindent}{0pt}
%\setlength{\tabcolsep}{0mm}
%\setlength{\arrayrulewidth}{0pt}

\setlength{\parskip}{1.25ex}
\setlength{\subquestionspacing}{1ex}

\fancypagestyle{plain}{%
\fancyhf{}
\fancyfoot[L]{\emph{bladsy}~\thepage~\emph{van}~\pageref{LastPage}}
\fancyfoot[R]{\emph{page}~\thepage~\emph{of}~\pageref{LastPage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{1pt}}

\newcommand{\leftquestionpreheadingtext}{Vraag}
\newcommand{\rightquestionpreheadingtext}{Question}

\settowidth{\leftquestionpreheadingwidth}{\bf{\leftquestionpreheadingtext}~99:~~}
\setlength{\leftquestionheadingwidth}{0.5\textwidth-\markscolumnwidth-\leftquestionpreheadingwidth-0.5\questionsepwidth-\questionmarwidth}
\settowidth{\rightquestionpreheadingwidth}{\bf{\rightquestionpreheadingtext}~99:~~}
\setlength{\rightquestionheadingwidth}{0.5\textwidth-\markscolumnwidth-\rightquestionpreheadingwidth-0.5\questionsepwidth-\questionmarwidth}

\newenvironment{PaperFrontPage}
{
  \begin{longtable}[l]{@{}@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}}
  \hline
  \endhead
  \hline
  \endfoot
  \multicolumn{8}{|@{\hspace{\ColLeftInnerMarg}}p{\FullColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{}\\
  \multicolumn{8}{|@{\hspace{\ColLeftInnerMarg}}p{\FullColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \makebox(30,27)[tl]{\includegraphics[height=25mm]{c:/localtexmf/NuweUSlogo}}
    \hfill
    \makebox(30,27)[cc]{\parbox{120mm}{\centering \Large \textbf{FAKULTEIT INGENIEURSWESE\\
                                                      \textsl{FACULTY OF ENGINEERING}}}}
    \hfill
    \makebox(30,27)[tr]{\includegraphics[height=25mm]{c:/localtexmf/NuweENlogo}}}  \\ \hline
}
{
  \end{longtable}
}

\newcommand{\PaperSubject}[2]{%
  \multicolumn{4}{|@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \centering \Large \textbf{#1\rule[-1.5ex]{0pt}{4ex}}}
  &
  \multicolumn{4}{@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \centering \Large \textbf{\emph{#2}}}
  \\
  \hline
}

%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\PaperTypeDateDurationTotal}[5]{%
  \multicolumn{2}{|@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \parbox[b]{\QuarterColInnerWidth}{\textbf{#1}\rule{0pt}{2ex}\par\textbf{\emph{#2}}}}
  &
  \multicolumn{2}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
     \parbox[b]{\QuarterColInnerWidth}{\textbf{#3}\par\textbf{\emph{#4}}}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
     \parbox[b]{\QuarterColInnerWidth}{\textbf{Tydsduur:}\par\textbf{\emph{Duration}:}}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
     \parbox[b]{\QuarterColInnerWidth}{\huge\textbf{#5\rule{0pt}{2ex}}}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
     \parbox[b]{\QuarterColInnerWidth}{\textbf{Totaal:}\par\textbf{\emph{Total}:}}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
     \parbox[b]{\QuarterColInnerWidth}{\huge\textbf{\ref{TotalMarks}\rule{0pt}{2ex}}}}
  \\
  \hline
}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\PaperTypeDateTimeTotal}[5]{%
  \multicolumn{2}{|@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \parbox[b]{\QuarterColInnerWidth}{\textbf{#1}\rule{0pt}{2ex}\par\textbf{\emph{#2}}}}
  &
  \multicolumn{2}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
     \parbox[b]{\QuarterColInnerWidth}{\textbf{#3}\par\textbf{\emph{#4}}}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
     \parbox[b]{\QuarterColInnerWidth}{\textbf{Tyd:}\par\textbf{\emph{Time}:}}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
     \parbox[b]{\QuarterColInnerWidth}{\huge\textbf{#5\rule{0pt}{2ex}}}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
     \parbox[b]{\QuarterColInnerWidth}{\textbf{Totaal:}\par\textbf{\emph{Total}:}}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
     \parbox[b]{\QuarterColInnerWidth}{\huge\textbf{\ref{TotalMarks}\rule{0pt}{2ex}}}}
  \\
  \hline
}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%

\newcommand{\PaperQuestionMarks}{%
  \\
  \hline
  \multicolumn{1}{|@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{~\rule{0pt}{4ex}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{~\rule{0pt}{4ex}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{~\rule{0pt}{4ex}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{~\rule{0pt}{4ex}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{~\rule{0pt}{4ex}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{~\rule{0pt}{4ex}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{~\rule{0pt}{4ex}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\EighthColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{~\rule{0pt}{4ex}}
  \\
  \hline
}

\newcommand{\PaperType}[2]{%
  \multicolumn{1}{|@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{Tipe:\rule{0pt}{2ex}}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{#1}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{Type:}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{#2}}
  \\
}

\newcommand{\PaperDate}[2]{%
  \multicolumn{1}{|@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{Datum:}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{#1}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{Date:}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{#2}}
  \\
  \hline
}

\newcommand{\PaperTime}[1]{%
  \multicolumn{1}{|@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{Tydsduur:}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \huge \textbf{#1\rule{0pt}{2ex}}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{Duration:}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \huge \textbf{#1}}
  \\
  \hline
}

\newcommand{\PaperFullMarks}[1]{%
  \multicolumn{1}{|@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{Volpunte:}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \huge \textbf{#1\rule{0pt}{2ex}}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{Full Marks:}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \huge \textbf{#1}}
  \\
  \hline
}

\newcommand{\PaperTotal}{%
  \multicolumn{1}{|@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{Totaal:}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \huge \textbf{\ref{TotalMarks}\rule{0pt}{2ex}}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{Total:}}
  &
  \multicolumn{1}{@{\hspace{\ColLeftInnerMarg}}p{\QuarterColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \huge \textbf{\ref{TotalMarks}}}
  \\
  \hline
}

\newcommand{\PaperExaminers}[2]{%
  \\
  \hline
  \multicolumn{4}{|@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{Eksaminator\rule[-1ex]{0pt}{3ex}}}
  &
  \multicolumn{4}{@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{Mede-Eksaminator}}
  \\
  \multicolumn{4}{|@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{\emph{Examiner}}}
  &
  \multicolumn{4}{@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{\emph{Co-Examiner}}}
  \\
  \hline
  \multicolumn{4}{|@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \rule{0pt}{15mm}}
  &
  \multicolumn{4}{@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    }
  \\
  \hline
  \multicolumn{4}{|@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    #1}
  &
  \multicolumn{4}{@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    #2}
  \\
  \hline
}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\StudentNameNo}{\ifthenelse{\boolean{OnPaper}}{
  \\
  \hline
  \multicolumn{4}{|@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{Naam van Student\rule[-1ex]{0pt}{3ex}}}
  &
  \multicolumn{4}{@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{Studentenommer}}
  \\
  \multicolumn{4}{|@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{\emph{Name of Student}}}
  &
  \multicolumn{4}{@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \textbf{\emph{Student Number}}}
  \\
  \hline
  \multicolumn{4}{|@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \rule{0pt}{15mm}}
  &
  \multicolumn{4}{@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    }
  \\
  \hline
}{\cr\kill}}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\InstructionItem}[2]{%
  \begin{list}{#1}{%
    \setlength{\leftmargin}{\labelwidth-\labelsep}}
    \vspace{-1.5\baselineskip}
    \item \small#2
    \vspace{-\baselineskip}
  \end{list}}


\newcommand{\PaperInstructionsHead}{%
  \\
  \hline
  \multicolumn{4}{|@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \centering \large \textbf{Instruksies\rule[-1ex]{0pt}{3ex}}}
  &
  \multicolumn{4}{@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \centering \large \textbf{Instructions}}
  \\
  \hline
}

\newcommand{\PaperInstructions}[2]{%
  \multicolumn{4}{|@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \refstepcounter{InstructionCounter}
    \InstructionItem{\small\theInstructionCounter.}{\small #1}}
  &
  \multicolumn{4}{@{\hspace{\ColLeftInnerMarg}}p{\HalfColInnerWidth}@{\hspace{\ColRightInnerMarg}}|}{
    \InstructionItem{\small\theInstructionCounter.}{\small #2}}
  \\
}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\questionline}{\hhline{-------~~}\\}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\questionblankline}{&&&&&&\\}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\addmarks}[1]{\addtocounter{questiontotal}{#1}\addtocounter{papertotal}{#1}}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\questionheading}[3]{%
  \multicolumn{2}{@{}l@{}}{%
    \begin{tabular*}{\questioncolumnwidth-\questionmarwidth}[t]{@{}p{\leftquestionpreheadingwidth}@{}@{}p{\leftquestionheadingwidth}@{}}
      \bf{\leftquestionpreheadingtext~\thequestionnumber :} & \raggedright\bf{#2}
    \end{tabular*}\par\vspace{\subquestionspacing}} &
  \parbox[t]{\markscolumnwidth}{\bf{[\ref{TotalMarksQuestion\thequestionnumber}]}} &&
  \multicolumn{2}{@{}l@{}}{%
    \begin{tabular*}{\questioncolumnwidth-\questionmarwidth}[t]{@{}p{\rightquestionpreheadingwidth}@{}@{}p{\rightquestionheadingwidth}@{}}
      \bf{\rightquestionpreheadingtext~\thequestionnumber :} & \raggedright\bf{#3}
    \end{tabular*}\par\vspace{\subquestionspacing}} &
  \parbox[t]{\markscolumnwidth}{\bf{[\ref{TotalMarksQuestion\thequestionnumber}]}} &&
  \ifthenelse{\boolean{OnPaper}}{\ifthenelse{\equal{#1}{x}}
    {\psframe[linewidth=2pt](0mm,-5mm)(\linewidth,5mm)}
    {}}{}\\}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\questioninfo}[3]{%
  \multicolumn{2}{@{}p{\questioncolumnwidth}@{}}{%
    \parbox[t]{\questioncolumnwidth-\questionmarwidth}{#2\selectlanguage{afrikaans}\par\vspace{\subquestionspacing}}} &
  \ifthenelse{#1=0}{~}{[#1]} & &
  \multicolumn{2}{@{}p{\questioncolumnwidth}@{}}{%
    \parbox[t]{\questioncolumnwidth-\questionmarwidth}{#3\selectlanguage{english}\par\vspace{\subquestionspacing}}} &
  \ifthenelse{#1=0}{~}{[#1]\addmarks{#1}}\\}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\subquestion}[3]{\refstepcounter{subquestionnumber}%
  \parbox[t]{\numbercolumnwidth}{(\alph{subquestionnumber})\selectlanguage{afrikaans}} &
  \parbox[t]{\subquestioncolumnwidth-\questionmarwidth}{#2\par\vspace{\subquestionspacing}} &
  \ifthenelse{\equal{#1}{}}{}{[#1]} & &
  \parbox[t]{\numbercolumnwidth}{(\alph{subquestionnumber})\selectlanguage{english}} &
  \parbox[t]{\subquestioncolumnwidth-\questionmarwidth}{#3\par\vspace{\subquestionspacing}} &
   \ifthenelse{\equal{#1}{}}{}{\parbox[t]{\markscolumnwidth}{[#1]}\addmarks{#1}}\\}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\subsubquestion}[3]{\refstepcounter{subsubquestionnumber}%
  &
  \parbox[t]{\numbercolumnwidth}{\roman{subsubquestionnumber}.\selectlanguage{afrikaans}}\parbox[t]{\subquestioncolumnwidth-\numbercolumnwidth-\questionmarwidth}{#2\par\vspace{\subsubquestionspacing}}
  &
  \ifthenelse{\equal{#1}{}}{}{[#1]} & &
  &
  \parbox[t]{\numbercolumnwidth}{\roman{subsubquestionnumber}.\selectlanguage{english}}\parbox[t]{\subquestioncolumnwidth-\numbercolumnwidth-\questionmarwidth}{#3\par\vspace{\subsubquestionspacing}}
  &
  \ifthenelse{\equal{#1}{}}{}{\parbox[t]{\markscolumnwidth}{[#1]}\addmarks{#1}}\\}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\subquestioninfo}[2]{
  \parbox[t]{\numbercolumnwidth}{\selectlanguage{afrikaans}} &
  \parbox[t]{\subquestioncolumnwidth-\questionmarwidth}{#1\par\vspace{\subquestionspacing}} & & &
  \parbox[t]{\numbercolumnwidth}{\selectlanguage{english}} &
  \parbox[t]{\subquestioncolumnwidth-\questionmarwidth}{#2\par\vspace{\subquestionspacing}} &  \\}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\answerinfo}[2]{\ifthenelse{\boolean{OnPaper}}{
  \parbox[t]{\numbercolumnwidth}{\selectlanguage{afrikaans}} &
  \parbox[t]{\subquestioncolumnwidth-\questionmarwidth}{#1\par\vspace{\subquestionspacing}} & & &
  \parbox[t]{\numbercolumnwidth}{\selectlanguage{english}} &
  \parbox[t]{\subquestioncolumnwidth-\questionmarwidth}{#2\par\vspace{\subquestionspacing}} &  \\}{\cr\kill}}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\questioninclude}[1]{%
  \end{longtable}
  #1
 \begin{longtable}[l]{@{}p{\numbercolumnwidth}@{}@{}p{\subquestioncolumnwidth}@{}@{}p{\markscolumnwidth}@{}@{}p{\questionsepwidth}@{}@{}p{\numbercolumnwidth}@{}@{}p{\subquestioncolumnwidth}@{}@{}p{\markscolumnwidth}@{}@{}p{\marginparsep}@{}@{}p{\marginparwidth}@{}}}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\answerinclude}[1]{\ifthenelse{\boolean{OnPaper}}{
  \end{longtable}
  #1
 \begin{longtable}[l]{@{}p{\numbercolumnwidth}@{}@{}p{\subquestioncolumnwidth}@{}@{}p{\markscolumnwidth}@{}@{}p{\questionsepwidth}@{}@{}p{\numbercolumnwidth}@{}@{}p{\subquestioncolumnwidth}@{}@{} p{\markscolumnwidth}@{}@{}p{\marginparsep}@{}@{}p{\marginparwidth}@{}}}{\cr\kill}}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\captionsetup{labelfont={bf},textfont=md}
\newcommand{\Caption}[2]{%
  \renewcommand{\figurename}{{Figuur}}
  \caption{#1}
  \ContinuedFloat
  \renewcommand{\figurename}{{Figure}}
  \caption{#2}}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\answerblankline}{\rule{0pt}{5mm}&&&&&&\\}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\answerblanklines}[2][]{\answerblankline\setcounter{i}{1}
  \whiledo{\value{i}<#2}
    {\answerblankline
     \stepcounter{i}}
  \ifthenelse{\equal{#1}{x}}
    {\answerlinemarkbox}
    {\answerline}
  \answerblankline}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\answerline}{\rule{0pt}{5mm}\psline[linecolor=gray,linewidth=0.25pt](0,0)(\textwidth,0)\\}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\answerlinemarkbox}{\rule{0pt}{5mm}\psline[linecolor=gray,linewidth=0.25pt](0,0)(\textwidth,0) &&&&&&&&
  \psframe[linewidth=0.8pt](0mm,-5mm)(\linewidth,5mm)\\}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\answerblanklinemarkbox}{\ifthenelse{\boolean{OnPaper}}{\rule{0pt}{5mm} &&&&&&&&
  \psframe[linewidth=0.8pt](0mm,-5mm)(\linewidth,5mm)\\}{\cr\kill}}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\answerlines}[2][]{\ifthenelse{\boolean{OnPaper}}{\answerblankline\setcounter{i}{1}%
  \ifthenelse{\equal{#1}{x}}
    {\answerlinemarkbox}
    {\answerline}
  \whiledo{\value{i}<#2}
    {\answerline
     \stepcounter{i}}
  \answerblankline}{\cr\kill}}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newlength{\preanswertextlength}
\newlength{\answerlinelength}

\newcommand{\answerbox}[2][]{\ifthenelse{\boolean{OnPaper}}{\rule{0pt}{10mm} &
  \settowidth{\preanswertextlength}{#2\,=~}
  \setlength{\answerlinelength}{\linewidth-\preanswertextlength}
  \psframe[linewidth=0.8pt](-3mm,-2mm)(\linewidth,8mm)#2\,=\psline[linecolor=gray,linewidth=0.25pt](0,0)(\answerlinelength,0) &&&&&&&
  \ifthenelse{\equal{#1}{x}}
    {\psframe[linewidth=0.8pt](0mm,-2mm)(\linewidth,8mm)}
    {}\\
  \answerblankline}{\cr\kill}}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\answerdrawing}[2][]{\ifthenelse{\boolean{OnPaper}}{\answerblankline
  \cr\kill\multicolumn{7}{@{}c@{}}{%
  \begin{pspicture}(0,0)(\textwidth,#2)
    \psset{unit=5mm,gridwidth=0.25pt,gridcolor=gray,gridlabels=0pt,subgriddiv=1}
    \psgrid
  \end{pspicture}}&&
  \ifthenelse{\equal{#1}{x}}
    {\setlength{\templength}{#2-10mm}
     \psframe[linewidth=0.8pt](-1mm,#2)(9mm,\templength)}
    {}\\
  \answerblankline}{\cr\kill}}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\answeritemlines}[2][]{\ifthenelse{\boolean{OnPaper}}{\stepcounter{subanswernumber}\setcounter{i}{0}%
  \ifthenelse{\value{subanswernumber}=1}{\cr}{\kill}
  \parbox[t]{\numbercolumnwidth}{\roman{subanswernumber})} &
  \multicolumn{6}{@{}l@{}}{%
  \setlength{\answerlinelength}{\textwidth-\numbercolumnwidth-3pt}
  \begin{tabular*}{\answerlinelength}[t]{@{}p{\answerlinelength}@{}}
    \whiledo{\value{i}<#2}
      {\rule{0pt}{5mm}\psline[linecolor=gray,linewidth=0.25pt](0,0)(\answerlinelength,0)\\
       \stepcounter{i}}
  \end{tabular*}}&&
  \ifthenelse{\equal{#1}{x}}
    {\psframe[linewidth=0.8pt](0mm,-5mm)(\linewidth,5mm)}
    {}\\}{\cr\kill}}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\PageBreakAlways}{\newpage}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\PageBreakAnswerOnPaper}{\ifthenelse{\boolean{OnPaper}}{\mbox{}\\\newpage}{\mbox{}}}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\PageBreakQuestionsOnly}{\ifthenelse{\boolean{OnPaper}}{\mbox{}}{\mbox{}\\\newpage}}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\makeatletter
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newenvironment{question}
{
  \refstepcounter{questionnumber}
  \setlongtables
  \begin{longtable}[l]{@{}p{\numbercolumnwidth}@{}@{}p{\subquestioncolumnwidth}@{}@{}p{\markscolumnwidth}@{}@{}p{\questionsepwidth}@{}@{}p{\numbercolumnwidth}@{}@{}p{\subquestioncolumnwidth}@{}@{}p{\markscolumnwidth}@{}@{}p{\marginparsep}@{}@{}p{\marginparwidth}@{}}
}
{
  \end{longtable}
  \immediate\write\@auxout{\string\newlabel{TotalMarksQuestion\thequestionnumber}{{\thequestiontotal}{}{}}}
}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\newcommand{\subqlabel}[1]{\immediate\write\@auxout{\string\newlabel{#1}{{\alph{subquestionnumber}}{}{}{}}}}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\AtEndDocument{\immediate\write\@auxout{\string\newlabel{TotalMarks}{{\thepapertotal}{}{}{}}}
               \immediate\write\@auxout{\string\newlabel{TotalQuestions}{{\thequestionnumber}{}{}{}}}}
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
\makeatother
%------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%
