MCPcopy Create free account
hub / github.com/SLiCAP/SLiCAP_python / _ensure_slicap

Function _ensure_slicap

SLiCAP/schematic/latex_label.py:90–117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

88
89
90def _ensure_slicap() -> bool:
91 global _slicap_ready, _slicap_check, _slicap_latex
92 if _slicap_ready is not None:
93 return _slicap_ready
94 orig = os.getcwd()
95 try:
96 os.chdir(get_cache_dir())
97 with contextlib.redirect_stdout(io.StringIO()):
98 from SLiCAP.SLiCAPmath import _checkExpression
99 from SLiCAP.SLiCAPhtml import _latex_ENG
100 from SLiCAP.SLiCAPlatex import sub2rm
101 _slicap_check = _checkExpression
102 # IEEE typesetting: subscripts that are plain alphanumeric labels are set
103 # upright (\mathrm) rather than italic. Applied here, at the single
104 # SLiCAP→LaTeX boundary, so every generated equation/symbol — component
105 # value labels and the parameter & model tables alike — is formatted
106 # consistently. (Free-form user LaTeX fragments do not pass through here
107 # and keep whatever formatting the user wrote.)
108 def _latex_ieee(sympy_obj):
109 s = _latex_ENG(sympy_obj)
110 return sub2rm(s) if s else s
111 _slicap_latex = _latex_ieee
112 _slicap_ready = True
113 except Exception:
114 _slicap_ready = False
115 finally:
116 os.chdir(orig)
117 return _slicap_ready
118
119
120# ── calibration ───────────────────────────────────────────────────────────────

Callers 2

expression_to_latexFunction · 0.85
_render_freshFunction · 0.85

Calls 1

get_cache_dirFunction · 0.85

Tested by

no test coverage detected