For a multiple choice exam, I'm using the mcexam package. There does not seem to be a command that allows me to print the total number of questions. Is there a way I can define such a command? E.g.:
The total number of questions in this exam is: \numquestions
This command is defined for the regular exam document class. I tried adding this to my preamble:
\newcommand{\numquestions}{\mc@totalNumberOfQuestions}
but this gives me an undefined control sequence.
Here's a small example. It won't compile due to the \numquestions command. Notice that this example is a trimmed version of the example.tex file shipped with mcexam:
\documentclass[a4paper]{article}
\usepackage[output=exam
,numberofversions=4
,version=1
,seed=1
,randomizequestions=true
,randomizeanswers=true
,writeRfile=false
]{mcexam}
% Packages used for special things
\usepackage{tikz,framed}
% 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}
\makeatletter
\newcommand{\numquestions}{\mc@totalNumberOfQuestions} %DOES NOT WORK
\makeatother
\begin{document}
\begin{center}
\bfseries\LARGE Midterm Exam
\end{center}
\begin{framed}
\centering\bfseries\Large\MakeUppercase{\mctheversion}
\end{framed}
\mcifoutput{concept,exam}{
\bigskip
\noindent Name: \dotfill\\[.5\baselineskip]
\noindent Student Number: \dotfill\\[.5\baselineskip]
\noindent Program: \dotfill
\vspace{2\baselineskip}
\noindent\textbf{Instructions:}
\begin{itemize}[nosep]
\item This exam has \numquestions questions. %THIS THROWS AN UNDEFINED CONTROL SEQUENCE ERROR
\end{itemize}
}
\begin{mcquestions}
\question What is the color of the sky?
\begin{mcanswerslist}[fixlast]
\answer[correct] blue
\answer green
\answer red
\answer yellow
\answer none of the above
\end{mcanswerslist}
\begin{mcexplanation}
If you look up to the sky and there are no clouds, you'll see it is blue.
\end{mcexplanation}
\begin{mcnotes}
This question had a large proportion of good answers last year.
\end{mcnotes}
\question Which figure is a square?
\begin{mcanswers}
\begin{tabular}{@{}cccc}
\answer{1}{\tikz{\draw (-0.66,0)--(0.66,0)--(0,1)--cycle;}}&
\answer{2}{\tikz{\draw (0,0)--(2,0)--(2,1)--(0,1)--cycle;}}&
\answer[correct]{3}{\tikz{\draw (0,0)--(1,0)--(1,1)--(0,1)--cycle;}}&
\answer{4}{\tikz{\draw (0,0) circle[radius=0.5];}}\\
\answernum{1}&\answernum{2}&\answernum{3}&\answernum{4}\\
\end{tabular}
\end{mcanswers}
\end{mcquestions}
\end{document}

mcexam; can you please add a minimal example to play with? – egreg May 18 '18 at 14:55\makeatletter/\makeatotherat the appropriate places? – Teepeemm May 18 '18 at 14:59