# Mulitple choice question in Exercise package

I am creating an assignment for students that would contain some several chapters with theory, exercise and solution. I want to create multiple choice questions using exercise package of latex. I believe this package does not directly support MCQs. I have come across a few pieces of the code that I have combined.

My aim is to create MCQs with one or more than one correct answers such that all answers along with explanations and analysis should appear at the end of the chapter.

If someone suggest other packages/methods, it would be fine too.

\documentclass[a4paper]{amsbook}
\usepackage[margin=1in]{geometry}
\usepackage{mathptmx}
\usepackage[cmintegrals, cmbraces]{newtxmath}
\usepackage{hyperref}% you must load it before the exercise package
\usepackage{environ}

\newlength{\choiceslen}
\newif\ifshowcorrect
\newcounter{choices}
\newcommand{\choicefinal}[1]{%
\ifnum\value{choices}>0 \hfill\fi\egroup
\hspace{0pt}%
\hbox to\choiceslen
\bgroup
\stepcounter{choices}%
\ifcase#1\relax
(\Alph{choices})%
\else
\ifshowcorrect
\expandafter\bfseries
\fi
{(\Alph{choices})}%
\fi\space
}
\newcommand{\choicetemp}[1]{%
\stepcounter{choices}%
\space(\Alph{choices})\cr
}

\NewEnviron{choices}{%
\setcounter{choices}{0}%
\let\choice\choicetemp
\settowidth{\choiceslen}{\vbox{\halign{##\hfil\cr\BODY\crcr}}}
\ifdim\choiceslen>.5\textwidth
\setlength{\choiceslen}{\textwidth}%
\else
\ifdim\choiceslen>.25\textwidth
\setlength{\choiceslen}{.5\textwidth}%
\else
\setlength{\choiceslen}{.25\textwidth}%
\fi
\fi
\let\choice\choicefinal
\setcounter{choices}{0}%

\begin{flushleft}
\bgroup\BODY\hfill\egroup
\end{flushleft}
}

\newcommand{\shorthandchoice}{%
\let\oldchoice\choice
\renewcommand{\choice}{\oldchoice{0}}
\def\correctchoice{\oldchoice{1}}
}
\parindent 0pt

\begin{document}
\begin{Exercise}[label={mylabel}]
\showcorrecttrue
\begin{choices}
\correctchoice apple
\choice banana
\correctchoice orange
\choice pear
\end{choices}
\end{Exercise}
7

\begin{ExerciseList}
\Exercise What is the value of $\pi$  \showcorrecttrue
\begin{choices}
\correctchoice apple
\choice banana
\correctchoice orange
\choice pear
\end{choices}
\Exercise What is the value of $e$
\end{ExerciseList}
\clearpage
\begin{center}
\end{center}
\newpage % I've added a new page only to clearly show the hyperlink. Of course, you don't need it in your document.
\end{document}


I'm not sure this is what you want to achieve, but you could use tasks package.

\documentclass[a4paper]{amsbook}
\usepackage[margin=1in]{geometry}
\usepackage{mathptmx}
\usepackage[cmintegrals, cmbraces]{newtxmath}
\usepackage{hyperref}% you must load it before the exercise package
counter-format = {(tsk[A])},
label-width=1.4em
}

\begin{document}
\chapter{Exercises}
\begin{Exercise}[label={mylabel}]
\end{Exercise}
\ref{correctchoice} 7
\begin{Exercise}[label={mysecondlabel}]
\end{Exercise}
\ref{apple} apple or \ref{orange} orange
\begin{Exercise}[label={mythirdlabel}]
What is the value of $\pi$? (To see the answer click here: \refAnswer{\ExerciseLabel})
\end{Exercise}