# Problem in documentclass(exam)

I am writing an MCQ test using exam class. The main.tex is under:

\documentclass[12pt,a4paper]{exam}
\usepackage{amsmath,amsthm}
\usepackage{ifthen,amsfonts,amssymb,dsfont}
\usepackage{etoolbox,multicol}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{geometry}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{enumitem,kantlipsum}
\usepackage[dvips]{graphicx,color}
\usepackage{verbatim, pstricks,ulem}
\usepackage{syntonly}
\newcommand{\newmatrix}[2]{\left(\begin{array}{#1} #2\end{array}\right)}

{%
}%
{%
\bigbreak
\egroup
}

}

{%
}%
{%
\bigbreak
\egroup
}

\ifthenelse{\equal{#6}{}}{}{
}}

\setlength\parindent{0pt}

\newcommand{\fourch}[6]{
\par
\begin{tabular}{*{4}{@{}p{0.23\textwidth}}}
(a)~#1 & (b)~#2 & (c)~#3 & (d)~#4
\end{tabular}
}

\newcommand{\twoch}[6]{
\par
\begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
(a)~#1 & (b)~#2
\end{tabular}
\par%\vspace{4pt}
\begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
(c)~#3 & (d)~#4
\end{tabular}
}

\newcommand{\onech}[6]{
%\par
\begin{tabular}{@{}p{0.04\textwidth}@{}p{0.91\textwidth}}
(a) & #1
\end{tabular}\vspace{2pt}
\begin{tabular}{@{}p{0.04\textwidth}@{}p{0.91\textwidth}}
(b) & #2
\end{tabular}\vspace{2pt}
\begin{tabular}{@{}p{0.04\textwidth}@{}p{0.91\textwidth}}
(c) & #3
\end{tabular}\vspace{2pt}
\begin{tabular}{@{}p{0.04\textwidth}@{}p{0.91\textwidth}}
(d) & #4
\end{tabular}

}

\newlength\widthcha
\newlength\widthchb
\newlength\widthchc
\newlength\widthchd
\newlength\widthch
\newlength\tabmaxwidth

\setlength\tabmaxwidth{0.96\textwidth}
\newlength\fourthtabwidth
\setlength\fourthtabwidth{0.25\textwidth}
\newlength\halftabwidth
\setlength\halftabwidth{0.5\textwidth}

\newcommand{\choice}[6]{%
\settowidth\widthcha{AM.#1}\setlength{\widthch}{\widthcha}%
\settowidth\widthchb{BM.#2}%
\ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%
\settowidth\widthchb{CM.#3}%
\ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%
\settowidth\widthchb{DM.#4}%
\ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%

\ifdim\widthch>\halftabwidth
\onech{#1}{#2}{#3}{#4}{#5}{#6}
\else\ifdim\widthch<\halftabwidth
\ifdim\widthch>\fourthtabwidth
\twoch{#1}{#2}{#3}{#4}{#5}{#6}
\else
\fourch{#1}{#2}{#3}{#4}{#5}{#6}
\fi\fi\fi}

\newcommand{\mcq}[8]{
\question #2
\choice{#3}{#4}{#5}{#6}{#7}{#8}
}

\def\blankpage{%
\clearpage%
\thispagestyle{empty}%
\null%
\clearpage}

\begin{document}
\begin{questions}
\mcq{245}{Let $A$ be a symmetric matrix of order $n$ and $B$ be a skew-    symmetric matrix of order $n$. Then which one of the following is a skew-symmetric matrix?}{$A^{2}$}{$B^{2}$}{$AB+BA$}{$AB-BA$}{c}{}{}

\mcq{248}{A square matrix is a diagonal matrix if and only if it is}{upper triangular}{lower triangular}{both upper triangular and lower triangular}{none of these}{c}{}{}

\mcq{249}{Let $A$ be a non-singular matrix of order $3$. Then the rank of matrix $A^{2018}$ is}{$1$}{$2$}{$3$}{$9$}{c}{Note that $A^{2018}$ is a non-singular matrix of order $3$. Hence rank $(A^{2018})=3$.}{}

\mcq{250}{If $A=\newmatrix{ccc}{0 & 1 & 0\\0 & 0 & 1\\1 & 0 & 0}$, then rank of the matrix $A+A^{2}+A^{3}$ is}{$1$}{$2$}{$3$}{none of these}{a}{Note that $A+A^{2}+A^{3}=\newmatrix{ccc}{1 & 1 & 1\\1 & 1 & 1\\1 & 1 & 1}$. Hence rank $(A+A^{2}+A^{3})=1$}{}
\end{questions}
\begin{center}
Space for rough work
\end{center}
\newpage
\bigskip
\bigskip
\setcounter{page}{1}
\begin{center}
\begin{multicols}{6}
\end{multicols}
\end{center}

\bigskip
\Huge{Hint/Explanation of Selected Problems:}
\bigskip\bigskip
\end{document}


This is not working in overleaf. But if I change \mcq{250} in the following way then the program is working in overleaf.

\mcq{250}{If $A=\newmatrix{ccc}{0 & 1 & 0\\0 & 0 & 1\\1 & 0 & 0}$, then rank of the matrix $A+A^{2}+A^{3}$ is}{$1$}{$2$}{$3$}{none of these}{a}{Note that $A+A^{2}+A^{3}=$. Hence rank $(A+A^{2}+A^{3})=1$}{}


• Welcome to TeX.SE! I am sorry, I do not understand your question: "When I take these files as an input in main.tex, it is working properly." and "When I take the file testdata2.tex as an input in the main file main.tex, then it is not working." seem to contradict each other. Notice that generally people do not follow such links here. (When I tried, the web page asked me to join, which I do not want to do.) Please consider posting a minimal example showing the problem. – marmot Sep 17 '18 at 3:18
• Welcome. Your link gives "Restricted, sorry you don't have permission to load this page."... And also a MWE (tex.meta.stackexchange.com/q/228/120578) would make your question helpful to this community... A link to overleaf that leads to a project that will possibly deleted later makes the question non-useful to anyone but you. – koleygr Sep 17 '18 at 3:47
• You always can edit your question and add some code (at least your main file) here... – koleygr Sep 17 '18 at 4:56

Just add \protect command before the last \newmatrix in \mcq{250} ,like this:

\mcq{250}{If $A=\newmatrix{ccc}{0 & 1 & 0\\0 & 0 & 1\\1 & 0 & 0}$,
then rank of the matrix $A+A^{2}+A^{3}$ is}
{$1$}{$2$}{$3$}{none of these}{a}
{Note that $A+A^{2}+A^{3}=\protect\newmatrix{ccc}{1 & 1 & 1\\1 & 1 & 1\\1 & 1 & 1}$.
Hence rank $(A+A^{2}+A^{3})=1$}{}


and that should do it!

• Thanks a lot @ Hafid Boukhoulda. It is now working fine. Please let me know how can I shuffle the questions in exam class. I am really new in exam class. – Arindam Bandyopadhyay Sep 17 '18 at 17:28
• Hi @Arindam, if the answer solves your problem please consider mark it as accepted. If you have a new question you should use the Ask question button (top right) and post a new question. This will help others who may face the same problem. thanks! – Hafid Boukhoulda Sep 17 '18 at 21:19