I have been using the optional package in order to conveniently create solutions in the same document. I had been writing solutions longhand by placing it inside:

\opt{optS}{\color{blue} \textbf{Solution:} asdfasdf \color{black}}

But I'd like to save time by creating an environment that includes the \opt{optS} call. I tried doing it with the following code:

{ \opt{optS}{\color{blue} \textbf{Solution:}  }}

It appears to work nicely when I have optS selected when I compile. But if optO is used during compiling, the solutions still appear but now in black. Is there something I'm missing with including the \opt{optS} inside a new environment? Thank you for the help!


Sorry for the lack of clarity. My intention is to have

\begin{sol} text of solution here \end{sol}

such that the \newenvironment{sol} wraps the "text of solution here" inside an \optS{ } so that the solution only appears when compiled with the optS optional argument. I additionally had it automatically making it blue and putting "Solution:" before it but that works fine. I think the real issue is that the \optS{ needs be included in the prior arguments to \newenvironment but the closing } needs to be in the ending arguments and I don't think \newenvironment allows unequal brackets in that way.


2 Answers 2

  • it is not clear, what you like to have (please, clarify your question)
  • in the case, that you need only word "solution" in the blue bold face text, than you can define for example \solution{\textcolor{blue}{\textbf{Solution~}}}
  • in cases, that you like change text "solution" and its color, than you can consider \newcommand\optS[2][blue]{\textcolor{#1}{\textbf{#2}}}

\solution text of solution

\optS{Solution:} text of solution

\optS[red]{Comment:} text of comment

enter image description here


To ignore environment bodies, maybe you should be using the comment package instead of or in addition to the optional package.


You must log in to answer this question.

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