3

I am using exam package and want to print solutions conditionally. I can print solutions by using answers option in exam. I can get two lines for answers using \fillwithlines{1.0in} in each question. But this is a very naive approach. I wonder how can I get two lines automatically for answers if I don't want to print solutions. Any help will be highly appreciated.

\documentclass[12pt, addpoints, answers]{exam}
%\documentclass[12pt, addpoints]{exam}

\usepackage{amsmath, amsfonts, amssymb, xhfill, float}
\usepackage[margin=0.5in]{geometry}

\renewcommand{\solutiontitle}{\noindent\textbf{Answer:}\par\noindent}


\linespread{1.4}
\setlength{\topmargin}{-0.2in}

\setlength\linefillheight{0.5in}

\begin{document}

\begin{questions}

\question
Where does XYZ live?

\fillwithlines{1.0in}

\begin{solution}
XYZ lives in home.
\end{solution}

\end{questions}

\end{document}
2

What about using the environment solutionorlines instead of the environment solution?

%\documentclass[12pt, addpoints, answers]{exam}
\documentclass[12pt, addpoints]{exam}

\usepackage{amsmath, amsfonts, amssymb, xhfill, float}
\usepackage[margin=0.5in]{geometry}

\renewcommand{\solutiontitle}{\noindent\textbf{Answer:}\par\noindent}


\linespread{1.4}
\setlength{\topmargin}{-0.2in}

\setlength\linefillheight{0.5in}

\begin{document}

\begin{questions}

\question
Where does XYZ live?

\begin{solutionorlines}[1.0in]
XYZ lives in home.
\end{solutionorlines}

\end{questions}

\end{document}
0

there was a similar question with beamer in normal and handout mode.

I think of the same solution with the {subfiles} package:

You basically create 3 files:


exam-with-answers.tex

\documentclass[12pt, addpoints, answers]{exam}
\usepackage{subfiles}
\begin{document}
\subfile{your-former-main.tex}
\end{document}

exam-without-answers.tex

\documentclass[12pt, addpoints]{exam}
\usepackage{subfiles}
\begin{document}
\subfile{your-former-main.tex}
\end{document}

your-former-main.tex

\documentclass[exam-with-answers.tex]{subfile}
%% ...

you can successfully compile either one. your-former-main.tex and exam-with-answers.tex will result in containing the answeres, exam-without-answers.tex will have no answeres. Plus you get both documents with different names without any additional effort.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.