# hiding equation with fcolorbox won't work

I'm learning some formulas and in order to hide them (=print white) within my pdf-document using fcolorbox. I tried to create some macro, here's my mwe:

\documentclass[a4paper]{scrartcl} \nonstopmode
\usepackage{commath}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{calc}
\usepackage{mathtools}
\usepackage{xcolor}
\newcommand\f[2]{
%    \text{#1: } & #2 \\ % works fine
\text{#1: } & \fcolorbox{white}{white}{#2} \\ % won't work
}
\begin{document}
\begin{align*}
\f{Pythagoras}{a^2 + b^2 &=& c^2}
\f{Plank Equation}{E &=& \hbar\,\omega}
\end{align*}
\end{document}


You can see I indicated two lines with comments. Why does the first line produce the expected output, but the second one yields errors? Namely: Missing $inserted. Is there a better command to colorize/hide equations? I tried \phantom{} which works fine but only without ampersands… • \fcolorbox saves the contents in an extra box and so the ampersand is handled as a special token which has to escaped. Aug 17 '13 at 6:51 • removing the ampersands did not help Aug 17 '13 at 7:03 • You have to change "#2" into "$#2" or "\ensuremath{#2}" in the defintion of the macro \f and "&=&" into " = " on two places, where you use this macro. Then your document compiles. But the equation is not hidden. It is simply printed on white background in a rectangle with white boundary. To hide some content, try ocg-p package. Aug 17 '13 at 7:20 • If you don't use ampersands, \newcommand\f[2]{\text{#1: } & \color{white}#2 \\} works as well. Aug 17 '13 at 7:21 • tex.stackexchange.com/questions/13681/… is perhaps of interest. Aug 17 '13 at 7:53 ## 2 Answers You could use ifthen instead of fiddling with the colour. \documentclass[a4paper]{article} \usepackage{ifthen} \usepackage{amsmath} \begin{document} \newboolean{showeq} \setboolean{showeq}{true} % <-- comment this out to hide the equations \begin{align*} \text{Pythagoras:} && \ifthenelse{\boolean{showeq}}{a^2+b^2 &=c^2}{} \\ \text{Plank equation:} && \ifthenelse{\boolean{showeq}}{E &= \hbar\,\omega}{} \end{align*} \end{document}  You have two problems with your code for \f: 1. \fcolorbox stores its contents in a box, which switches the mode back to text (from math). As elements like a^2 can only be used in math mode, this causes the error (missing  inserted). If you're using \fcolorbox, you need to switch back to math mode explicitly: \fcolorbox{.}{.}{$..$}.
2. Since \fcolorbox boxes its contents, it has no reference on using the symbol &/its hidden from its intended meaning - typically used for alignment inside tabular or align (and friends). So, just drop it in this case.

While using single-character macros may be convenient, it's advised to use something a little more describing (also because some core macros could be single-characters themselves). Here's a revised version of your input:

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\newif\ifshoweq\showeqtrue
\newcommand{\showeq}[2]{%
\text{#1: } & \ifshoweq #2\else\phantom{#2}\fi
}
\begin{document}
Equations are visible:
\begin{align*}
\showeq{Pythagoras}{a^2 + b^2 = c^2} \\
\showeq{Plank Equation}{E = \hbar\,\omega}
\end{align*}

\showeqfalse

Equations are invisible:
\begin{align*}
\showeq{Pythagoras}{a^2 + b^2 = c^2} \\
\showeq{Plank Equation}{E = \hbar\,\omega}
\end{align*}
\end{document}


\showeq{<name>}{<eqn>} prints <name> in text mode, right aligned, and left aligns <eqn>. If the boolean variable \ifshoweq is set to \showeqfalse (default is to show equations/\showeqtrue), then it sets the equation as a \phantom. This provides the correct spacing of the equation, without actually printing it (also, no need for using "white" as a colour).

• thank you for your helpful and explaining answer! Unfortunately I can only accept one answer, and I accepted already one :-( Aug 21 '13 at 8:07