Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example LaTeX source for mcexam package
\documentclass[twoside]{article}
\usepackage[english]{babel}
% set fonts
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage{microtype}
\usepackage{etoolbox}
\ifdef{\myoutput}{}{\def\myoutput{concept}}
\ifdef{\myversion}{}{\def\myversion{1}}
% mcexams options.
\usepackage[output=\myoutput
,numberofversions=2
,version=\myversion
,seed=1
,randomizequestions=true
,randomizeanswers=true
,writeRfile=true
]{mcexam}
\usepackage[margin=0.95in]{geometry}
% Packages used for special things
\usepackage{framed,booktabs}
% Set headers and footers
\usepackage{fancyhdr,lastpage}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{1pt}
\lfoot{\mctheversion}
\rfoot{Page \thepage\ of \pageref{LastPage}}
% Ensure each question+answers is printed entirely on the same page.
\usepackage{calc}
\renewenvironment{setmcquestion}{\begin{minipage}[t]{\linewidth-\labelwidth}}{\end{minipage}\par}
% question intros should also be printed on the same page.
\renewenvironment{setmcquestioninstruction}
{\begin{minipage}{\textwidth}}
{\end{minipage}}
\usepackage{multicol}
% disable paragraph indenting
\setlength{\parindent}{0cm} % Default is 15pt.
% no extra space between sentences
\frenchspacing
% fix test spacing wonkiness due to grouped questions
\raggedbottom
% less space for true/false questions
\renewenvironment{setmcanswers}{}{}
\setlist[setmcquestions]{label=\mcquestionlabelfmt{*}.
,ref=\mcquestionlabelfmt{*}
,itemsep=0.5\baselineskip
,topsep=1\baselineskip
}
% use Version 1, 2 etc instead of I, II
\renewcommand\mcversionlabelfmt[1]{\arabic{#1}}
\usepackage{array}
\usepackage{xparse}
% Rotation macro
% Rotation: \rot[<angle>][<width>]{<stuff>}
\NewDocumentCommand{\rot}{O{45} O{1em} m}{\makebox[#2][l]{\rotatebox{#1}{#3}}}%
% macro for true/false correct answers
\global\def\qtrue{\begin{mcanswers}[permutenone]\answer[correct]{1}{}\answer{2}{}\end{mcanswers}}
\global\def\qfalse{\begin{mcanswers}[permutenone]\answer{1}{}\answer[correct]{2}{}\end{mcanswers}}
% macro for question intros that list the number of questions
\global\def\numq[#1]{[Questions \the\numexpr\value{setmcquestionsi}+1\relax--\the\numexpr\value{setmcquestionsi}+#1\relax]}
\usepackage{graphicx}
% ensure always one blank page at end
\mcifoutput{exam}{
\AtEndDocument{\ifodd\value{page}
\newpage\thispagestyle{empty}\hbox{\hfill{}This page intentionally left blank.\hfill{}}\newpage\thispagestyle{empty}\hbox{}
\else
\newpage\thispagestyle{empty}\hbox{}
\fi}
}
% custom hyphenation
\hyphenation{al-kap-to-nu-ri-a}
\begin{document}
% Exam preamble stuff - this will be printed on every version
\begin{center}
\bfseries\Huge My Favorite Exam \\
\LARGE
\today
\end{center}
% Show which version is being printed (Concept, Answers, etc.)
\begin{center}\bfseries\Huge\MakeUppercase{\mctheversion}\end{center}
% This only shows on the "Exam" form that students see. So put instructions, etc. here.
\mcifoutput{exam}{
\large\bigskip
\noindent Name: \hrulefill{}\hrulefill{}\hrulefill{}\quad{}Student ID\#: \hrulefill\hrulefill{} \\[.75\baselineskip]
\vfill
\begin{framed} \centering\bfseries\Large No calculators allowed! \end{framed}
\vfill
On your scantron, use a \#2 pencil to:
\begin{enumerate}
\item \textbf{Write and bubble your last name, first name, and student ID\#}
\item \textbf{Write and bubble your exam version}
\end{enumerate}
% ensure that questions don't get printed on this intro page, which annoys students
\cleardoublepage
\renewcommand{\baselinestretch}{1.05}
\normalsize
} % end if exam
%%%%%%%%%%%%%%%%%%%%%%%%
% BEGIN EXAM QUESTIONS %
%%%%%%%%%%%%%%%%%%%%%%%%
\begin{mcquestions}
\question Which of the following numbers is prime? This shows how \texttt{multicol} can be used to format options all on one line.
\begin{multicols}{4}
\begin{mcanswerslist}[ordinal]
\answer 12
\answer 16
\answer[correct] 17
\answer 20
\end{mcanswerslist}
\end{multicols}
\begin{mcquestioninstruction}
\numq[5] Which of the following foods can be eaten on a keto diet? Mark A for True and B for False. This shows how we can use the True/False macros and custom edits to \texttt{mcexam.sty} to produce a compact series of True/False questions.
\end{mcquestioninstruction}
\question Blueberries \qtrue
\question[follow] Eggs \qtrue
\question[follow] Steak \qtrue
\question[follow] Bread \qfalse
\question[follow] Cupcakes \qfalse
\question Which combination of of hexadecimal values is orange? This is an example of some fancy stuff in \texttt{mcexam}. The options below are formatted like a table (using extensive amounts of spacing) and will also be randomized on different exam versions.
\begin{mcanswers}
\bigskip
\begin{minipage}{0.5\textwidth}
\hspace{2.2em}\makebox[4em]{\textbf{Red}}\hfill\makebox[5em]{\textbf{Green}}\hfill\makebox[5em]{\textbf{Blue}}\par
\makebox[1em]{\answernum{1}}\quad\answer[correct]{1}{\makebox[5em]{ff}\hfill\makebox[5em]{aa}\hfill\makebox[5em]{00}}\par
\makebox[1em]{\answernum{2}}\quad\answer{2}{\makebox[5em]{cc}\hfill\makebox[5em]{00}\hfill\makebox[5em]{44}}\par
\makebox[1em]{\answernum{3}}\quad\answer{3}{\makebox[5em]{ff}\hfill\makebox[5em]{ff}\hfill\makebox[5em]{ff}}\par
\makebox[1em]{\answernum{4}}\quad\answer{4}{\makebox[5em]{00}\hfill\makebox[5em]{00}\hfill\makebox[5em]{00}}\par
\makebox[1em]{\answernum{5}}\quad\answer{5}{\makebox[5em]{33}\hfill\makebox[5em]{66}\hfill\makebox[5em]{99}}
\end{minipage}
\end{mcanswers}
\end{mcquestions}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment