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)
| 529 | return Snippet(TEX, self.format) |
| 530 | |
| 531 | def eqn(self, LHS, RHS, units="", label="", multiline=False): |
| 532 | """ |
| 533 | Creates a displayed (numbered) equation. |
| 534 | |
| 535 | :param LHS: Left hand side of the equation. |
| 536 | :type LHS: str, sympy.Symbol, sympy.Expr |
| 537 | |
| 538 | :param RHS: Right hand side of the equation. |
| 539 | :type RHS: sympy.Symbol, sympy.Expr |
| 540 | |
| 541 | :param units: Units |
| 542 | :type units: str |
| 543 | |
| 544 | :param label: Reference label for the table. Defaults to an empty string. |
| 545 | :type label: str |
| 546 | |
| 547 | :param multiline: n breaks the equation over multiple lines with n sums |
| 548 | or products per line |
| 549 | :type multiline: int, Bool |
| 550 | |
| 551 | :return: SLiCAP Snippet object |
| 552 | :rtype: SLiCAP.SLiCAPprotos.Snippet |
| 553 | |
| 554 | :example: |
| 555 | |
| 556 | >>> import SLiCAP as sl |
| 557 | >>> import sympy as sp |
| 558 | >>> |
| 559 | >>> ltx = sl.LaTeXformatter() |
| 560 | >>> lhs = sp.sympify("e^(1j*pi)") |
| 561 | >>> rhs = sp.N(-1) |
| 562 | >>> ltx.eqn(lhs, rhs, label="nice_eqn").save("nice_eqn") |
| 563 | """ |
| 564 | try: |
| 565 | units = units2TeX(units) |
| 566 | except: |
| 567 | units = '' |
| 568 | if type(LHS) == str: |
| 569 | LHS = sp.sympify(LHS) |
| 570 | if type(RHS) == str: |
| 571 | RHS = sp.sympify(RHS) |
| 572 | if multiline: |
| 573 | TEX = '\n' + sp.multiline_latex(roundN(LHS), roundN(RHS), |
| 574 | terms_per_line=multiline) |
| 575 | TEX = TEX.replace('\\\\\n', '\\nonumber \\\\\n') |
| 576 | TEX = TEX.replace('{align*}', '{align}') |
| 577 | if label != '': |
| 578 | TEX = TEX.replace('\\end{align}', '\\label{%s}\n\\end{align}'%(label)) |
| 579 | TEX += '\\,\\left[\\mathrm{' + units + '}\\right]\n' |
| 580 | else: |
| 581 | TEX = '\\begin{equation}' |
| 582 | TEX += '\n' + sp.latex(roundN(LHS)) + ' = ' + sp.latex(roundN(RHS)) |
| 583 | if units != '': |
| 584 | TEX += '\\,\\left[\\mathrm{' + units + '}\\right]' |
| 585 | TEX += '\n' |
| 586 | if label != '': |
| 587 | TEX += '\\label{'+ label + '}\n' |
| 588 | TEX += '\\end{equation}\n\n' |