Render '\text{name} = value' as SVG for component labels (show_name=True). Uses _latex_to_svg directly (not _render_cached) so the combined LaTeX string is never passed through the SymPy parser.
(name: str, value_str: str)
| 164 | |
| 165 | |
| 166 | def render_name_eq_value(name: str, value_str: str) -> bytes | None: |
| 167 | """ |
| 168 | Render '\text{name} = value' as SVG for component labels (show_name=True). |
| 169 | |
| 170 | Uses _latex_to_svg directly (not _render_cached) so the combined LaTeX |
| 171 | string is never passed through the SymPy parser. |
| 172 | """ |
| 173 | if not LATEX_AVAILABLE: |
| 174 | return None |
| 175 | safe = name.replace('_', r'\_').replace('^', r'\^{}') |
| 176 | val = value_str.strip() |
| 177 | if not (val.startswith("{") and val.endswith("}")): |
| 178 | val = "{" + val + "}" |
| 179 | val_tex = expression_to_latex(val) |
| 180 | if not val_tex: |
| 181 | val_tex = val[1:-1] |
| 182 | return _render_latex_str(rf"{{\footnotesize \textsf{{{safe}}}}} = {val_tex}") |
| 183 | |
| 184 | |
| 185 | def render_expression(value_str: str) -> bytes | None: |
no test coverage detected