|
51 | 51 | import html5lib |
52 | 52 | import pyparsing |
53 | 53 | import six |
54 | | -from calc.preview import latex_preview |
55 | 54 | from chem import chemcalc |
56 | 55 |
|
57 | 56 | from lxml import etree |
@@ -1298,20 +1297,18 @@ def preview_formcalc(self, get): |
1298 | 1297 |
|
1299 | 1298 | result['request_start'] = int(get.get('request_start', 0)) |
1300 | 1299 |
|
1301 | | - try: |
1302 | | - # TODO add references to valid variables and functions |
1303 | | - # At some point, we might want to mark invalid variables as red |
1304 | | - # or something, and this is where we would need to pass those in. |
1305 | | - result['preview'] = latex_preview(formula) |
1306 | | - except pyparsing.ParseException: |
1307 | | - result['error'] = _("Sorry, couldn't parse formula") |
1308 | | - result['formula'] = formula |
1309 | | - except Exception: # lint-amnesty, pylint: disable=broad-except |
1310 | | - # this is unexpected, so log |
1311 | | - log.warning( |
1312 | | - "Error while previewing formula", exc_info=True |
1313 | | - ) |
1314 | | - result['error'] = _("Error while rendering preview") |
| 1300 | + # TODO add references to valid variables and functions |
| 1301 | + # At some point, we might want to mark invalid variables as red |
| 1302 | + # or something, and this is where we would need to pass those in. |
| 1303 | + from xmodule.capa_block import ProblemBlock |
| 1304 | + numeric_result = ProblemBlock.preview_numeric_input(formula) |
| 1305 | + # Map results into the correct format |
| 1306 | + result["preview"] = numeric_result["preview"] |
| 1307 | + if numeric_result["error"]: |
| 1308 | + result["error"] = numeric_result["error"] |
| 1309 | + # if formula is invalid retrn formula |
| 1310 | + if not numeric_result["is_valid"]: |
| 1311 | + result["formula"] = formula |
1315 | 1312 |
|
1316 | 1313 | return result |
1317 | 1314 |
|
|
0 commit comments