My colleague and I have adapted this code from the eqexam
package and used it for fill-in questions in examinations:
\newcommand{\fillin}[3][u]{
%% #1= the box (u=underlined, e=empty, b=boxed) #2= space for the
%% answer, #3= the correct answer
\space
\ifx#1u\let\fillin@Fmt=\underbar%%% by default underlined space
\else\ifx#1e\let\fillin@Fmt=\relax%%% empty space
\else\ifx#1b\let\fillin@Fmt=\fbox%%% box
\fi\fi\fi
\fillin@Fmt{\parbox[b][.8\height][b]{#2}{%
\strut\hfil\fill@ans@color{#3}\hfil}%
}
}
We have tried to have the text of the answer splitted across lines, but it does not work. As in this command you can define the length of the blank space, the problem of the greater space to be filled by hand should be solved.
We will think about the possibility to split text across lines and we will post the solution if find it.
EDIT:
A part of the code missing in my previous answer. I apologize.
Here is a m.w.e. with the complete code:
\documentclass{article}
\usepackage{calc}
\newif \ifteacher
\makeatletter
\ifteacher
\teachertrue
%\teacherfalse
\def\fill@ans@color#1{\bfseries\color{red}{#1}}%%% with solutions
answers are in red by default
\else
\def\fill@ans@color#1{\phantom{#1}}%%% without solutions option -> no
answers
\fi
\newcommand{\fillin}[3][u]{
%% #1= the box (u=underlined, e=empty, b=boxed) #2= space for the
%% answer, #3= the correct answer
\space
\ifx#1u\let\fillin@Fmt=\underbar%%% by default underlined space
\else\ifx#1e\let\fillin@Fmt=\relax%%% empty space
\else\ifx#1b\let\fillin@Fmt=\fbox%%% box
\fi\fi\fi
\fillin@Fmt{\parbox[b][.8\height][b]{#2}{%
\strut\hfil\fill@ans@color{#3}\hfil}%
}
}
\makeatother
\begin{document}
2+4=\fillin{4cm}{6}
\end{document}
If you want teacher version you have to uncomment the \teachertrue command, if you want student version you have to uncomment the other one.
EDIT 2
The switch \teachertrue or \teacherfalse must be put in the preamble. The above code should now work.