Insert braces when parsing Expression widget input for correctness
Insert braces when parsing Expression widget input for correctness

Summary:
In the past, we had problems with expressions like x^23 being parsed
by KAS as x^{23} but displayed in TeX as x^{2}3. This was fixed in D20989.
However, the issue also applied to subscripts, and in some cases, this led to
broken exercises, because we were running the 'insert braces' transform on the
user's input when grading, but not on the correct answers in the editor, and
not when checking whether the user's answer was a properly formed expression
(i.e., when deciding whether or not to display an error message).

For example, if a content creator entered log_23, this would be parsed by KAS as
log_{23}, which is an invalid expression, so an error indicator would appear
and the exercise would always be marked as incorrect. (If a user entered
log_23, an error indicator would also appear, but it would be parsed correctly
during the grading step.)

This diff adds the 'insert braces' call to two places: first, before solving
for the correct answer in the editor; and second, when checking that the user
has entered a valid expression (so as to avoid inappropriately triggering error
messages).

Test Plan:
- Run `make serve` from `perseus`.
- Open [this exercise](http://localhost:9000/test.html#content=%7B%22question%22%3A%7B%22content%22%3A%22%5B%5B%E2%98%83%20expression%201%5D%5D%5Cn%5Cn%22%2C%22images%22%3A%7B%7D%2C%22widgets%22%3A%7B%22expression%201%22%3A%7B%22type%22%3A%22expression%22%2C%22alignment%22%3A%22default%22%2C%22static%22%3Afalse%2C%22graded%22%3Atrue%2C%22options%22%3A%7B%22answerForms%22%3A%5B%7B%22value%22%3A%22%5C%5Clog_2%5C%5Cleft%283%5C%5Cright%29%22%2C%22form%22%3Afalse%2C%22simplify%22%3Afalse%2C%22considered%22%3A%22correct%22%2C%22key%22%3A0%7D%5D%2C%22buttonSets%22%3A%5B%22basic%22%2C%22logarithms%22%5D%2C%22functions%22%3A%5B%22f%22%2C%22g%22%2C%22h%22%5D%2C%22times%22%3Afalse%7D%2C%22version%22%3A%7B%22major%22%3A1%2C%22minor%22%3A0%7D%7D%7D%7D%2C%22answerArea%22%3A%7B%22type%22%3A%22multiple%22%2C%22options%22%3A%7B%22content%22%3A%22%22%2C%22images%22%3A%7B%7D%2C%22widgets%22%3A%7B%7D%7D%2C%22calculator%22%3Afalse%2C%22periodicTable%22%3Afalse%7D%2C%22itemDataVersion%22%3A%7B%22major%22%3A0%2C%22minor%22%3A1%7D%2C%22hints%22%3A%5B%5D%7D).
    - Verify that no errors are raised in the editor.
- Type `log_2 3` into the renderer.
    - Verify that no error is raised, and that it grades as correct.
- Type `log_2 (3)` into the renderer.
    - Verify that it grades as correct.
- Change the correct answer to `log_2 3` by removing the parens.
    - Verify that no error is raised.
    - Verify that grading works as before.

Reviewers: alex

Reviewed By: alex

Subscribers: mattdunnrankin

Differential Revision: https://phabricator.khanacademy.org/D21811

ariabuckles/perseus,learningequality/perseus,learningequality/perseus,ariabuckles/perseus,ariabuckles/perseus,ariabuckles/perseus