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

Method build_latex

SLiCAP/schematic/model_item.py:170–203  ·  view source on GitHub ↗
(model_name: str, model_type: str, params: list)

Source from the content-addressed store, hash-verified

168
169 @staticmethod
170 def build_latex(model_name: str, model_type: str, params: list) -> str:
171 from .latex_label import expression_to_latex
172
173 def _escape(s: str) -> str:
174 return s.replace('_', r'\_').replace('^', r'\^{}')
175
176 def _value_tex(s: str) -> str:
177 s = s.strip()
178 if not s:
179 return r"\cdot"
180 if not (s.startswith("{") and s.endswith("}")):
181 s = "{" + s + "}"
182 return expression_to_latex(s)
183
184 header = (r"\texttt{.model}"
185 rf"\ \mathtt{{{_escape(model_name)}}}"
186 rf"\ \mathtt{{{_escape(model_type)}}}")
187 filled = [(n.strip(), v) for n, v in params if n.strip()]
188
189 if not filled:
190 return rf"\[ {header} \]"
191
192 rows = " \\\\\n".join(
193 rf" {{\footnotesize \textsf{{{_escape(n)}}}}} & {_value_tex(v)}"
194 for n, v in filled
195 )
196 return (
197 r"\[" "\n"
198 r"\begin{array}{r@{\;=\;}l}" "\n"
199 rf"\multicolumn{{2}}{{l}}{{{header}}} \\" "\n"
200 + rows + "\n"
201 r"\end{array}" "\n"
202 r"\]"
203 )
204
205 def netlist_lines(self) -> list:
206 """Return .model lines for netlist export; values are auto-wrapped in {}."""

Callers 5

_load_rendererMethod · 0.95
_renderMethod · 0.45
start_model_placementMethod · 0.45
_renderMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected