I am trying to find a way to hide expressions inside a math environment. I found a solution, provided by Steven B. Segletes at
Hiding part of text leaving blank space
However, when I add the amsmath package, it breaks, giving me the error "Missing $ inserted". I have provided a MWE example below. If I remove \usepackage{amsmath}, it compiles. If I remove the \frac command it compiles.
\documentclass{article}
\usepackage{amsmath}
\usepackage{censor}
\usepackage{stackengine}
\usepackage{scalerel}
\censorruleheight=0ex
\makeatletter
\long\def\blackout#1{%
\def~{-}%
\protected@edef\save@arg{#1}%
\expandafter\censor@Block\save@arg\stringend\let~\sv@tilde}
\let\sv@cenword\@cenword
\newcommand\m@cenword[1]{\ThisStyle{%
\stackengine{\mcensorruledepth}{$\SavedStyle\phantom{#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
\begin{document}
\[\mblackout{\frac{a}{b}} \]
\end{document}




amsmath, your text, title and tag saysamsthm, I assume you meant to haveamsmatheverywhere? – Torbjørn T. Sep 21 '14 at 14:46amsmath. any math substituted in the\mblackoutexpression will fail. comment outamsmathand change the display line to\[ \mblackout{\alpha} \]-- that results in the sameMissing $ inserted., and inserting$signs as\[ \mblackout{$\alpha$} \]results in the errorMissing } inserted.so no, there is something wrong with your definitions, which i haven't got time to debug. – barbara beeton Sep 21 '14 at 15:28\color{white}{Text to be hidden here}like one of the other solutions in Hiding part of text leaving blank space – 0az Sep 21 '14 at 15:35\alphaand most other math commands. However,it is not correct that any math substituted into\mblackoutfails. It works with\fracwithout amsmath, but not with. I assume amsmath redefines\fracin some way? I do not want to use\color{white}(which was my original solution) because I am blanking out text on the students' version of my notes and I decided I do not want them to be able to copy the hidden text (also, I do not always have a white background). – smcc Sep 21 '14 at 15:51\[1+\mblackout{1\alpha}+1\], the code compiles correctly with no errors. The code does not compile correctly (and with the same error message as before) when I try\[1+\mblackout{\alpha}+1\]. – smcc Sep 21 '14 at 16:48