Extract the last LaTeX boxed expression from a string. Args: string: Input string containing LaTeX code Returns: The last boxed expression or None if not found
(string: str)
| 19 | |
| 20 | |
| 21 | def last_boxed_only_string(string: str) -> Optional[str]: |
| 22 | """Extract the last LaTeX boxed expression from a string. |
| 23 | |
| 24 | Args: |
| 25 | string: Input string containing LaTeX code |
| 26 | |
| 27 | Returns: |
| 28 | The last boxed expression or None if not found |
| 29 | """ |
| 30 | idx = string.rfind("\\boxed{") |
| 31 | if idx < 0: |
| 32 | return None |
| 33 | |
| 34 | i = idx |
| 35 | right_brace_idx = None |
| 36 | num_left_braces_open = 0 |
| 37 | |
| 38 | while i < len(string): |
| 39 | if string[i] == "{": |
| 40 | num_left_braces_open += 1 |
| 41 | if string[i] == "}": |
| 42 | num_left_braces_open -= 1 |
| 43 | if num_left_braces_open == 0: |
| 44 | right_brace_idx = i |
| 45 | break |
| 46 | i += 1 |
| 47 | |
| 48 | return string[idx:right_brace_idx + 1] if right_brace_idx is not None else None |
| 49 | |
| 50 | |
| 51 | def remove_boxed(s: str) -> str: |
no outgoing calls
no test coverage detected