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

Method eqn

SLiCAP/SLiCAPrst.py:417–474  ·  view source on GitHub ↗

Creates a displayed (numbered) equation. :param LHS: Left hand side of the equation. :type LHS: str, sympy.Symbol, sympy.Expr :param RHS: Right hand side of the equation. :type RHS: sympy.Symbol, sympy.Expr :param units: Units :type units:

(self, LHS, RHS, units="", label="", multiline=False)

Source from the content-addressed store, hash-verified

415 return Snippet(RST, self.format)
416
417 def eqn(self, LHS, RHS, units="", label="", multiline=False):
418 """
419 Creates a displayed (numbered) equation.
420
421 :param LHS: Left hand side of the equation.
422 :type LHS: str, sympy.Symbol, sympy.Expr
423
424 :param RHS: Right hand side of the equation.
425 :type RHS: sympy.Symbol, sympy.Expr
426
427 :param units: Units
428 :type units: str
429
430 :param label: Reference label for the table. Defaults to an empty string.
431 :type label: str
432
433 :param multiline: n breaks the equation over multiple lines with n sums
434 or products per line
435 :type multiline: int, Bool
436
437 :return: SLiCAP Snippet object
438 :rtype: SLiCAP.SLiCAPprotos.Snippet
439
440 :example:
441
442 >>> import SLiCAP as sl
443 >>> import sympy as sp
444 >>>
445 >>> rst = sl.RSTformatter()
446 >>> lhs = sp.sympify("e^(1j*pi)")
447 >>> rhs = sp.N(-1)
448 >>> rst.eqn(lhs, rhs, label="nice_eqn").save("nice_eqn")
449 """
450 RST = '.. math::\n'
451 if label != '':
452 RST += ' :label: ' + label + '\n'
453 RST += '\n'
454 try:
455 units = units2TeX(units)
456 except:
457 units = ''
458
459 if multiline:
460 TEX = '\n' + sp.multiline_latex(roundN(LHS), roundN(RHS),
461 terms_per_line=multiline)
462 TEX = TEX.replace('\\\\\n', '\\nonumber \\\\\n')
463 TEX = TEX.replace('{align*}', '{align}')
464 if units != '':
465 units = '\\,\\left[\\mathrm{' + units + '}\\right]'
466 TEX = TEX.replace('\\end{align}', '%s\n\\end{align}'%(units))
467 TEX += '\n'
468 TEX = TEX.replace("\n", "\n ")
469 RST += TEX
470 else:
471 RST += ' ' + sp.latex(roundN(LHS)) + ' = ' + sp.latex(roundN(RHS))
472 if units != '':
473 RST += '\\,\\,\\left[\\mathrm{' + units + '}\\right]\n\n'
474 return Snippet(RST, self.format)

Callers 7

laplace.pyFile · 0.45
noise.pyFile · 0.45
sphinx_report.pyFile · 0.45
ttime.pyFile · 0.45
balanced.pyFile · 0.45
feedback.pyFile · 0.45
dcvar.pyFile · 0.45

Calls 3

units2TeXFunction · 0.90
roundNFunction · 0.90
SnippetClass · 0.90

Tested by

no test coverage detected