sagemath / sage-shell-mode

Emacs front end for SageMath
GNU General Public License v3.0
98 stars 16 forks source link

[feature] Inline graphics in sage-shell-mode #5

Closed PythonNut closed 7 years ago

PythonNut commented 8 years ago

It would be really cool if sage-shell-mode could display graphics inline, like the official sage-mode does. I'm not sure how difficult this would be to implement, but clearly it is possible. :)

stakemori commented 8 years ago

Thanks for posting this issue. I think it is not so difficult to implement such a feature if I support only recent versions of Sage. I will try to implement it when I have free time. For what it's worth, I made an org-babel package for Sage recently. It supports inline display of graphs.

PythonNut commented 8 years ago

For what it's worth, I made an org-babel package for Sage recently. It supports inline display of graphs.

Indeed. I've recently started using it, and I much appreciate it. In fact, that's what inspired me to open this issue.

EmmanuelCharpentier commented 7 years ago

I second the original idea, and add that displaying a (\LaTeX|markdown) rendering of Sage utput would be extremely useful : I'm much more used to standard mathematical notation than to code output.

You could do that by comparing the output to be displayed with \newcommand{\Bold}[1]{, which seems to prefix any \LaTeX output from Sage.

You might also force \LaTeX rendering of all Sage output (possibly under the control of an option...).

That's (approximately) what did the late sage_mode. And that was damnably useful. Combined with the "code blocks" feature, you'd get almost all the features of the Jupyter notebook...

stakemori commented 7 years ago

@EmmanuelCharpentier, unfortunately, I don't enough time for implementing it this month. I will implement it in a few month. By the way, ob-sagemath is also similar to Sage's notebook and might be useful.

stakemori commented 7 years ago

@PythonNut, @EmmanuelCharpentier, I just added this feature. You can enable sage-shell-view minor mode by (add-hook 'sage-shell-after-prompt-hook #'sage-shell-view). Sorry for taking a long time.

EmmanuelCharpentier commented 7 years ago

On 23/12/2016 09:38, Sho Takemori wrote:

@PythonNut https://github.com/PythonNut, @EmmanuelCharpentier https://github.com/EmmanuelCharpentier, I just added this feature.

Nice stockings filler ! Thank you very much Now, I can work efficiently on both research and report without the notebook (which is nice for research, but not for maintaining a complicated text...).

Note that, at first start (i. e. immediately after updating the package), emacs gave me the Sage banner, but I never got a Sage prompt, and emacs was quite unresponsive. Things went better after killing emacs and its subprocesses (via console) and restarting (from console again).

You can enable |sage-shell-view| minor mode by |(add-hook 'sage-shell-after-prompt-hook #'sage-shell-view)|.

I think that this would be a nice addition to the "Sage" menu ogf the Sage buffer.

If possible in your implementation (the code in sage-shell-view.el is not clear about it), the ability to toggle separately plot output and LaTeX output (i. e. two menu entries) would be even nicer (different use cases : I use LaTeX output quite often, but plot output in a separate window is not much of a chore).

I also suggest to advertize the existence of the "Sage Shell View" customization group, ad possibly to document what can and cannot be customized (e. g. scale for latex output) somewhere in the REAME.md of the Github page.

Sorry for taking a long time.

Don't be sorry ! We are extremely glad of this addition, and grateful for the time and care you gave it. The result was worth waiting...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sagemath/sage-shell-mode/issues/5#issuecomment-268957144, or mute the thread https://github.com/notifications/unsubscribe-auth/AHljTBfHRXhB5EQllFe26NfyvI4JVLutks5rK4h4gaJpZM4HsHwc.

stakemori commented 7 years ago

@EmmanuelCharpentier, thank you very much for the feedback.

Note that, at first start (i. e. immediately after updating the package), emacs gave me the Sage banner, but I never got a Sage prompt, and emacs was quite unresponsive. Things went better after killing emacs and its subprocesses (via console) and restarting (from console again).

I think it would be better to restart Emacs when upgrading any elisp package.

If possible in your implementation (the code in sage-shell-view.el is not clear about it), the ability to toggle separately plot output and LaTeX output (i. e. two menu entries) would be even nicer

Yes, it is possible. To enable only LaTeX output, please set sage-shell-view-default-commands as follows:

(setq sage-shell-view-default-commands 'output)

I also added commands sage-shell-view-toggle-inline-output and sage-shell-view-toggle-inline-plots and added them to the menu.

I also suggest to advertize the existence of the "Sage Shell View" customization group, ad possibly to document what can and cannot be customized (e. g. scale for latex output) somewhere in the REAME.md of the Github page.

I updated sage-shell-view section of README.org. The variable sage-shell-view-scale exists but it is not a customizable variable. Please use sage-shell-view-default-resolution instead. It is passed to the -r option of the gs command and has clearer meaning.

By the way, when inline typesetting enabled, a blank line is inserted before each output. I guess it is due to a bug of Sage 7.4 and should be fixed.

EmmanuelCharpentier commented 7 years ago

Since this issue is still open (while almost perfectly fixed, IMHO, modulo an extra blank line...), I'll use it to warn you that I updated the Sage Wiki Sage mode comparison page, to advertise the recent changes (inline typesetting, inline plots, blocks).

I also mentioned the AUCTeX integration as "customizable". I have some half-cooked ideas about that, but I need to think more about them...

The extra blank line : why do you think it is a Sage bug ? What is the problem ? The Sage view function does not seem to be affected ; maybe you should have a peek ?

Again, thank you very much !

stakemori commented 7 years ago

@EmmanuelCharpentier, thank you very much for updating the wiki (I always forget updating it) and I look forward to your idea about AUCTeX.

The extra blank line : why do you think it is a Sage bug ? What is the problem ? The Sage view function does not seem to be affected ; maybe you should have a peek ?

I have just noticed that if repr(obj) contains a newline character, then an extra blank line is inserted. The Sage version is 7.4. One can also reproduce this in Sage in the terminal. I'm not sure if this is a known bug. I will report this at sage-devel.

When sage-shell-view minor mode enabled, the output is actually as follows:

BEGIN_TEXT:obj:END_TEXT
BEGIN_LATEX:\newcommand{\Bold}[1]{\mathbf{#1}}latex(obj):END_LATEX

So the output always contains a newline. In the latest commit, I removed the newline character from the output.

By the way, I close this issue since porting sage-view.el has been done and open a new issue for the extra blank line.