# 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
• @MartinScharrer Hi, MartinScharrer . Your solution is really power. But could you please explain the macro part a little? I saw no uline in your macro, why it will affect uline? – user15964 May 28 '16 at 4:58
• @user15964: It's simple: The \uline uses \UL@putbox internally. I just analyzed \uline to discover its internal behavior. This way I don't have to recreate the whole complex macro, but can rely on the existing one. – Martin Scharrer May 31 '16 at 18:50

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.

• My lecture notes (provided as PDF) appear to be done like this (with blanks to fill in) and you can see what's in the blanks just by selecting the white text. That's harmless, since the fully-filled in notes get released a week or so after the lecture, but if you gave students a test in PDF format they would be able to see the answers, which isn't ideal. – GKFX Feb 27 '18 at 23:41