Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tm_sympy - Correctly handle exceptions and output formatting #15470

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mardukbp
Copy link
Contributor

@mardukbp mardukbp commented Nov 8, 2018

References to other Issues or PRs

Brief description of what is fixed or changed

Given some input code, tm_sympy checks whether it is an expression or a statement. Executing a statement does not generate output. If the result of evaluating an expression is a SymPy object, tm_sympy outputs its LaTeX representation.

Other comments

Release Notes

  • other
    • [TeXmacs] Exceptions are correctly handled and the interactive session does not hang anymore.
    • [TeXmacs] SymPy output is sent to TeXmacs as LaTeX. Any other output is displayed verbatim.

Depending on the type of the output it is processed accordingly and sent to TeXmacs.
@sympy-bot
Copy link

sympy-bot commented Nov 8, 2018

Hi, I am the SymPy bot (v134). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • other
    • [TeXmacs] Exceptions are correctly handled and the interactive session does not hang anymore. (#15470 by @mardukbp)

    • [TeXmacs] SymPy output is sent to TeXmacs as LaTeX. Any other output is displayed verbatim. (#15470 by @mardukbp)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.4.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234". See
https://github.com/blog/1506-closing-issues-via-pull-requests .-->


#### Brief description of what is fixed or changed

Given some input code, tm_sympy checks whether it is an expression or a statement. Executing a statement does not generate output. If the result of evaluating an expression is a SymPy object, tm_sympy outputs its LaTeX representation.

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* other
  * [TeXmacs] Exceptions are correctly handled and the interactive session does not hang anymore.
  * [TeXmacs] SymPy output is sent to TeXmacs as LaTeX. Any other output is displayed verbatim.
<!-- END RELEASE NOTES -->

@asmeurer
Copy link
Member

asmeurer commented Nov 9, 2018

I'm still not clear how to actually use the plugin in TeXmacs.

Also I noticed that TeXmacs lists several plugins for other CASes in its help menu. Would it make sense to move the TeXmacs plugin from the SymPy repo to the TeXmacs repo, so that they can maintain it? As far as I know, no SymPy maintainers use the plugin, so it isn't being very well maintained here.

Given some input code, check whether it is an expression or a statement. Executing a statement does not generate output.
The result of evaluating a Python expression can be of two types: either it has a LaTeX representation or it does not.
@mardukbp mardukbp changed the title tm_sympy - Improved output tm_sympy - Correctly handle exceptions and output formatting Nov 10, 2018
@mardukbp
Copy link
Contributor Author

In order to use the plugin go to Insert > Session > SymPy and use it as a normal REPL. But try it with the latest version of this pull request. These are the most important fixes that will finally allow people to use SymPy in TeXmacs. I was frustrated for many years, but now I know how to make it work.

It is unfortunate that not many people use SymPy with TeXmacs. The other day I read a thread in which people expressed their preference for Mathematica over Jupyter only because of 2D math input. TeXmacs predates even IPython. But I admit that it is intimidating. It took me years to have the courage to learn to use it. But just like with Emacs and Haskell, it is well worth it.

Below you will see 2D input in action, but that is only the tip of the iceberg. I am working on a pull request for tighter TeXmacs integration, including syntax highlighting and tab completion.

sympy_texmacs

I would prefer to keep contributing my improvements to this plugin to this repo for two reasons:

  • IMHO GitHub is a more efficient tool for software development than its GNU counterpart. Therefore, it makes it easier for many people to improve this plugin.
  • It will mostly be Python code dealing with SymPy

I would like to suggest that SymPy advertises the TeXmacs interface. The problem with TeXmacs is that it does not have a large community and Scheme is not as popular as Python. But if the scientific Python community notices its potential, I believe that it can become at the very least an inspiration.

For example, one can store all the calculations behind an equation, and only display the equation. In my view, this should be the future of scientific papers. No more "after long and tedious algebra", that is not trivial and the result might be wrong.

@asmeurer
Copy link
Member

OK, now that I know how to use the plugin, I can't get it to actually install. My ~/.TeXmacs/plugins/sympy/ is a copy of data/TeXmacs. Should we include a small install script with the plugin?

I would like to suggest that SymPy advertises the TeXmacs interface.

Having a README included with the TeXmacs plugin a good start for this. Any other places you see where we should advertise it?

Also, one of the reasons I want to include the plugin with TeXmacs itself is so that TeXmacs advertises SymPy in its list of builtin plugins. It already includes several other CASes, both open and closed.

@mardukbp
Copy link
Contributor Author

I did some experimenting and found the solution. Execute Tools > Update > Plugins. But there is still the PATH problem. I will tell the TeXmacs devs to include a launcher script in the macOS bundle, just like they do in Linux. In the meantime, use open /Applications/TeXmacs-1.99.8.

There is no need for an installer script, but I will certainly write an INSTALL file. As for the README I will write a TeXmacs document that explains how to to use the plugin.

Any other places you see where we should advertise it?

Yes, SymPy's website. I have the impression that SymPy does not get the attention it deserves and that is in part due to poor advertisement. As I see it, it is the only free-software CAS that has a large and vibrant community, and it is easy to extend and adapt to your needs. In addition, SymEngine can speed up very large computations that come up in scientific research, and coupled with Julia one can efficiently evaluate expressions numerically. Those are big selling points. But many scientists are still stuck with Mathematica. That can change with the help of TeXmacs.

TeXmacs can provide a cross-platform GUI with context menus, interactive dialogs, inline plots, an XML store for your session, not to mention beautifully typeset prose and math that you can export to PDF, HTML, LaTeX. And much more.

I'm working on implementing the things I mentioned above. Once the SymPy plugin is beta-quality, I will prepare some screenshots for the website. All these years of effort by so many people deserve much more recognition. The best homage to SymPy is for it to become THE go-to CAS. Let's make it happen!

I can submit the SymPy plugin to the TeXmacs repo and will take care of keeping it updated, but I will continue the development here, with the support of the SymPy community :)

@asmeurer
Copy link
Member

I am still unable to test this. When I start TeXmacs and try to open a menu it just hangs.

@asmeurer
Copy link
Member

It eventually stopped hanging and I was able to start the plugin. It just says "Busy..." after each input, though.

In the terminal it says

TeXmacs] debug-shell, Launching 'tm_sympy --texmacs'
TeXmacs] debug-shell, TeXmacs] Error: cannot start 'tm_sympy --texmacs'

@asmeurer
Copy link
Member

By the way, a minor issue: in the plugin, the input prompt says "Sympy]", but it should be spelled "SymPy]".

@mardukbp
Copy link
Contributor Author

mardukbp commented Nov 15, 2018

It eventually stopped hanging and I was able to start the plugin.

Which version of macOS do you have? Now I am using 10.11 and have not experienced any issues.

In the terminal it says
TeXmacs] Error: cannot start 'tm_sympy --texmacs'

I believe chmod +x tm_sympy should fix this.

The prompt now uses the correct spelling SymPy
@mardukbp
Copy link
Contributor Author

By the way, a minor issue: in the plugin, the input prompt says "Sympy]", but it should be spelled "SymPy]".

Yeah, that is auto-generated by TeXmacs. I have fixed that now.

@asmeurer
Copy link
Member

The tm_sympy file is already executable (this is tracked by git).

@asmeurer
Copy link
Member

Is it possible the tm_sympy is raising an exception, but it isn't being printed to the terminal? I suspect the problem is that it's using my system Python, which doesn't have SymPy installed.

@mardukbp
Copy link
Contributor Author

I don't think so. When Python cannot find SymPy, the exception is printed in TeXmacs. I checked the source code of TeXmacs, the problem seems to be that Qt cannot launch the process. Is there any character that needs quoting or a non-ASCII character in the path of tm_sympy?

I will try to take a closer look in the coming days.

@asmeurer
Copy link
Member

No. There aren't any spaces in the path either.

@oscarbenjamin oscarbenjamin added the Uncategorised Doesn't fit other labels... label Jan 23, 2019
@oscarbenjamin
Copy link
Contributor

What's the status of this?

@oscarbenjamin oscarbenjamin added the PR: author's turn The PR has been reviewed and the author needs to submit more changes. label Jan 28, 2019
@asmeurer
Copy link
Member

I wasn't able to get it working, though that could just be because I am using macOS. If someone can verify that it works on Linux, we can merge this and fix the Mac issues later.

@jksuom
Copy link
Member

jksuom commented Jan 28, 2019

I am testing on Ubuntu 14.04. I had some trouble adding SymPy to the search path but, after I managed to do that, the welcome message appeared all right. What kind of tests should be done in addition?

@czgdp1807
Copy link
Member

@asmeurer @jksuom Can it be merged? The last few comments show that it is ready to go in.

@czgdp1807
Copy link
Member

@asmeurer @oscarbenjamin @jksuom Is this ready for merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: author's turn The PR has been reviewed and the author needs to submit more changes. Uncategorised Doesn't fit other labels...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants