r""" All characters in LaTeX math mode are preserved. The substrings in LaTeX math mode, which start with the character ``$`` and end with ``$``, are preserved without escaping. Otherwise regular LaTeX escaping applies. Parameters ---------- s : str Input to be
(s: str)
| 2577 | |
| 2578 | |
| 2579 | def _math_mode_with_dollar(s: str) -> str: |
| 2580 | r""" |
| 2581 | All characters in LaTeX math mode are preserved. |
| 2582 | |
| 2583 | The substrings in LaTeX math mode, which start with |
| 2584 | the character ``$`` and end with ``$``, are preserved |
| 2585 | without escaping. Otherwise regular LaTeX escaping applies. |
| 2586 | |
| 2587 | Parameters |
| 2588 | ---------- |
| 2589 | s : str |
| 2590 | Input to be escaped |
| 2591 | |
| 2592 | Return |
| 2593 | ------ |
| 2594 | str : |
| 2595 | Escaped string |
| 2596 | """ |
| 2597 | s = s.replace(r"\$", r"rt8§=§7wz") |
| 2598 | pattern = re.compile(r"\$.*?\$") |
| 2599 | pos = 0 |
| 2600 | ps = pattern.search(s, pos) |
| 2601 | res = [] |
| 2602 | while ps: |
| 2603 | res.append(_escape_latex(s[pos : ps.span()[0]])) |
| 2604 | res.append(ps.group()) |
| 2605 | pos = ps.span()[1] |
| 2606 | ps = pattern.search(s, pos) |
| 2607 | |
| 2608 | res.append(_escape_latex(s[pos : len(s)])) |
| 2609 | return "".join(res).replace(r"rt8§=§7wz", r"\$") |
| 2610 | |
| 2611 | |
| 2612 | def _math_mode_with_parentheses(s: str) -> str: |
no test coverage detected