2

I've been trying to write a small package so I can show/hide solutions in some of my notes, so far I have the following non working example which I hacked by looking at some other answers and the latex wiki book https://en.wikibooks.org/wiki/LaTeX/Plain_TeX#Self_defined_conditionals

\ProvidesPackage{solutions}

\newif\ifsolutions
\solutionsfalse
\DeclareOption{solutions}{\solutionstrue}
\DeclareOption{nosolutions}{\solutionsfalse}

\newenvironment{solution}[1]{
    \ifsolutions
       #1 $\delta$ % I'd ideally want to write the solution in a gray box
    \else 
       #1 $\bullet$ % I'd like to ignore all the input when solutions is false, but putting a circle will do for now.
    \fi
}

and my .tex

\documentclass[reqno, 12pt, twoside, letterpaper]{memoir}
\usepackage[nosolutions]{packages/solutions}
\begin{document}
  \begin{solution}
    Test
  \end{solution}
\end{document}

But this doesn't work at all, if I define solutions it doesn't work and if I define nosolutions it will fail to compile. I've been searching for a way to use an if inside the new environment with nothing that looks even remotely promising.

Any ideas on where I should look for this?

3
  • 2
    you need \ProcessOptions.
    – ljguo
    Commented Aug 15 at 4:47
  • Your setup is a bit confusing: You define the solution environment to take one mandatory argument, but the sample instance of the solution environment does not appear to make purposeful use of this argument. What's the argument supposed to influence or achieve? Does the solution environment need an argument at all?
    – Mico
    Commented Aug 15 at 6:18
  • It needs at least one argument, the other might default so you're right in the sense I don't need two I think. One should show the solutions in the output file and the other should basically blank them. But I think thats a problem for another question and not this one.
    – aram
    Commented Aug 15 at 14:03

1 Answer 1

4

You need \ProcessOptions\relax to handle package options.

\ProvidesPackage{solutions}

\newif\ifsolutions
\solutionsfalse
\DeclareOption{solutions}{\solutionstrue}
\DeclareOption{nosolutions}{\solutionsfalse}
\ProcessOptions\relax
\newenvironment{solution}[1]{
    \ifsolutions
       #1 $\delta$ % I'd ideally want to write the solution in a gray box
    \else 
       #1 $\bullet$ % I'd like to ignore all the input when solutions is false, but putting a circle will do for now.
    \fi
}{}

You must log in to answer this question.

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