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'm trying to find a way of replacing part of text with a horizontal line. I'd like it to behave like the phantom command which replaces the text with an empty box of the correct width (and height), but instead put a horizontal line through the box.

As a specific example, I'm seeking something like a \phantomdash command, where adding it to text in this manner

Lorem ipsum dolor sit amet, \phantomdash{consectetuer adipiscing} elit...

would replace "consectetuer adipiscing" with a horizontal line of the width of the argument "consectetuer adipiscing".

Question: Is there a command for this already? If not, what is a way to achieve this?

share|improve this question

3 Answers 3

up vote 6 down vote accepted

censor can help in this regard:

enter image description here

\documentclass{article}
\usepackage{censor}% http://ctan.org/pkg/censor
\setlength{\censorruledepth}{.5ex}
\setlength{\censorruleheight}{.4pt}
\let\phantomdash\xblackout
\begin{document}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit\ldots

Lorem ipsum dolor sit amet, \phantomdash{consectetuer adipiscing} elit\ldots

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse eget pharetra nisi, at cursus orci. Fusce ipsum justo, \ldots

Lorem ipsum dolor sit amet, consectetur adipiscing elit. \phantomdash{Suspendisse eget pharetra} nisi, at cursus orci. Fusce ipsum justo, \ldots
\end{document}
share|improve this answer
    
Thanks for that (this worked for me). And thanks for the other answers too! –  Rebecca J. Stones May 1 at 2:07
\documentclass{article}
\usepackage[normalem]{ulem}
\newcommand\phantomdash[1]{%
    \uline{\phantom{#1}}%
}
\begin{document}
  Lorem ipsum dolor sit amet, \phantomdash{consectetuer adipiscing} elit...
\end{document}

enter image description here

You can move the line up if you want so:

\documentclass{article}
\usepackage[normalem]{ulem}
\newcommand\phantomdash[1]{%
    \setlength\ULdepth{-0.5ex}
    \uline{\phantom{#1}}%
}
\begin{document}
  Lorem ipsum dolor sit amet, \phantomdash{consectetuer adipiscing} elit...
\end{document}
share|improve this answer

I write a lot of documents where I create blanks for answers on quizzes and then fill in the blanks for an answer key or solution sheet. Here's the sort of approach I take to this.

\documentclass{article}

\makeatletter
\newif\ifhideanswers
\hideanswerstrue
\newlength\ae@tmp@length
\newcommand\phantomdash[1]{%%
  \ifhideanswers
    \settowidth\ae@tmp@length{#1}%%
    \rule[-0.25ex]{\ae@tmp@length}{0.4pt}%%
  \else
    #1%%
  \fi}

\makeatother
\begin{document}

What is the antipode of the north pole?  \phantomdash{the south pole}.

\hideanswersfalse
What is the antipode of the north pole?  \phantomdash{the south pole}.

\end{document}

enter image description here

This approach works fairly well as long as you're not intending to underline long strings of text. In particular, if you're not worried about the text to be hidden breaking across lines, then I find this to be a decent enough approach. If you need the text to break across lines, then this approach is not so good.

Also, I don't like having to open and close file to rewrite just one line --- inevitably I accidentally delete or add something I don't want, particularly when I'm in a hurry. So, I usually do some kind of test on the existence of a an outside hidden file to determine whether the flag should be set. For example I might have something along the following lines in my preamble:

 \IfFileExists{./.design/hide.answers.true}{\hideanswerstrue}{\hideanswersfalse}
share|improve this answer

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.