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
200 stars 118 forks source link

Support superscripts ² and ³ #868

Closed jhoobergs closed 2 years ago

jhoobergs commented 2 years ago

On (some) azerty keyboards you can type the superscripts ² and ³ really easily (it is just one of the keys on the keyboard). Quite some students use that key to write a square and cube and it would be useful if this is supported. It would be most useful for questions with second degree equations.

As far as I know, only ² and ³ can be typed this way.

The current implementation implies:

PS: It is best to squash merge this, I started out trying a different approach, but the replace seems like the better option.

PS 2: On my linux computer with azerty keyboard, ^ is a dead key so if I type ^2 it will show up as ² and I can do this for all digits (e.g ^6 yields ⁶). So it might be useful to also support all other digits instead of just 2 and 3.

christianp commented 2 years ago

Thanks for this suggestion! It relates to issue #690, which is about supporting more unicode characters in JME.

I think the right way of implementing this is for the tokeniser to interpret a string of superscript digits as equivalent to the op ^ followed by an integer.

For me, I think a string of consecutive superscript digits should be considered as a single number.

jhoobergs commented 2 years ago

Would you also support superscript (round) brackets and plus/minus signs? Or only a string of superscript digits?

sangwinc commented 2 years ago

And now the can of worms is fully open.....

christianp commented 2 years ago

I wondered about that! Then you'd have to be careful to bracket all the superscripted characters

jhoobergs commented 2 years ago

Would x⁽²⁺³⁾ and x²⁺³ be considered equal? Or would only the first version be allowed? (it really is a rabithole)

christianp commented 2 years ago

Yes: I think that xy should be equivalent to x^(y), whatever y is.

jhoobergs commented 2 years ago

Ok, I'll look into it tomorrow (or tonight)

christianp commented 2 years ago

I think that it should be done by translating each superscript character into the corresponding normal-size character, and running the normal tokeniser over it. I haven't looked to see if the tokeniser lets you branch off like that at the moment, or if that needs to be added.

christianp commented 2 years ago

On Ubuntu, the compose key combination Compose ^ - produces the macron character ¯. I think this shouldn't be interpreted as a minus sign, but I bet that some student will use it for that at some point. Maybe when the JME parser gives better error messages, it could give a warning about this.