1

I am using exam class to prepare a question bank and I wanted to mark the source of the question(that is from where I have taken) at the end of the question.

How to achieve this?

MWE:

\documentclass[11pt,a4paper,addpoints]{exam}
\renewcommand{\baselinestretch}{1.1}
\oddsidemargin 0in \evensidemargin 0in \topmargin 0in \textheight
9.2in \textwidth 6.5in
%\hoffset -1in
%\voffset -1in
%\evensidemargin 14pt
\usepackage{amsmath,amsthm,amsfonts,amssymb,tikz,}


%%%---------------For Title drop

\usepackage{,titling}
\setlength{\droptitle}{-1in}
\posttitle{\par\end{center}}
\pagestyle{headandfoot} 
\rfoot{\iflastpage{}{\thepage}}
\cfoot{\iflastpage{$\maltese\maltese\maltese \maltese
    \maltese$}{}} 
\pointsinrightmargin

%    command name
\newcommand{\cn}[1]{{\protect\ntt\bslash#1}}
\hfuzz1pc % Don't bother to report overfull boxes if overage is < 1pc

\newbox\allanswers
\setbox\allanswers=\vbox{}

\newenvironment{answer}
{%
\global\setbox\allanswers=\vbox\bgroup
\unvbox\allanswers
}%
{%
\bigbreak
\egroup
}

\newcommand{\showallanswers}{\twocolumn{    
    \begin{center}
        \large{\textbf{Question Bank\\ Answer key\\\hrule height 1pt}}
    \end{center}        \par\unvbox\allanswers}}


\newcommand*{\getanswer}[5]{%
\ifthenelse{\equal{#5}{a}}
{\begin{answer}\thequestion. (a)~#1\end{answer}}
{\ifthenelse{\equal{#5}{b}}
    {\begin{answer}\thequestion. (b)~#2\end{answer}}
    {\ifthenelse{\equal{#5}{c}}
        {\begin{answer}\thequestion. (c)~#3\end{answer}}
        {\ifthenelse{\equal{#5}{d}}
            {\begin{answer}\thequestion. (d)~#4\end{answer}}
            {\begin{answer}\textbf{\thequestion. (#5)~Invalid answer 
                        choice.}\end{answer}}}}}
}

\setlength\parindent{0pt}
%usage \choice{ }{ }{ }{ }
%(A)(B)(C)(D)
\newcommand{\fourch}[5]{
\par
\begin{tabular}{*{4}{@{}p{0.23\textwidth}}}
    (a)~#1 & (b)~#2 & (c)~#3 & (d)~#4
\end{tabular}
\getanswer{#1}{#2}{#3}{#4}{#5}
}

%(A)(B)
%(C)(D)
\newcommand{\twoch}[5]{
\par
\begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
    (a)~#1 & (b)~#2
\end{tabular}
\par
\begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
    (c)~#3 & (d)~#4
\end{tabular}
\getanswer{#1}{#2}{#3}{#4}{#5}
}

%(A)
%(B)
%(C)
%(D)
\newcommand{\onech}[5]{
\par
(a)~#1 \par (b)~#2 \par (c)~#3 \par (d)~#4
\getanswer{#1}{#2}{#3}{#4}{#5}
}

\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}[5]{%
\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<\fourthtabwidth
\fourch{#1}{#2}{#3}{#4}{#5}
\else\ifdim\widthch<\halftabwidth
\ifdim\widthch>\fourthtabwidth
\twoch{#1}{#2}{#3}{#4}{#5}
\else
\onech{#1}{#2}{#3}{#4}{#5}
\fi\fi\fi}
%\renewcommand{\questionlabel}{}
%\renewcommand\partlabel{\Alph{partno}.}
\makeatletter
\def\vhrulefill#1{\leavevmode\leaders\hrule\@height#1\hfill \kern\z@}
\makeatother
\begin{document}


\begin{center}
    \large{\textbf{Question Bank} }
\end{center}    

    \section{Linear Algebra}
    \begin{questions}       
    \question[MU2017] What are all the subspaces of $\mathbb{R},\mathbb{R}^2,\mathbb{R}^3$?

    \question Which of the following matrix is/are diagonalizable?
    \choice{$\left(\begin{array}{cc}
        1&0\\
        0&1
        \end{array}\right)$
    }{$\left(\begin{array}{cc}
        1&1\\
        0&1
        \end{array}\right)$}{$\left(\begin{array}{cc}
        1&1\\
        1&0
        \end{array}\right)$}{$\left(\begin{array}{cc}
        1&1\\
        1&1
        \end{array}\right)$}{×}



\question[NEST2015] There are 10 black balls in a box. A person picks 5 balls from the box, paints them white
and puts them back into the box. Now the person picks 5 balls from the box at random. The
probability that exactly 3 of these 5 balls are white is 
\choice{$\frac{25}{126}$}
{$\frac{3}{10}$}
{$\frac{25}{63}$}
{$\frac{50}{63}$}{c}

\question[NEST2015] For three arbitrary real numbers $ r, s, t $ the mathematical identity is
\choice{  $(\min\{r,s,t\})^3 = \min \{ r^3, s^3, t^3\}$}
{  $(\min\{r,s,t\})^2 = \min \{ r^2, s^2, t^2\}$}
{  $|\min\{r,s,t\}| = \min \{ |r|, |s|, |t|\}$}
{$\sin(\min{r, s, t}) = \min{\sin r, \sin s, \sin t}$} {a}

    \question 
    %\vskip 1in \centering{\large\decotwo\decofourleft\floweroneright $~~All ~~The~~ Best~~$\floweroneleft\decofourright\decotwo}
\end{questions}
\showallanswers % Phil Hirschorn
%\setcounter{page}{1}
%\cfoot{\iflastpage{$\maltese\maltese\maltese \maltese \maltese$}{\thepage}} \rfoot{}
\end{document}

enter image description here

  • The texts whichever I have written in the points place, (for example, \question[NEST2015]), prints the same about 5 times just above the question.
  • A nd more over I get an error if I include some text instead of numbers in the first question.

Something's wrong--perhaps a missing \item. \question W

  • For what I can see from your MWE, is that you didn't redefine \question which is essentially \item. Now \question takes an optional number which is the points given to a question. Using a non-number will probaply break things. If you change strings like MU2017into a number the errors disappear. – Jesse op den Brouw Jul 26 '18 at 6:53
  • Is it possible to redefine \quetion and post as an answer?? @JesseopdenBrouw – David Jul 26 '18 at 6:56
  • A quick solution is to use \titledquestion. It has an optional parameter which can be printed at the end of the question like this: \titledquestion{MU2017}[10] What are all the subspaces of $\mathbb{R},\mathbb{R}^2,\mathbb{R}^3$? \par From exam: \thequestiontitle – Jesse op den Brouw Jul 26 '18 at 8:37
  • @JesseopdenBrouw I have tried this solution and somehow, I dont know why, it didnt serve what it supposed to. – David Jul 26 '18 at 9:28
  • Are you running TexLive 2018? Maby you have to update the exam class file. – Jesse op den Brouw Jul 26 '18 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.