-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexescape.py
More file actions
23 lines (20 loc) · 2.07 KB
/
texescape.py
File metadata and controls
23 lines (20 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""TeX escaping helper."""
from __future__ import annotations
import re
tex_replacements = [('$', '\\$'), ('%', '\\%'), ('&', '\\&'), ('#', '\\#'), ('_', '\\_'), ('{', '\\{'), ('}', '\\}'), ('\\', '\\textbackslash{}'), ('~', '\\textasciitilde{}'), ('^', '\\textasciicircum{}'), ('[', '{[}'), (']', '{]}'), ('✓', '\\(\\checkmark\\)'), ('✔', '\\(\\pmb{\\checkmark}\\)'), ('✕', '\\(\\times\\)'), ('✖', '\\(\\pmb{\\times}\\)'), ('\ufeff', '{}'), ('⎽', '\\_'), ('ℯ', 'e'), ('ⅈ', 'i')]
ascii_tex_replacements = [('-', '\\sphinxhyphen{}'), ("'", '\\textquotesingle{}'), ('`', '\\textasciigrave{}'), ('<', '\\textless{}'), ('>', '\\textgreater{}')]
unicode_tex_replacements = [('¶', '\\P{}'), ('§', '\\S{}'), ('€', '\\texteuro{}'), ('∞', '\\(\\infty\\)'), ('±', '\\(\\pm\\)'), ('→', '\\(\\rightarrow\\)'), ('‣', '\\(\\rightarrow\\)'), ('–', '\\textendash{}'), ('⁰', '\\(\\sp{\\text{0}}\\)'), ('¹', '\\(\\sp{\\text{1}}\\)'), ('²', '\\(\\sp{\\text{2}}\\)'), ('³', '\\(\\sp{\\text{3}}\\)'), ('⁴', '\\(\\sp{\\text{4}}\\)'), ('⁵', '\\(\\sp{\\text{5}}\\)'), ('⁶', '\\(\\sp{\\text{6}}\\)'), ('⁷', '\\(\\sp{\\text{7}}\\)'), ('⁸', '\\(\\sp{\\text{8}}\\)'), ('⁹', '\\(\\sp{\\text{9}}\\)'), ('₀', '\\(\\sb{\\text{0}}\\)'), ('₁', '\\(\\sb{\\text{1}}\\)'), ('₂', '\\(\\sb{\\text{2}}\\)'), ('₃', '\\(\\sb{\\text{3}}\\)'), ('₄', '\\(\\sb{\\text{4}}\\)'), ('₅', '\\(\\sb{\\text{5}}\\)'), ('₆', '\\(\\sb{\\text{6}}\\)'), ('₇', '\\(\\sb{\\text{7}}\\)'), ('₈', '\\(\\sb{\\text{8}}\\)'), ('₉', '\\(\\sb{\\text{9}}\\)')]
tex_replace_map: dict[int, str] = {}
_tex_escape_map: dict[int, str] = {}
_tex_escape_map_without_unicode: dict[int, str] = {}
_tex_hlescape_map: dict[int, str] = {}
_tex_hlescape_map_without_unicode: dict[int, str] = {}
def escape(s: str, latex_engine: str | None=None) -> str:
"""Escape text for LaTeX output."""
pass
def hlescape(s: str, latex_engine: str | None=None) -> str:
"""Escape text for LaTeX highlighter."""
pass
def escape_abbr(text: str) -> str:
"""Adjust spacing after abbreviations. Works with @ letter or other."""
pass