I make handouts/slides for my students. I like to produce three different versions of these

  • Solutions mode - Contains my solutions (usually in blue).
  • Student mode - Solutions are hidden.
  • Darkmode - Like student mode, but the background is dark and text is light (easier on the eyes for zoom classes)

The way I've been handling this is to call either \solutionsversion, \studentversion \darkmodeversion in the preamble, and this sets the colors of things (all the macros tidied away into a style file I wrote). I have a command \answer{...} which I put around stuff that is considered an answer. If \solutionsversion is called, this command sets the textcolor to be blue, if one of the other versions are called, it sets the textcolor to be the same as the background color, so text is hidden.

This works great until something I want to be an answer is living in something whose color is different than the standard background color, for instance, in a beamer block environment.

A partial fix I have found is to change the definition of \answer to make the text temporarily transparent with the following definition

\newcommand{\answer}[1]{\pgfsetfillopacity{0} #1 \pgfsetfillopacity{1}}

However, I have found that the dividing lines in fractions using \frac{}{} as well as the augmenting line in the answer to this question don't go transparent.

Does anyone have an idea of how I could have a single command that sets the content's color to be the same as the current background color, or should I stop trying to have a single macro to do everything.

Fixed: I was initially using \pgfsetfillopacity from the pgfplots package to make the text transparent. I have found that \texttransparent{0}{...} from the transparency package also gets the parts that pgfplots was missing.

  • Hmm.... aren't the student able to see the answers by just selecting the text, copying and pasting it somewhere?
    – Rmano
    Commented May 31, 2022 at 15:17
  • @Rmano They can, but if it is a handout I give them the student version as a print-out in class (and we fill it in together) and if it is slides, I annotate the student version in class.
    – James
    Commented May 31, 2022 at 15:19
  • 2
    BTW, you should really post a minimal example. I use also answers that disappear, but the idea is to use an \if block to just not to typeset them, so the color is not a problem...
    – Rmano
    Commented May 31, 2022 at 15:19
  • @Rmano I have thought about using literally disappearing text, but then then you have to produce whitespace instead or there will be no empty space.
    – James
    Commented May 31, 2022 at 15:21
  • I see the main problem to determine the color of the current background color. This totally changes by the way, how the background color is defined. It can be a png graphic, a coloured box, a deformed rule. Commented May 31, 2022 at 15:34

1 Answer 1


Just as illustrated suggestion:

You can make the answer code commands into variables (macros), and \renew... them as required.

q and a




\verb|>>Q: aaa A: \mybox{\mymode{\myanswer}}<<\par|

>>Q: aaa A: \mybox{\mymode{\myanswer}}<<\par

>>Q: aaa A: \mybox{\mymode{\myanswer}}<<\par

>>Q: aaa A: \mybox{\mymode{\myanswer}}<<\par


You must log in to answer this question.

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