# Phantom and line break

I want to make a cloze test using LaTeX. My Idea was to use the \phantom command to produce the space:

Some text \underline{\phantom{some text to complete}} some more text.


Now the problem is that \phantom seems to handle "some text to complete" as one word and does not break lines.

\documentclass{minimal}

\begin{document}

Some text \underline{\phantom{some  text to complete some  text to complete
some  text to complete some  text to complete some  text to complete some    text
to complete some  text to complete}} some more text.

\end{document}

-
Unless you are setting the document in a large size the space created by \phantom will be too small for manual completion. I'd suggest to take a look at the exam package. –  Christian Lindig Apr 17 '11 at 13:05
Thanks, that's a good point. However exam seems to be a documentclass and I don't want to change the documentclass. –  student Apr 17 '11 at 15:07

Neither \underline nor \phantom allow for line breaks because they use the so called restricted horizontal mode, i.e. the same as a \mbox{...}. Your application reminded me about the censor package which is able to remove text and replace it by black bars or underlines. However, it seems also not to support line breaks. The ulem package gives \uline which underlines text in a line-breakable way. You could use it and redefine the internal macro which sets the text to use a phantom box. Note that this does only allows for line breaks at normal spaces and not for hyphenation.

\documentclass{article}
\usepackage[normalem]{ulem}

\makeatletter
\def\UL@putbox{\ifx\UL@start\@empty \else % not inner
\vrule\@width\z@ \LA@penalty\@M
\phantom{\box\UL@box}%
\fi}
\makeatother

\begin{document}

Some text \uline{some text to complete some  text to complete
some  text to complete some  text to complete some  text to complete some    text
to complete some  text to complete} some more text.

\end{document}


-
Thanks, that's great! Is it possible to adjust your solution such that \uline has an optional arguments where you can say that it should make n-times of the space as in your \uline version? –  student Apr 17 '11 at 15:05
@user4011: After thinking about it I don't think so, because this would affect the line breaking again. –  Martin Scharrer Aug 29 '11 at 11:47
Sidebar: The censor package now supports linebreaks through its \blackout command. –  Steven B. Segletes Apr 23 '13 at 14:11

I solved this problem by using the color package to write the phantom lines in white:

\usepackage{color}

\newcommand{\white}[1]{{\textcolor{white}{#1}}}

Some text \underline{\white{some text to complete}} some more text.

-