WeBWorK Main Forum

Why Giga newton is not allowed

Re: Why Giga newton is not allowed

by Alex Jordan -
Number of replies: 0

Yes, you can do that. It could lead to git conflicts when you upgrade in the future, but it is not too likely.

There is a way to add arbitrary units to the units parser though, via the problem or a macro library. If giganewtons and other things are common for you, perhaps it is worth doing this. See the commentary at the top of:


for how to add new units. It is something like this:

$newUnits = [

   {name => 'GN', conversion => {factor =>10**9, kg=>1, m=>1, s=>-2}},
   {name => 'TN', conversion => {factor =>10**12, kg=>1, m=>1, s=>-2}},

Then make the answer like:

$answer = NumberWithUnits("3 GN",{newUnit=>$newUnits});

As I said, if you;d use this a lot, then it is worth the effort to not put the $newUnits declaration into each problem. Instead you could make a macro library file that loads parserNumberWithUnits.pl and then sets the $newUnits array ref. I'm not immediately sure how you could write the `{newUnit=>$newUnits}` part into the macro library though. A NumberWithUnits object uses some legacy code and I didn't look into how to work with that.