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.

@Martin Scharrer suggested me the following amazing solution to make cloze texts: http://tex.stackexchange.com/a/16004/4011

\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}

Now I have some follow up questions about this approach:

  1. How can I adjust this such that I can choose all the "underline styles" offered by the ulem package \dotuline, \dashuline, \uwave and\uuline?
  2. How can I adjust the vertical space between the phantom text and the underline?
  3. Is it possible to get a normal working version of \uline at the same time? (Call it for example \Uline, \Uuline etc.).
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted
  1. Just use them.

  2. \setlength{\ULdepth}{...}

  3. The following example adds the switch \ifulphantom that can be set to enable or disable the phantom version for the macros of package ulem.

Full example:

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

\makeatletter
\@ifdefinable\UL@putbox@original{%
  \let\UL@putbox@original\UL@putbox
  \def\UL@putbox@phantom{%
    \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
  }%
  \newif\ifulphantom
  \renewcommand*{\UL@putbox}{%
    \ifulphantom
      \expandafter\UL@putbox@phantom
    \else
      \expandafter\UL@putbox@original
    \fi
  }%
}
\makeatother

\usepackage{parskip}

\begin{document}

\ulphantomtrue

\begingroup
  \setlength{\ULdepth}{0pt}

  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.

  \setlength{\ULdepth}{1ex}

  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.
\endgroup

Some text \uuline{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.

Some text \uwave{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.

\ulphantomfalse

\begingroup
  \setlength{\ULdepth}{0pt}

  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.

  \setlength{\ULdepth}{1ex}

  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.
\endgroup

Some text \uuline{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.

Some text \uwave{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

share|improve this answer
    
@student Switch \ifulphantom added that enables/disables the phantom versions of the macros from package ulem. –  Heiko Oberdiek Oct 30 '12 at 15:27
    
Thanks, works great! –  student Oct 30 '12 at 16:06
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.