BigUpdate
Python application / build (push) Has been cancelled

This commit is contained in:
Igor20264
2026-09-03 10:44:08 +03:00
parent d2da20fdb2
commit 516abe7b83
177 changed files with 40178 additions and 2 deletions
+42
View File
@@ -0,0 +1,42 @@
"""Escape helpers for LaTeX output."""
from __future__ import annotations
import re
_SPECIAL = {
"\\": r"\textbackslash{}",
"{": r"\{",
"}": r"\}",
"#": r"\#",
"$": r"\$",
"%": r"\%",
"&": r"\&",
"_": r"\_",
"~": r"\textasciitilde{}",
"^": r"\textasciicircum{}",
}
def escape_text(s: str) -> str:
if not s:
return ""
out = []
for ch in s:
out.append(_SPECIAL.get(ch, ch))
return "".join(out)
def escape_verbatim_for_listing(s: str) -> str:
"""lstlisting body — avoid ending the environment accidentally."""
return s.replace("\\end{lstlisting}", "\\end\\{lstlisting}")
_LABEL_RE = re.compile(r"[^\w\-]+", re.UNICODE)
def latex_label(name: str | None, prefix: str = "obj") -> str:
if not name:
return prefix
cleaned = _LABEL_RE.sub("-", name.strip()).strip("-")
return f"{prefix}:{cleaned or 'x'}"