[Tex/LaTex] Fill in the blank: text wrapping & math mode

inline()text-decorationsulem

I am making notes with blanks to fill in and would like to produce an instructor version with blanks filled in and a student version with blanks unfilled.

I would like a \fillin{ . . . } command that wraps text and allows math. The solution from Create fill-in-the-blank version of a document with ability to toggle blanks on and off works well for wrapping text, but censor does not allow math (or other font switching):

\documentclass{article}
\usepackage{censor}
\censorruledepth=-.2ex
\censorruleheight=.1ex

\begin{document}

\xblackout{this works fine this works fine this works fine this works fine this works fine this works fine this works fine this works fine this works fine this works fine }

\xblackout{this does not work $a+b$ this does not work $a+b$ this does not work $a+b$ this does not work $a+b$ this does not work $a+b$ this does not work $a+b$ this does not work $a+b$ this does not work $a+b$ this does not work $a+b$}

\end{document}

One idea I tried was to use ulem's uline, but color text white for the student version. This works for math mode, but text-wrapping fails:

\documentclass{article}
\usepackage{ulem,xcolor}
\newcommand{\fillin}[1]{\uline{\textcolor{white}{#1}}}

\begin{document}

\fillin{This allows math mode $a+b=c$, but the text-wrapping is broken This allows math mode $a+b=c$, but the text-wrapping is broken This allows math mode $a+b=c$, but the text-wrapping is broken}

\end{document}

Best Answer

Both ulem and soul can achieve what you're after, although it seems that the latter is slightly preferred. In the following examples, texts are colored red only for illustration purposes. Changing the color to white will "hide" the texts.

Code

\documentclass{article}
\usepackage{ulem,xcolor}
\usepackage{soul}

\newcommand\ulemfill{\bgroup\color{red}\markoverwith % change red to white to hide text
{\textcolor{black}{\rule[-.6ex]{2pt}{.5pt}}}\ULon}   % underline color for ulem

\setulcolor{black}                                   % underline color for soul
\newcommand{\soulfill}[1]{\textcolor{red}{\ul{#1}}}      % change red to white to hide text

\begin{document}

\ulemfill{This allows math mode $a+b=c$, but the text-wrapping is broken This allows math mode $a+b=c$, but the text-wrapping is broken This allows math mode $a+b=c$, but the text-wrapping is broken}

\vspace{20pt}

\soulfill{This allows math mode $a+b=c$, but the text-wrapping is broken This allows math mode $a+b=c$, but the text-wrapping is broken This allows math mode $a+b=c$, but the text-wrapping is broken}

\end{document}

Output

enter image description here