%%
%% This document was generated by QuizML using the tcd-eleceng-latex.jinja template
%%
%% see www.github.com/frcs/quizml
%%
%%
\documentclass{tcdexams}

<# passing the header variables to template  #>
<# we do not include 'type' and keys starting with '_'      #>
<| if header                                               -|>
<|   for key, value in header.items()                      -|>
<|     if (key != 'type') and (not key.startswith('_'))     |>
\def \info<<key>> {<<value>>}
<|     endif                                                |>  
<|-  endfor                                                 |>
<|-endif                                                    |>  

\providecommand{\infoprogrammeyearname}{}
\providecommand{\infoexamsemester}{}
\providecommand{\infoexamyear}{}
\providecommand{\infoexamdate}{}
\providecommand{\infoexamtime}{}
\providecommand{\infoexamvenue}{}
\providecommand{\infomodulename}{}
\providecommand{\infomodulecode}{}
\providecommand{\infoexaminer}{}
\providecommand{\infoinstructions}{}
\providecommand{\infomaterials}{}
\providecommand{\infoadditionalinformation}{}

\programmeyearname{\infoprogrammeyearname}
\examsemester{\infoexamsemester}
\examyear{\infoexamyear}
\examdate{\infoexamdate}
\examtime{\infoexamtime}
\examvenue{\infoexamvenue}
\modulename{\infomodulename}
\modulecode{\infomodulecode}
\examiner{\infoexaminer}
\instructions{\infoinstructions}
\materials{\infomaterials}
\additionalinformation{\infoadditionalinformation}

\usepackage{longtable,booktabs,tabto,multicol}
\usepackage{amsmath,amssymb}

\providecommand{\tightlist}
{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}

%% \usepackage[totalmarks]{examquestions}
\usepackage{listings}


%%
%% defining style for code blocks
%%
\usepackage{inconsolata}
\usepackage{fontspec}
\setmonofont[Scale=0.8]{inconsolata}

\lstset{%
  frame=l,
  basicstyle=\ttfamily\linespread{1.1}\fontsize{12}{13}\selectfont,
  commentstyle=\itshape,
  columns=fullflexible,
  breaklines=true,
  numbersep=10pt,
  numbers=left,  
  framerule=0.5pt,
  xleftmargin=-16pt,
  language=Python,
  xrightmargin=-24pt,
  numberstyle=\fontsize{11}{13}\selectfont\color{gray},
  keywordstyle=\color{blue},
  rulecolor=\color{gray},
  stringstyle=\color{red},
  commentstyle=\color{green},
  stringstyle=\color{red},
  resetmargins=true
}

%%
%% defining the `question` environment
%%
\newcommand*{\weightunit}{ marks}
\newcommand*{\subquestionskip}{1em}
\newsavebox{\qmarks}
\newcounter{bbquestion}
\newenvironment{bbquestion}[1][]{\sbox\qmarks{\bfseries #1 marks}
\refstepcounter{bbquestion}\par\medskip\textbf{Q.\thebbquestion.}
\hfill\begin{minipage}[t]{0.92\textwidth}}{\hspace*{0em plus 1fill}
\makebox{\bfseries [\usebox{\qmarks}]}\end{minipage}
\vspace{\subquestionskip}}

\usepackage{tikz,pgfplots,environ}
\usetikzlibrary{matrix,chains,positioning,decorations.pathreplacing,arrows,backgrounds}

\usepackage{parskip,setspace,xspace}
\onehalfspacing

\usepackage{etoolbox}

\newcommand{\btVFill}{\vskip0pt plus 1filll}

\usepackage{nccmath}
\usepackage{empheq}
\usepackage[many]{tcolorbox}
\usepackage{ragged2e}
\justifying

\usepackage{subfig}
\usepackage{changepage}
\usepackage{booktabs}
\usepackage[scale=2]{ccicons}
\usepackage{verbatim}
\usepackage[percent]{overpic}
\usepackage[absolute,overlay]{textpos}

\usepackage{array,booktabs}
\usepackage{multirow}
\usepackage{xspace}

\usepackage{adjustbox}
\captionsetup[subfigure]{labelformat=empty}

\usepackage{fancyhdr}


%% for displaying a watermark of the version used.  this can be useful
%% if you have multiple verions the same test to give. For instance,
%% version A for the even seat numbers, version B for the odd ones.

\ifdefined\infoversion

\usepackage{eso-pic}
\makeatletter
\AddToShipoutPicture{%
    \setlength{\@tempdimb}{.95\paperwidth}%
    \setlength{\@tempdimc}{0\paperheight}%
    \setlength{\unitlength}{1pt}%
    \put(\strip@pt\@tempdimb,\strip@pt\@tempdimc){%
        \makebox(0,0){ \textcolor{gray}{\infoversion} }%
    }%
}
\makeatother
\fi



\usepackage{svg}

%% \newcommand{\omrSIZE}{}
%% \newcommand{\omrSKIP}{.7em}

\ifcsname ifsolutions\endcsname\else
  \expandafter\let\csname ifsolutions\expandafter\endcsname
                  \csname iffalse\endcsname
                  \fi

%% loading the MCQ glyphs for keying (A-Z, 0-9). These glyphs are
%% suitable for OCR.

% Engine-agnostic thickness control
\newcommand{\thickText}[2][0.9]{%
  \ifpdftex\pdfliteral{2 Tr #1 w}#2\pdfliteral{0 Tr}%
  \else\ifluatex\pdfextension literal direct {2 Tr #1 w}#2\pdfextension literal direct {0 Tr}%
  \else\ifxetex\special{pdf:literal direct 2 Tr #1 w}#2\special{pdf:literal direct 0 Tr}\fi\fi\fi
}

\newcommand{\omrCirc}[2][white]{%
\hspace{-0.1em}%
\begin{tikzpicture}[
    baseline={([yshift=-0.7ex] current bounding box.center)},
  ]   
  \node[
    draw, 
    circle, 
    fill=#1,
    scale=0.58,
    line width=1pt,
    inner sep=2pt, 
    minimum size=1em,
    text width=1em, 
    align=center,
    font=\sffamily\small
  ] {\thickText[0.8]{#2}};
\end{tikzpicture}%
\hspace{-0.1em}%
\xspace%
}

\foreach \x in {A,...,Z} {
  \expandafter\xdef\csname o\x\endcsname{\noexpand\omrCirc{\x}}
  \expandafter\xdef\csname x\x\endcsname{\noexpand\omrCirc[black!60]{\x}}
}

\newcommand{\oZero}{\omrCirc{0}}  \newcommand{\xZero}{\omrCirc[gray!50]{0}}
\newcommand{\oOne}{\omrCirc{1}}   \newcommand{\xOne}{\omrCirc[gray!50]{1}}
\newcommand{\oTwo}{\omrCirc{2}}   \newcommand{\xTwo}{\omrCirc[gray!50]{2}}
\newcommand{\oThree}{\omrCirc{3}} \newcommand{\xThree}{\omrCirc[gray!50]{3}}
\newcommand{\oFour}{\omrCirc{4}}  \newcommand{\xFour}{\omrCirc[gray!50]{4}}
\newcommand{\oFive}{\omrCirc{5}}  \newcommand{\xFive}{\omrCirc[gray!50]{5}}
\newcommand{\oSix}{\omrCirc{6}}   \newcommand{\xSix}{\omrCirc[gray!50]{6}}
\newcommand{\oSeven}{\omrCirc{7}} \newcommand{\xSeven}{\omrCirc[gray!50]{7}}
\newcommand{\oEight}{\omrCirc{8}} \newcommand{\xEight}{\omrCirc[gray!50]{8}}
\newcommand{\oNine}{\omrCirc{9}}  \newcommand{\xNine}{\omrCirc[gray!50]{9}}

\newcommand{\omrDIGITS}{\oZero\oOne\oTwo\oThree\oFour\oFive\oSix\oSeven\oEight\oNine}

%% end of ORM Glyphs


\ifsolutions
\newcommand{\iO}{\refstepcounter{enumii}\expandafter\csname o\Alph{enumii}\endcsname}
\newcommand{\iX}{\refstepcounter{enumii}\expandafter\csname x\Alph{enumii}\endcsname}
\else
\def\iO{\refstepcounter{enumii}\expandafter\csname o\Alph{enumii}\endcsname}
\def\iX{\refstepcounter{enumii}\expandafter\csname o\Alph{enumii}\endcsname}
\fi

\newcommand{\Q}[1]{{\\[1em]{\bf\textit Q#1. }}}

\ifsolutions
     \newenvironment{answer}[1][]
     {\par\medskip 
      \noindent \color{red} }
     { \medskip }
\else
	\usepackage{environ}
	\NewEnviron{answer}{%
    	\par  \medskip   \medskip

	}
\fi



\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
  \hbox{}
  \vspace*{\fill}
  \begin{center}
    This page was intentionally left blank.
  \end{center}
  \vspace{\fill}
  \thispagestyle{empty}
  \newpage
  \if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother

%%
%% start of user-defined preamble
%%

<| if '_latexpreamble' in header  |>
<< header['_latexpreamble']  >>
<| endif |>

%%
%% end of user-defined preamble
%%

\begin{document}
\pagestyle{plain}
\maketitle

\cleardoublepage
\vspace*{-4em}

\ifdefstring{\infomidterm}{true}
{
\begin{minipage}[t]{.6\linewidth}
Student Name: \tabto{3cm} \underline{\hspace{6cm}}\vspace{0.3cm}
Student Number: \tabto{3.5cm} \underline{\hspace{5.5cm}}
\end{minipage}
\begin{minipage}[t]{.4\linewidth}
  Mark your student number below

  \omrDIGITS

  \omrDIGITS

  \omrDIGITS

  \omrDIGITS

  \omrDIGITS
      
  \omrDIGITS
      
  \omrDIGITS
      
  \omrDIGITS
      
\end{minipage}
}{
\begin{minipage}[t]{.6\linewidth}
Exam Number: \tabto{3cm} \underline{\hspace{6cm}}

Seat Number : \tabto{3.5cm} \underline{\hspace{5.5cm}}
\end{minipage}
\begin{minipage}[t]{.4\linewidth}
  Mark your exam number below

  \omrDIGITS

  \omrDIGITS

  \omrDIGITS

  \omrDIGITS

  \omrDIGITS
      
\end{minipage}
}

\vspace{1em}
{\bf 
  All your MCQ answers must be filled in on this answer page. 
}

For {\bf True} or {\bf False} questions, mark \oT or \oF. For
questions with multiple choices, mark all solutions that are correct
(for instance \xA\xB\oC\xD).

\vspace{0.5em}

\begin{multicols}{3}
\begin{enumerate}
<| set letter = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N'] |>
<| for q in questions +|>
\item[{\bf Q.<<loop.index>>}]
<|- if q.type == 'essay' |>
essay question
<|- elif q.type == 'tf' |>
<|-     if q.answer|lower == 'true'    -|>
\ifsolutions\xT\oF\else\oT\oF\fi
<|-     else  -|>
\ifsolutions\oT\xF\else\oT\oF\fi
<|-     endif -|>
<|- elif q.type == 'mc' or q.type == 'ma' |>
<|-   for a in q.choices -|>
<|-     if a.x is defined  -|>
\ifsolutions\x<<letter[loop.index0]>>\else\o<<letter[loop.index0]>>\fi
<|-     else  -|>
\o<<letter[loop.index0]>>
<|-     endif -|>
<|-   endfor |>
<| endif |>
<| endfor |>
\end{enumerate}
\end{multicols}

\cleardoublepage
\ifsolutions\else
\renewcommand{\labelenumii}{(\alph{enumii})}
\renewcommand{\labelenumi}{(\alph{enumi})}
\fi

<| for q in questions |>
<| if q.type == 'essay' |>
\begin{bbquestion}[<<q.marks>>]
<<q.question>>
\end{bbquestion}
\begin{answer}
<<q.answer>>
\end{answer}
<| elif q.type == 'tf' |>
\begin{bbquestion}[<<q.marks>>]
<<q.question>>
  \vspace{1em}
\begin{enumerate}\setlength\itemsep{0.25em}
\ifsolutions  
<|        if q.answer|lower == 'true'    -|>
    \item[\xT] True
    \item[\oF] False
<|-       else          -|>  
    \item[\oT] True
    \item[\xF] False
<|-       endif          |>
\else
    \item[(t)] True
    \item[(f)] False
\fi
\end{enumerate}
\end{bbquestion}

<| elif q.type == 'mc' or q.type == 'ma' |>
\begin{bbquestion}[<<q.marks>>]
<<q.question>>
  \vspace{1em}
<|   if q['cols']|int > 1  |>
\begin{multicols}{<<q['cols']>>}
<|   endif           |>
\begin{enumerate}\ifsolutions\else\renewcommand{\theenumi}{(\alph{enumi})}\fi\setcounter{enumii}{0}\setlength\itemsep{0.25em}
<|-   for a in q.choices |>
\ifsolutions  
<|        if a.x is defined   -|>
    \item[\iX] <<a.x>>
<|-        else          -|>  
    \item[\iO] <<a.o>>
<|-        endif          |>
\else
<|        if a.x is defined   -|>
    \item <<a.x>>
<|-        else          -|>  
    \item <<a.o>>
<|-        endif          |>
\fi

<|-    endfor +|>
  \end{enumerate}
<|   if q['cols']|int > 1  |>
\end{multicols}
<|   endif           |>  
\end{bbquestion}
<| elif q.type == 'matching' |>
\begin{bbquestion}[<<q.marks>>]
<<q.question>>

\begin{tabular}{cc}
<|-   for a in q.choices |>
    \adjustbox{max width=0.45\linewidth}{\vbox{<<a.A>>}} &
	\adjustbox{max width=0.45\linewidth}{\vbox{<<a.B>>}} \\
	  (a) & (1) \\	  
<|-    endfor +|>
  \end{tabular}
\end{bbquestion}
<| endif |>  
<| endfor |>


\begin{center}[oOo]\end{center}


\end{document}
