In my class file I have this code:



In my document I then call \solutions{}, but nothing happens. The environment "solution" is not included. Why is showsolution not set true?

Here is a full code example:

  • When the class is read, \excludecomment{solution} is executed. Doing \solutions in the document just changes the value of the conditional.
    – egreg
    Commented Jul 3, 2019 at 17:17

2 Answers 2


The command \solutions just switches the conditional \if@solutions, but cannot change already executed code. And \excludecomment{solution} has been performed.

The class should do


You can define a command that switches environments depending on the value of \ifshowsolution and call it either at the beginning of your document or when you want to change the behavior of the solution environment.

To define the "on" environment, you can use the \specialcomment macro from the comment package. Activating a specific environment depending on a condition is the main purpose of this command.

\nosolutions % default behaviour

You must log in to answer this question.

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