Skip to content

Commit

Permalink
Fix equation printing #113
Browse files Browse the repository at this point in the history
  • Loading branch information
mph- committed Nov 3, 2023
1 parent b9651b2 commit a0d1d1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/systems.rst
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Continuous-time state-space representation
Lcapy has two state-space representations: `StateSpace` for
continuous-time linear time-invariant systems and `DTStateSpace` for
discrete-time linear time-invariant systems. Both representations
share many methods and attributes.
share many methods and attributes, see :ref:`state-space-analysis`.

A state-space object is created from the state matrix, `A`, input
matrix, `B`, output matrix `C`, and feed-through matrix `D`::
Expand Down
17 changes: 17 additions & 0 deletions lcapy/equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

from .expr import ExprPrint, ExprMisc, expr
from .printing import latex
from sympy import Eq


Expand All @@ -17,6 +18,12 @@ def __init__(self, lhs, rhs):
self.lhs = expr(lhs)
self.rhs = expr(rhs)

@property
def _pexpr(self):
"""Return expression for printing."""

return self

# TODO, perhaps add canonical, etc.

def __call__(self, arg, **assumptions):
Expand All @@ -32,3 +39,13 @@ def symbols(self):
"""Return dictionary of symbols in the equation keyed by name."""

return dict(self.lhs.symbols, **self.rhs.symbols)

def _repr_latex_(self):
"""This is used by jupyter notebooks to display an expression using
LaTeX markup. However, this requires mathjax. If this method
is not defined, jupyter falls back on _repr_pretty_ which
outputs unicode."""

# This is called for Expr but not ExprList
s = latex(self._pexpr, mode='plain')
return "$$%s$$" % s

0 comments on commit a0d1d1c

Please sign in to comment.