numbas / Numbas

A completely browser-based e-assessment/e-learning system, with an emphasis on mathematics
http://www.numbas.org.uk
Apache License 2.0
198 stars 118 forks source link

How to deal with decimals when rendering an expression as JME or TeX #968

Closed christianp closed 1 year ago

christianp commented 1 year ago

decimal values are currently rendered using the dec(...) syntax in JME, and often in scientific notation in TeX.

Quite often, this isn't the best choice: a student would expect to see an unannotated decimal number.

The immediate motivation of this issue is when the correct answer to a mathematical expression part has a decimal value substituted in. The expected answer ends up looking like dec("1.23")*x, which a student would never type, and the LaTeX preview looks like \\textrm{1.23} x.

The getCorrectAnswer method for mathematical expression parts uses Numbas.jme.subvars to substitute values in. It doesn't currently use the display flag, but maybe it should. The simplification step then renders x^{dec(0.123456789} as x^1.23456789*10^-1, which is not equivalent.

Should we avoid rendering decimals in scientific notation when the exponent is small?

christianp commented 1 year ago

Just using display mode for subvars when getting the correct answer for a mathematical expression part was not the right thing to do: it meant that subbed-in values don't always get brackets round them.

christianp commented 1 year ago

I don't think Numbas.jme.subvars can be fixed in display mode without breaking a lot of existing questions: we'd need to interpret the expression as a tree, but there are questions that rely on it acting like a string, particularly with unclosed braces.

I've made a note that Numbas.jme.subvars shouldn't be used for subbing into JME expressions in display mode, instead preferring Numbas.jme.display.subvars, which does parse the expression as a tree.