I just posted a question and can now generate a conditional section in a text: how to make a conditional document feature
But to extend and generalize the question, first how could I create a document with a multivalued parameter (let's say, a difficulty level). If I were to identify the difficulty level of each exercise with an integer from 1 to 10, suppose I want to define that I print exercises with difficulties from 1 to 5 only.
In addition, whether just a boolean as before or a multi-valued parameter, is there any way to set a value from outside LaTeX? I would like to run a batch job that builds both a teacher edition and a student edition automatically, and I would prefer not to embed that state in the document and continually change it back and forth.
Best Answer
Here I present a ConTeXt solution using the
--arguments
feature and modes. Modes provide a way to conditionally include parts of a document. For instance, when printing a text book one can decide to print only the text or the text including exercises or everything, including exercises and hints to each exercise. Another use case is a single source file for slides and handouts.It's up to you what you want to mark up. Either mark up each exercise, if you want to be able to include individual exercises, or mark the individual difficulty levels. That way you can include all exercises from a particular difficulty level.
Here I created some example exercises with numeric difficulty levels. Some of the exercises have clues. Now you can include particular exercises on the command line. This includes exercise one and two and no clues.
It renders as:
To include exercise three to ten and the clues, use:
It renders as:
As you can see, the values of the arguments can be obtained using
\env{key}
. It is also possible to directly pass arguments to context:The value can be obtained using
\getdocumentargument{bodyfont}
in this case. But I'd recommend using--argument
, since it's safer and does not clash with already defined command line arguments.