1. Measuring total height of a paragraph :
Hello I'm trying to draw a black box of same height and width of a paragraph with several lines. For this I need to know the size of paragraph and I'm using the following function:
\documentclass{article}
\newlength{\mytextheight}
\newsavebox{\mytext}
\newcommand{\TestHeight}[1]
{
\savebox{\mytext}{#1}
\settoheight{\mytextheight}{\usebox{\mytext}}
{#1}
Height of Text: \the\mytextheight\\
}
\begin{document}
\TestHeight{This is sample text.}
\TestHeight{\Large This is larger text.}
\TestHeight{
This is sample text with multiple lines.\\
This is the second line.
The height is the same height as with one single line !! ?? \\
settoheight is very bad...
}
\end{document}
As you can see after testing, the height is not at all the good height (same heights for both single line and several lines). -> How to really measure this ?
2. Replacing the paragraph by a black rectangle of same dimensions at same position
After we got the good height how to create a tikz macro that replaces the text the paragraph by a black rectangle with exact the same dimensions (height, width) at the same position ? I tried this macro but according to what is explained above it obviously doesn't work as the total height is not good :
\usepackage{tikz} %to be used with package below:
\newlength\heighthide
\newlength\widthhide
\newcommand\hide[1]{%
\settoheight{\heighthide}{#1}%
\settowidth{\widthhide}{#1}%
\tikz{\node[inner sep=0pt,rectangle,draw,
text height=\heightconf,
text width=\widthconf,
fill=black]{};}
}
Thanks in advance for help.

censorpackage. Perhaps it might be what you are looking for (not for measuring, but for replacing text with black box). – Steven B. Segletes Aug 05 '14 at 09:47\documentclass{article} \usepackage{censor} \begin{document} There are several lines\\ Let's say 3 lines\\ I want to hide with \verb|censor| command.\\ \censor{ There are several lines\\ Let's say 3 lines\\ I want to hide with \verb|censor| command.\\} The black rectangle above has not the good dimensions\\ (multi lines not supported ?) \end{document}http://s1.postimg.org/d0avbkudr/censortest1.jpg and the proof here: https://www.writelatex.com/1321672jpytkm – jyloup Aug 05 '14 at 14:48\blackouti's a little bit better, but there is still alignment problems : `\documentclass{article} \usepackage{censor} \usepackage{listings} \lstset{frame=single,escapechar=ç} \begin{document}There are several lines\ Let's say 3 lines\ I want to hide with censor command.\
\blackout{ There are several lines\ Let's say 3 lines\ I want to hide with censor command.\}
\begin{lstlisting}
a=b for =i do a=b end ç\blackout{for =i do a=b end}ç \end{lstlisting}
The hidden words are not really at the good place. \end{document}` https://www.writelatex.com/1321772hdzqfr
– jyloup Aug 05 '14 at 15:19\documentclass{article} \usepackage{censor,lipsum} \begin{document} \setbox0=\vbox{\lipsum[1-2]}\box0 \clearpage\setbox0=\vbox{\lipsum[1-2]}\noindent\censorbox{\box0}\end{document}. I also see you trying to use it within listings, but I doubt that part of it will work. Also, I use a\vboxin this example, but an\hboxcould be used if the item does not span the full\textwidth. – Steven B. Segletes Aug 05 '14 at 17:36phantomI think). How to make the hidden part black or another color ? About your comment above I really don't understand plain Tex language so it's not really clear for me at this time if there is no a complete testing code example. Thanks anyway for your help. – jyloup Aug 05 '14 at 20:22