8

In responding to how to typeset a Long underscore in LaTeX, I attempted to use a \phantom with \ul, but end up Argument of \makeph@nt has an extra }. So, what is the proper way to use a \phantom command in such a situation.

\documentclass{article}
\usepackage{xcolor}%
\usepackage{soul}%

\newcommand{\UnderlineText}[2][red]{\setulcolor{#1}\ul{#2}}%

\begin{document}
    Signature: \UnderlineText[blue]{Sign here}

    %Signature: \UnderlineText[blue]{\phantom{Sign here}}% Error if un-commented.
\end{document}
Peter Grill
  • 223,288

1 Answers1

10

If you wrap the \phantom{...} in an extra set of curly braces, the code works:

\documentclass{article}
\usepackage{xcolor}%
\usepackage{soul}%

\newcommand{\UnderlineText}[2][red]{\setulcolor{#1}\ul{#2}}%

\begin{document}
    Signature: \UnderlineText[blue]{{\phantom{Sign here}}}
\end{document}
Jake
  • 232,450
  • Yep, did not occur to me to try that. Any idea why that is the case? – Peter Grill Aug 03 '11 at 05:38
  • No, unfortunately not. I assume once the day starts in Europe, the real TeXperts will quickly solve this. – Jake Aug 03 '11 at 05:39
  • 4
    Simply read section 2 of the documentation. It describes what must be protected inside a soul argument and how you can do it. – Ulrike Fischer Aug 03 '11 at 07:55
  • 4
    AFAIK soul reads the content of its macros token (or brace group) by token and so splits the \phantom and its argument apart. It has an internal list of macro to officially support (like the \textxx format macros), but fails on macros unknown to it (it can't know how many arguments they have). Wrapping the whole thing in braces will make soul take it as one unit. However, line breaking might not be done for these (AFAIK soul boxes all single units). – Martin Scharrer Aug 03 '11 at 08:18