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
205 stars 120 forks source link

JME functions to format numbers should have LaTeX versions #946

Open christianp opened 2 years ago

christianp commented 2 years ago

While resolving #889, it became apparent that we really need to produce a different string version of a number for LaTeX, rather than assuming the plain-text version will be fine. Commas inside numbers shouldn't be followed by an extra space.

There are several JME functions which format numbers as strings: formatnumber, dpformat, sigformat, and scientificnumber[latex|html]. These should produce LaTeX code when called inside a call to latex().

The latex function should set a stringSyntax attribute on the scope which gets passed through as Numbas.math.niceNumber's syntax option.

christianp commented 1 year ago

Another option is to produce both versions and store them in the TString token. When the string is subbed into LaTeX, the LaTeX version would be used. This might need all string operations to also operate on the LaTeX version.