REVISED SOLUTION
With the recent changes in the censor
package to incorporate a tokcycle
-based cycle to censor the tokens, the original approach given below requires revision...in fact, it becomes much simpler.
Math censoring can occur with \mblackout
(for character by character censoring) or with \mcensor
(block underlining).
\documentclass{article}
\usepackage[none]{hyphenat}
\usepackage{censor}
\usepackage{xcolor}
\usepackage{stackengine}
\usepackage{scalerel,lipsum}
\censorruledepth=-.25ex
\censorruleheight=.1ex
\newlength\maxkern
\setlength{\maxkern}{.14ex}
\newlength\nextcharwidth
\makeatletter
\renewcommand\@cenword[1]{%
\setlength{\nextcharwidth}{\widthof{#1}}%
\censorrule{\nextcharwidth}%
\kern -\nextcharwidth%
\color{white}%
\kern -.5\maxkern #1\kern .5\maxkern%
\kern -\nextcharwidth%
\kern -\maxkern #1\kern \maxkern%
\kern -\nextcharwidth%
\kern .5\maxkern #1\kern -.5\maxkern%
\kern -\nextcharwidth%
\kern \maxkern #1\kern -\maxkern%
\kern -\nextcharwidth%
\color{black}%
#1}
\let\sv@cenword\@cenword
\newcommand\m@cenword[1]{\ThisStyle{%
\stackengine{\mcensorruledepth}{$\SavedStyle#1$}%
{\rule{\widthof{$\SavedStyle#1$}}{\the\censorruleheight}}{U}{c}{F}{T}{L}}}
\newcommand\mblackout[2][\dp\strutbox]{%
\let\@cenword\m@cenword%
\def\mcensorruledepth{#1}%
\blackout{#2}%
\let\@cenword\sv@cenword%
}
\newcommand\mcensor[2][\dp\strutbox]{%
\let\@cenword\m@cenword%
\def\mcensorruledepth{#1}%
\censor{#2}%
\let\@cenword\sv@cenword%
}
\makeatother
\begin{document}
\blackout{This is a great test today}
{\raggedright\xblackout{This is a great test today}}
\[ \mblackout{y = A x^{2}} + Bx + \mblackout{C} \]
\[ \mblackout[.3ex]{y = \frac{a^{3} + b^{2} + c}{d_{3}}}\]
\[ \mcensor[3ex]{y = \frac{a^{3} + b^{2} + c}{d_{3}}}\]
\xblackout{Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel
justo vitae lacus tincidunt ultrices. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In hac habitasse platea dictumst.
Integer tempus convallis augue. Etiam facilisis. Nunc elementum
fermentum wisi. Aenean placerat. Ut imperdiet, enim sed gravida sollicitudin, felis odio placerat quam, ac pulvinar elit purus
eget enim. Nunc vitae tortor. Proin tempus nibh sit amet nisl.
Vivamus quis tortor vitae risus porta vehicula.}
\end{document}
ORIGINAL SOLUTION (based on outdated censor package)
This is a hack on the censor
package to do that which was not intended. All things considered, not too bad. It makes space for descenders, with a user-settable gap (\maxkern
)! The depth (\censorruledepth
) and thickness (\censorruleheight
) of the underrule are fully settable. It does linebreaking and page breaking. And with this EDITED version, it now does math underlining.
However, it does not do hyphenation. For text, it has two forms, using the censor
syntax, \blackout
(which skips over spaces and periods, and \xblackout
which attempts, through the use of carefully selected measures, to fill in underlines over the blanks and periods. As the parameters are set in my MWE, \xblackout
has a negative side effect of spilling slightly into the left margin.
\documentclass{article}
\usepackage[none]{hyphenat}
\usepackage{lipsum}
\usepackage{censor}
\usepackage{xcolor}
\usepackage{stackengine}
\usepackage{scalerel}
\censorruledepth=-.25ex
\censorruleheight=.1ex
\newlength\maxkern
\setlength{\maxkern}{.14ex}
\newlength\nextcharwidth
\makeatletter
\renewcommand\@cenword[1]{%
\setlength{\nextcharwidth}{\widthof{#1}}%
\censorrule{\nextcharwidth}%
\kern -\nextcharwidth%
\color{white}%
\kern -.5\maxkern #1\kern .5\maxkern%
\kern -\nextcharwidth%
\kern -\maxkern #1\kern \maxkern%
\kern -\nextcharwidth%
\kern .5\maxkern #1\kern -.5\maxkern%
\kern -\nextcharwidth%
\kern \maxkern #1\kern -\maxkern%
\kern -\nextcharwidth%
\color{black}%
#1}
\long\def\xblackout#1{\rule{0ex}{0ex}%
\def~{-}%
\def\@justpar{F}%
\def\@justperiod{F}%
\def\@justspace{F}%
\protected@edef\save@arg{#1}%
\expandafter\xcensor@Block\save@arg\stringend%
\let~\sv@tilde%
}
\long\def\blackout#1{%
\def~{-}%
\protected@edef\save@arg{#1}%
\expandafter\censor@Block\save@arg\stringend\let~\sv@tilde}
\newcommand\singlelipsum[1]{%
\begingroup\let\lips@par\relax\csname lipsum@\@roman{#1}\endcsname
\endgroup }
\let\sv@cenword\@cenword
\newcommand\m@cenword[1]{\ThisStyle{%
\stackengine{\mcensorruledepth}{$\SavedStyle#1$}%
{\rule{\widthof{$\SavedStyle#1$}}{\the\censorruleheight}}{U}{c}{F}{T}{L}}}
\newcommand\mblackout[2][\dp\strutbox]{%
\let\@cenword\m@cenword%
\def\mcensorruledepth{#1}%
\blackout{{#2}}%
\let\@cenword\sv@cenword%
}
\makeatother
\periodrlap=1ex
\afterperiodlap=.4ex
\lletterlap=.0ex
\rletterlap=.6ex
\afterspacelap=.6ex
\begin{document}
\blackout{\singlelipsum{4}}
{\raggedright\xblackout{\singlelipsum{4}}}
\[ \mblackout{y = A x^2} + Bx + \mblackout{C} \]
\[ \mblackout[3ex]{y = \frac{a^3 + b^2 + c}{d_3}}\]
\blackout{\singlelipsum{4}}
\end{document}
If space is desired between words, \blackout
works real nice.
If you want the spaces to be underlined, use \xblackout
. With my selection of the parameters to tune \xblackout
, the underline extends slightly into both margins. Also, I am using \raggedright
here, because stretching glue can make gaps form in the underline.
For math mode, the approach is slightly different. First difference is that it cannot make a gap for descenders (because I don't know how to convert a length variable into mu's). So, as a result, I place, by default, the math underline (named \mblackout
, keeping with the censor syntax) at the depth of the \strutbox
. However, for math that drops below this depth, it takes an optional argument of how far below the baseline to do the underline.
Thus,
\[ \mblackout{y = A x^2} + Bx + \mblackout{C} \]
\[ \mblackout[3ex]{y = \frac{a^3 + b^2 + c}{d_3}}\]
gives the following:
If you are afraid the underline might be confused for math division, you could always thicken it up with a change in \censorruleheight
.
Best Answer
Here is a solution using the
SOUL
package. Linebreaks etc. are respected although spacing may change very slightly if prior experience holds true. I tried withulem
but likely because of my unfamiliarity of the package, I couldn't get a solution that would work for more than a single word. I'm not sure if theSOUL
package is any less compatible thanulem
when it comes to conflicts etc.I believe that both packages first draw the line, and the place the text which is why the line is in the background. There may be other ways around that problem, but my "soul"ution was to typeset zero-width text (using
\rlap
), and then strikeout a phantom version of the text on top of it. The command takes two optional arguments: the first sets the color of the strike (default red) and the second sets the color of the text.