Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
1  
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
1  
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
add comment

2 Answers 2

up vote 20 down vote accepted

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

share|improve this answer
    
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
add comment

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.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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