@@ -132,12 +132,12 @@ class StateSpace(NonlinearIOSystem, LTI):
132132 signal offsets. The subsystem is created by truncating the inputs and
133133 outputs, but leaving the full set of system states.
134134
135- StateSpace instances have support for IPython LaTeX output, intended
136- for pretty-printing in Jupyter notebooks. The LaTeX output can be
135+ StateSpace instances have support for IPython HTML/ LaTeX output, intended
136+ for pretty-printing in Jupyter notebooks. The HTML/ LaTeX output can be
137137 configured using `control.config.defaults['statesp.latex_num_format']`
138- and `control.config.defaults['statesp.latex_repr_type']`. The LaTeX
139- output is tailored for MathJax, as used in Jupyter, and may look odd
140- when typeset by non-MathJax LaTeX systems.
138+ and `control.config.defaults['statesp.latex_repr_type']`. The
139+ HTML/LaTeX output is tailored for MathJax, as used in Jupyter, and
140+ may look odd when typeset by non-MathJax LaTeX systems.
141141
142142 `control.config.defaults['statesp.latex_num_format']` is a format string
143143 fragment, specifically the part of the format string after `'{:'`
@@ -386,8 +386,6 @@ def __str__(self):
386386 "\n " .join (str (M ).splitlines ()))
387387 for Mvar , M in zip (["A" , "B" , "C" , "D" ],
388388 [self .A , self .B , self .C , self .D ])])
389- if self .isdtime (strict = True ):
390- string += f"\n dt = { self .dt } \n "
391389 return string
392390
393391 def _repr_eval_ (self ):
@@ -396,16 +394,42 @@ def _repr_eval_(self):
396394 A = self .A .__repr__ (), B = self .B .__repr__ (),
397395 C = self .C .__repr__ (), D = self .D .__repr__ ())
398396
399- if config .defaults ['control.default_dt' ] != self .dt :
400- out += ",\n dt={dt}" .format (
401- dt = 'None' if self .dt is None else self .dt )
402-
403- if len (labels := self ._label_repr ()) > 0 :
397+ out += super ()._dt_repr (",\n " )
398+ if len (labels := super ()._label_repr (show_count = False )) > 0 :
404399 out += ",\n " + labels
405400
406401 out += ")"
407402 return out
408403
404+ def _repr_html_ (self ):
405+ """HTML representation of state-space model.
406+
407+ Output is controlled by config options statesp.latex_repr_type,
408+ statesp.latex_num_format, and statesp.latex_maxsize.
409+
410+ The output is primarily intended for Jupyter notebooks, which
411+ use MathJax to render the LaTeX, and the results may look odd
412+ when processed by a 'conventional' LaTeX system.
413+
414+ Returns
415+ -------
416+ s : string
417+ HTML/LaTeX representation of model, or None if either matrix
418+ dimension is greater than statesp.latex_maxsize.
419+
420+ """
421+ syssize = self .nstates + max (self .noutputs , self .ninputs )
422+ if syssize > config .defaults ['statesp.latex_maxsize' ]:
423+ return None
424+ elif config .defaults ['statesp.latex_repr_type' ] == 'partitioned' :
425+ return super ()._repr_info (html = True ) + self ._latex_partitioned ()
426+ elif config .defaults ['statesp.latex_repr_type' ] == 'separate' :
427+ return super ()._repr_info (html = True ) + self ._latex_separate ()
428+ else :
429+ raise ValueError (
430+ "Unknown statesp.latex_repr_type '{cfg}'" .format (
431+ cfg = config .defaults ['statesp.latex_repr_type' ]))
432+
409433 def _latex_partitioned_stateless (self ):
410434 """`Partitioned` matrix LaTeX representation for stateless systems
411435
@@ -420,7 +444,6 @@ def _latex_partitioned_stateless(self):
420444 D = eval (repr (self .D ))
421445
422446 lines = [
423- self ._repr_info_ (),
424447 r'$$' ,
425448 (r'\left('
426449 + r'\begin{array}'
@@ -433,8 +456,7 @@ def _latex_partitioned_stateless(self):
433456
434457 lines .extend ([
435458 r'\end{array}'
436- r'\right)'
437- + self ._latex_dt (),
459+ r'\right)' ,
438460 r'$$' ])
439461
440462 return '\n ' .join (lines )
@@ -458,7 +480,6 @@ def _latex_partitioned(self):
458480 eval (repr (getattr (self , M ))) for M in ['A' , 'B' , 'C' , 'D' ])
459481
460482 lines = [
461- self ._repr_info_ (),
462483 r'$$' ,
463484 (r'\left('
464485 + r'\begin{array}'
@@ -477,8 +498,7 @@ def _latex_partitioned(self):
477498
478499 lines .extend ([
479500 r'\end{array}'
480- + r'\right)'
481- + self ._latex_dt (),
501+ + r'\right)' ,
482502 r'$$' ])
483503
484504 return '\n ' .join (lines )
@@ -493,7 +513,6 @@ def _latex_separate(self):
493513 s : string with LaTeX representation of model
494514 """
495515 lines = [
496- self ._repr_info_ (),
497516 r'$$' ,
498517 r'\begin{array}{ll}' ,
499518 ]
@@ -522,52 +541,11 @@ def fmt_matrix(matrix, name):
522541 lines .extend (fmt_matrix (self .D , 'D' ))
523542
524543 lines .extend ([
525- r'\end{array}'
526- + self ._latex_dt (),
544+ r'\end{array}' ,
527545 r'$$' ])
528546
529547 return '\n ' .join (lines )
530548
531- def _latex_dt (self ):
532- if self .isdtime (strict = True ):
533- if self .dt is True :
534- return r"~,~dt=~\mathrm{True}"
535- else :
536- fmt = config .defaults ['statesp.latex_num_format' ]
537- return f"~,~dt={ self .dt :{fmt }} "
538- return ""
539-
540- def _repr_latex_ (self ):
541- """LaTeX representation of state-space model
542-
543- Output is controlled by config options statesp.latex_repr_type,
544- statesp.latex_num_format, and statesp.latex_maxsize.
545-
546- The output is primarily intended for Jupyter notebooks, which
547- use MathJax to render the LaTeX, and the results may look odd
548- when processed by a 'conventional' LaTeX system.
549-
550-
551- Returns
552- -------
553-
554- s : string with LaTeX representation of model, or None if
555- either matrix dimension is greater than
556- statesp.latex_maxsize
557-
558- """
559- syssize = self .nstates + max (self .noutputs , self .ninputs )
560- if syssize > config .defaults ['statesp.latex_maxsize' ]:
561- return None
562- elif config .defaults ['statesp.latex_repr_type' ] == 'partitioned' :
563- return self ._latex_partitioned ()
564- elif config .defaults ['statesp.latex_repr_type' ] == 'separate' :
565- return self ._latex_separate ()
566- else :
567- raise ValueError (
568- "Unknown statesp.latex_repr_type '{cfg}'" .format (
569- cfg = config .defaults ['statesp.latex_repr_type' ]))
570-
571549 # Negation of a system
572550 def __neg__ (self ):
573551 """Negate a state space system."""
0 commit comments