# Fill the blank type of text in non exam document

I want to make a fill the blank type of text in a non-exam document. Here the desired result that I want:

Let A be a subset of R, A called measurable set if m*(...) = ........, for all .... in R


I know that it can be accomplished by using examdesign class. But I don't want to use another class just for this task.

Here my attempt to create the example above.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
Let $A$ be a subset of $\mathbf{R}$, $A$ called measurable set
if $m^*(\ldots) = \ldots \ldots \ldots, \text{ for all } \ldots \ldots \text{ in } \mathbf{R}$.
\end{document}


But the solution that I want is using something like \blank{some text} that will be substituted with dots.

Extra: the dots must longer than the substituted text.

Hence, I can write:

if $m^*(\blank{B}) = \blank{m^*(A \cap B) + m^*(A \cap B^c)} \text{ for all } \blank{B} \text{ in } \mathbf{R}$.


How do I accomplish this?

-
and would you like the 'blanked' letters to appear when showing solutions? –  long tom May 6 '13 at 10:15

\documentclass{article}
\usepackage{amsmath}

\def\blank#1{\setbox0\hbox{$#1$}\hbox to \wd0{\dotfill}}

\begin{document}

if $m^*(\blank{B}) = \blank{m^*(A \cap B) + m^*(A \cap B^c)} \text{ for all } \blank{B} \text{ in } \mathbf{R}$.

\end{document}

-

The command \mdotfill draws some dotted line that has a width equal to the width of its argument plus 1em (as was required in the question); using the optional argument, you can increase the extra length by a desired amount:

\documentclass{article}
\usepackage{amsmath}

\DeclareMathOperator{\mes}{m}

\newlength\mylen
\newcommand\mdotfill[2][1em]{%
\settowidth\mylen{$#2$}

\begin{document}

$\mes^*(A \cap B) + \mes^*(A \cap B^c)$

\mdotfill{\mes^*(A \cap B) + \mes^*(A \cap B^c)}

\mdotfill[2em]{\mes^*(A \cap B) + \mes^*(A \cap B^c)}

\end{document}


-

I'm partial to readability' ;)

\documentclass{article}
\usepackage{amsmath}

\newlength{\blankwidth}
\newcommand{\blank}[1]{%
\ifmmode\settowidth{\blankwidth}{\ensuremath{{#1}{#1}{#1}}}%
\else\settowidth{\blankwidth}{{#1}{#1}{#1}}%
\fi
\makebox[\blankwidth]{\dotfill}}

\begin{document}
if $m^*(\blank{B}) = \blank{m^*(A \cap B)} + m^*(A \cap B^c) \text{ for all } \blank{B} \text{ in } \mathbf{R}$.
\end{document}


-
Also note that this require no extra packages. –  Sean Allred Apr 24 '13 at 13:42

I modified some commands from the censor package, using underlining, instead of dots. I modified my answer so that the \censor command is for arguments in text mode and the \censor* command is for arguments in math mode. The rule denote by \extra (currently 1ex long) is the length added to the argument that you requested.

\documentclass{article}
\usepackage{pbox}
\usepackage{amsmath}
\def\extra{\rule{1ex}{0ex}}
\makeatletter
\newcommand\censor{\@ifstar{\@cenmath}{\@centext}}
\newcommand\@cenmath[1]{%
\protect\rule[-.3ex]{\widthofpbox{\extra$#1$}}{0.1ex}}
\newcommand\@centext[1]{%
\protect\rule[-.3ex]{\widthofpbox{\extra#1}}{0.1ex}}
\makeatother
\begin{document}

The answer is 1ex longer than \censor{forty two}.

if $m^*(\censor*{B}) = \censor*{m^*(A \cap B) + m^*(A \cap B^c)} \text{ for all } \censor*{B} \text{ in } \mathbf{R}$.

\end{document}


-

This should be enough: \def\blank{\makebox[2cm]{\dotfill}}. Usage: $A$ \blank $B$. I think that more space, then originally, is needed, so the suggested difference. The other version: \def\blank#1{\makebox[#1]{\dotfill}}.

-