Parse expression *s* using the given *fonts_object* for output, at the given *fontsize* and *dpi*. Returns the parse tree of :class:`Node` instances.
(self, s, fonts_object, fontsize, dpi)
| 2496 | self._math_expression = p.math |
| 2497 | |
| 2498 | def parse(self, s, fonts_object, fontsize, dpi): |
| 2499 | """ |
| 2500 | Parse expression *s* using the given *fonts_object* for |
| 2501 | output, at the given *fontsize* and *dpi*. |
| 2502 | |
| 2503 | Returns the parse tree of :class:`Node` instances. |
| 2504 | """ |
| 2505 | self._state_stack = [self.State(fonts_object, 'default', 'rm', fontsize, dpi)] |
| 2506 | self._em_width_cache = {} |
| 2507 | try: |
| 2508 | result = self._expression.parseString(s) |
| 2509 | except ParseBaseException as err: |
| 2510 | raise ValueError("\n".join(["", |
| 2511 | err.line, |
| 2512 | " " * (err.column - 1) + "^", |
| 2513 | str(err)])) |
| 2514 | self._state_stack = None |
| 2515 | self._em_width_cache = {} |
| 2516 | self._expression.resetCache() |
| 2517 | return result[0] |
| 2518 | |
| 2519 | # The state of the parser is maintained in a stack. Upon |
| 2520 | # entering and leaving a group { } or math/non-math, the stack |