WeBWorK Main Forum

Text variables (units)

Text variables (units)

by Sean Fitzpatrick -
Number of replies: 5

We have a number of problems where there are variables like $units defined.

They're written in PGML, but they have stopped working with WeBWorK 2.19.

In most cases I can simply manually write in the units, but there are some places where the units depend on context.

For example, there is a problem about postal fees where the unit depends on the quantity. We have code like:

if ($h <= 20) {
$units3 = "\(\text{in}^3\)";
$units = "\(\text{in}\)";
}
elsif ($h <= 40) {
$units3 = "\(\text{cm}^3\)";
$units = "\(\text{cm}\)";
}
else {
$units3 = "\(\text{mm}^3\)";
$units = "\(\text{mm}\)";
}

Is there a way to make this work in 2.19? I have already tried changing the delimiters to [`...`].

In reply to Sean Fitzpatrick

Re: Text variables (units)

by Glenn Rice -
How were you using these variables in PGML?

If you use these variables like [@ $units @]* it will work.
In reply to Sean Fitzpatrick

Re: Text variables (units)

by Alex Jordan -

Some of your message has been eaten here in the forum, because the math is actively processed by MathJax.

But I think I saw the original in my email. Why are the unit variables stored with math delimiters surrounding them? In any case, can you post a complete exercise? It is a bit hard to understand how these would be used without that context.

In reply to Alex Jordan

Re: Text variables (units)

by Sean Fitzpatrick -

Here is a complete question file.

The change suggested by Glenn does the trick.

In reply to Sean Fitzpatrick

Re: Text variables (units)

by Alex Jordan -

There are problems with this. For one, static PTX output for a problem like this will fail. Where it should come out with "m" tags, it's going to have raw backslash-parentheses delimiters instead. But at a more abstract level, since it's math, the PGML math delimiters should be used.

So I recommend doing this like:

if ($h <= 20) {
    $units = "in";
} elsif ($h <= 40) {
    $units = "cm";
} else {
    $units = "mm";
}

And then in the body:

The [$country] Postal Service charges more for
boxes whose combined length and girth exceeds
[`[$max]\,\text{[$units]}`].

And:

Maximum volume [`V = {}`] [_]{$ans}{10} [`\text{[$units]}^3`]


In reply to Alex Jordan

Re: Text variables (units)

by Sean Fitzpatrick -
Thanks, I can make that change, although it is very unlikely that I will ever want PTX output from any of these problems. They all come from APEX, and were written about a year before I joined the project to rewrite APEX in PreTeXt. I think I offered these problems for use in APEX at the time, but there was no interest. I think every one of these problems now has a counterpart written directly in PTX source.