Calysto / matlab_kernel

Jupyter Kernel for Matlab
Other
469 stars 76 forks source link

MathJax/Latex Output #142

Open mlg556 opened 4 years ago

mlg556 commented 4 years ago

I was wondering if it was somehow possible to implement displaying the symbolic variables in the notebook environment like sympy does.

For clarification, this is the current situation: Current situation:

How symbolic output is displayed in sympy: Output in sympy

blink1073 commented 4 years ago

I don't believe so, the ipython kernel is doing some magic to generate display messages.

cjwomack commented 6 months ago

Not quite what you want but you can generate a latex representation of the expression using latex((a+5)/(a-3))

and copy the output between '' and paste the output between that into $$ either in markdown or in another cell using %%latex or %latex

I have noticed that fprintf("$%s$", latex((a+5)/(a-3))); gives a string close to the latex expression with text/latex if _execute_sync doesn't print the output using self.Print and uses self.Display instead???

Maybe if a line magic was created %symlatex and the magic made the expression expr was bracketed by fprintf("$%s$", latex(expr));

Then one would need to search within the output for $... $ and then set this fragment to be a text/latex and use the Ipython.display maybe...

Anyway, this is a rough idea...

cjwomack commented 6 months ago

On second thoughts, a line magic would be rather annoying and I'm not even sure existing metakernel code allows for the magic code to become normal code.

If one could invent ending line magic in this case this would be okay only if %symlatex or whatever name was; the last thing on the line with whitespace....

The delimiter to wrap around the latex expr generated by matlab maybe shouldn't be $ $, it could be something else.... but would need to be replaced to $ $ in the json

Anyway, I was investigating things re typing an maths assignment up....