Cache and render a pre-built LaTeX math string, bypassing SymPy parsing.
(latex_str: str)
| 269 | |
| 270 | |
| 271 | def _render_latex_str(latex_str: str) -> bytes | None: |
| 272 | """Cache and render a pre-built LaTeX math string, bypassing SymPy parsing.""" |
| 273 | if not LATEX_AVAILABLE: |
| 274 | return None |
| 275 | h = hashlib.sha256(("raw:" + latex_str).encode()).hexdigest()[:24] |
| 276 | path = get_cache_dir() / f"{h}.svg" |
| 277 | if path.exists(): |
| 278 | return path.read_bytes() |
| 279 | svg = _latex_to_svg(latex_str) |
| 280 | if svg is not None: |
| 281 | path.write_bytes(svg) |
| 282 | return svg |
| 283 | |
| 284 | |
| 285 | def _latex_to_svg(latex_str: str) -> bytes | None: |
no test coverage detected