2

I am looking to type up some solutions to math problems. However, I do not want someone who just looks at the document to be able to see the solution; I want the students to be able to see the problem without the solution.

How can I create an environment that has the text color the same as the background color?

As an added wrinkle, I do need the color to carry over to the math environment. Thanks for any help.

2
  • There are many existing packages that solve this exact problem (although I don't think they use the method of changing the text color). The one I use (its actually a class file) is called exam and its documentation is here: ctan.org/pkg/exam
    – darthbith
    Mar 27, 2015 at 20:06
  • 1
    Changing the color would not work if the students have the electronic version. The data would still be in the document. This answer might give ideas: tex.stackexchange.com/questions/135453/… Mar 27, 2015 at 20:21

1 Answer 1

1

As mentioned in the comments, there are classes or packages that are probably more suitable solutions (I usually use the exam class). However, one option is to create an environment that sets the color to be the same as the background. Here's an example in a tcolorbox, then again by itself. In the latter case you could just use \color{white} to hide the text.

\documentclass[12pt]{article}
\usepackage[english]{babel}
\usepackage{xcolor}
\usepackage{tcolorbox}
\usepackage[math]{blindtext}
\usepackage{mathtools}

\colorlet{mycolor}{blue!20!white}
\tcbset{colback=mycolor}

\newenvironment{mysolution}
{ Solution:\par\color{mycolor} }
{ \color{black} }

\begin{document}
\begin{tcolorbox}
Problem:

Some problem statement.
\tcblower
\begin{mysolution}
The solution

\begin{equation}
x=2
\end{equation}
\blindtext
\end{mysolution}
\end{tcolorbox}

Problem:

A different problem

\begin{mysolution}
\begin{equation}
y=x^{2}
\end{equation}
\blindtext
\end{mysolution}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .