1

@Martin Scharrer suggested me the following amazing solution to make cloze texts: https://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.).
4
  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

  • @student Switch \ifulphantom added that enables/disables the phantom versions of the macros from package ulem. – Heiko Oberdiek Oct 30 '12 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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