Skip to main content

The PreTeXt Guide

Subsection 7.1.2 Perl-free Problems

If you’d just like to rattle off a quick question with no randomization, you can do as in this example.
<exercise>
  <webwork>
    <statement>
      <p><m>1+2=</m><var name="'3'" width="5" /></p>
    </statement>
  </webwork>
</exercise>
The <exercise> above could be given an optional <title>, <introduction>, and <conclusion>. The <webwork> inside could be given a <hint> and <solution>. These are discussed in Subsection 7.1.3.
In the above example, '3' is the @name attribute to a <var> element. There is actually no “variable” named “3”; we are just using the slot where more complicated exercises would place a Perl variable answer.
So the above is how to create an answer blank that is expecting \(3\) as the answer. What you give as a @name attribute will be passed to PG’s Compute() constructor, so it needs to be valid input for Compute(). Note that you could pass a string encased in quotes, or a perl expression. Just be mindful of the difference:
  • 8**2 will process a perl real using exponentiation and lead to the MathObject Real 64.
  • '8^2' will process a perl string and lead to the MathObject Real 64.
  • 8^2 will process the perl real using bitwise XOR and lead to the MathObject Real 10.
The default context is Numeric, which understands numerical expressions and formulaic expressions in the variable \(x\text{.}\) You can activate some other context as in this example.
<exercise>
  <webwork>
    <pg-code>
      Context("ImplicitPlane");
    </pg-code>
    <statement>
      <p>The answer is <m>x+y=1</m>.</p>
      <p><var name="'x+y=1'" width="8" /></p>
    </statement>
  </webwork>
</exercise>
Many special contexts are automatically detected by PreTeXt, and it loads the appropriate macro file into the PG problem. However you may need to explicitly load a macro file as described in Subsection 7.1.3.