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 haveamsmath
everywhere?amsmath
. any math substituted in the\mblackout
expression will fail. comment outamsmath
and 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.\color{white}{Text to be hidden here}
like one of the other solutions in Hiding part of text leaving blank space\alpha
and most other math commands. However,it is not correct that any math substituted into\mblackout
fails. It works with\frac
without amsmath, but not with. I assume amsmath redefines\frac
in 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).\[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\]
.