[Tex/LaTex] Phantom and line break

line-breaking

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}

Best Answer

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
  {\UL@skip\wd\UL@box \UL@leaders \kern-\UL@skip}%
    \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}

Result or output