# How to create an optional argument like the 'correctchoice command in exam document class?

I want to create an alternative to CorrectChoice. That when [answers] command is used it will highlight the correct answer and be printed with the question together. I have seen this command by this link How to box the correct answer in Exam class?. it created a command MyCorrectSmartChoice I am thinking on if the [answers] command will not be included, how will the function(puting the correct answer inside the box) of this particular command be hidden??

example:

\documentclass[answers]{exam}
\begin{document}

\begin{questions}
\question The question is here.

\begin{choices}
\choice one
\MyCorrectSmartChoice two
\choice three

\end{choices}
\end{questions}

\end{document}


Then if the [answers] command will be used, it will be emphasized?

Need some help on this matter. Thanks!

-

The exam class offers a conditional \ifprintanswers which is explained in the exam documentation section 8.5 Changes depending on whether or not solutions are being printed. So you could change the definition of \MyCorrectSmartChoice in the linked question as follows:

\documentclass[answers]{exam}
% \documentclass{exam}

\usepackage{tikz}
\usetikzlibrary{calc,shapes}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\newcommand{\DrawSmartBox}[1][red]{%
\tikz[overlay,remember picture]{
\draw[#1]
($(bl)+(-1.75em,1em)$) rectangle
($(br)+(0.2em,-0.4em)$);}
}

% \MyCorrectSmartChoice:
% #1 optional argument: aspect customization
% #2 mandatory argument: the answer
\newcommand{\MyCorrectSmartChoice}[2][black]{%
\CorrectChoice \tikzmark{bl}#2\tikzmark{br}\DrawSmartBox[#1]%
\else
\CorrectChoice #2%
\fi
}
\CorrectChoiceEmphasis{}

\begin{document}

\begin{questions}
\question What's the question?
\begin{choices}
\choice How should I know?
\MyCorrectSmartChoice[thick,rounded corners,red]{What's $6\times7$?}
\end{choices}
\end{questions}

\end{document}


With answers option:

Without answers` option:

-