Repository: python-control/python-control

Issue:
Latex is not rendered in HTML output of in VSCode
On f6799ab8e60d7fcd4b02d52d5903f08c24957faf

As the title says, the math sections in HTML output generated by `_repr_html_` from `StateSpace` (and other classes) is not rendered.

![Image](https://github.com/user-attachments/assets/d2a9bfda-4ffe-420b-b910-d2ed61daa2b4)

This is not really the fault of this library and there is an open [issue](https://github.com/microsoft/vscode/issues/203725) in the VSCode repo for this, but the simpler output which used `_html_latex_` before #1091 did not have this problem.

![Image](https://github.com/user-attachments/assets/a9ffeee7-d25b-4c85-9a7b-0f2e247c0ac5)

I think adding back the old `_repr_latex_` would allow the user to choose between the new mixed HMTL output and the old Latex output if using VSCode, what do you think?

Another option that I saw in the VSCode issue is to explicitly add the renderer into the HTML but this seems really hacky:

![Image](https://github.com/user-attachments/assets/09be3501-2500-46b4-91be-8e1534ef77ed)


Discussion:
A couple of possibilities:
* If have `_repr_html` and `_repr_latex` allows VSCode to use LaTeX and Jupyter to use HTML, that could work.
* We could add something into `_repr_html` that checks for VSCode and set the output accordingly (won't be as pretty, but should work OK).
* We could add an option that allows the default `repr` format to be changed and users could use then set the format to `vscode` (or something like that), which would give the older style format.
I did try at one point getting things to look good with just LaTeX, but it was very hard to convince the LaTeX processor in Jupyter to do the right thing (it wanted raw latex math code, if memory serves).

I don't have access to VSCode, so someone else would have to create PR that worked there and we can then confirm Jupyter still renders correctly.

It would be nice to have this fixed for 0.10.2.
I experimented a bit more and it seems that VSCode will render latex contained in `_repr_markdown_` which mostly behaves like a superset of `_repr_html_`. So one can simply switch the output to text/markdown and everything works pretty much as it should have in the first place.

Pull request for blanked `_repr_markdown_` comming in a few minutes.



Patch:
diff --git a/control/iosys.py b/control/iosys.py
index 110552138..29f5bfefb 100644
--- a/control/iosys.py
+++ b/control/iosys.py
@@ -314,6 +314,9 @@ def _repr_latex_(self):
     def _repr_html_(self):
         # Defaults to using __repr__; override in subclasses
         return None
+    
+    def _repr_markdown_(self):
+        return self._repr_html_()
 
     @property
     def repr_format(self):


Test patch:
diff --git a/control/tests/statesp_test.py b/control/tests/statesp_test.py
index 0806696f0..e3d78bbdd 100644
--- a/control/tests/statesp_test.py
+++ b/control/tests/statesp_test.py
@@ -1440,6 +1440,7 @@ def test_html_repr(gmats, ref, dt, dtref, repr_type, num_format, editsdefaults):
     dt_html = dtref.format(dt=dt, fmt=defaults['statesp.latex_num_format'])
     ref_html = ref[refkey].format(dt=dt_html)
     assert g._repr_html_() == ref_html
+    assert g._repr_html_() == g._repr_markdown_()
 
 
 @pytest.mark.parametrize(