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

ipython notebook: show compile LaTeX inplace #18116

Open
dkrenn opened this issue Apr 3, 2015 · 41 comments
Open

ipython notebook: show compile LaTeX inplace #18116

dkrenn opened this issue Apr 3, 2015 · 41 comments

Comments

@dkrenn
Copy link
Contributor

dkrenn commented Apr 3, 2015

I also want to discourage the view() command, right now it is just spaghetti code that does different things depending on the time of the day. So I propose to use latex(...).compile() as an idiom to typeset LaTeX code.

See also https://groups.google.com/forum/#!topic/sage-devel/1ozhg8pHXL4

Depends on #17821
Depends on #17942

CC: @paulmasson @JeremiasE

Component: notebook

Keywords: ipython, latex, tikz, sd66

Author: Volker Braun

Branch/Commit: u/vbraun/pdf_wrapper @ 17529b3

Issue created by migration from https://trac.sagemath.org/ticket/18116

@dkrenn dkrenn added this to the sage-6.6 milestone Apr 3, 2015
@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 3, 2015

Changed keywords from ipython, latex, tikz to ipython, latex, tikz, sd66

@dkrenn

This comment has been minimized.

@vbraun
Copy link
Member

vbraun commented Apr 7, 2015

Branch: u/vbraun/pdf_wrapper

@vbraun
Copy link
Member

vbraun commented Apr 7, 2015

comment:4

Basic implementation works...


New commits:

c475636Wrapper for PDF Documents
1f50df6Switch LaTeX output to the new PDF Document wrapper

@vbraun
Copy link
Member

vbraun commented Apr 7, 2015

Commit: 1f50df6

@vbraun
Copy link
Member

vbraun commented Apr 7, 2015

Author: Volker Braun

@vbraun

This comment has been minimized.

@vbraun vbraun changed the title ipython notebook: show LaTeX tikz-graphics inplace ipython notebook: show compile LaTeX inplace Apr 7, 2015
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 7, 2015

Changed commit from 1f50df6 to a6f2fa0

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 7, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

a6f2fa0forgot debug output

@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 8, 2015

comment:6

show(T) stopped working (here I mean that it worked in sagenb showing the transducer inline and before this patch in ipython-notebook by showing it externally as pdf). It would be great if this gives the same as latex(T).compile(), since its docstring says "Show a graphics object x.".

Best wishes

Daniel

@vbraun
Copy link
Member

vbraun commented Apr 8, 2015

comment:7

Launching an external viewer from the notebook server process equals NOT working in my book. So show(T) never worked in the ipython notebook, and this ticket doesn't change that.

The correct way to get graphical output is T.plot(). The fact that this cannot produce the graphics that you want is a bug in the finite state machine code.

The show docstring is correct, it'll show a Graphics object if you provide one. If you don't give it a graphics object then you won't get a picture.

@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 8, 2015

comment:8

Replying to @vbraun:

Launching an external viewer from the notebook server process equals NOT working in my book. So show(T) never worked in the ipython notebook, and this ticket doesn't change that.

On my installations the command

T = transducers.GrayCode()
show(T)

does the following:

@vbraun
Copy link
Member

vbraun commented Apr 8, 2015

comment:9

Thats because #17821 will first have to fix show

@vbraun
Copy link
Member

vbraun commented Apr 8, 2015

Dependencies: #17821

@seblabbe
Copy link
Contributor

Hi Daniel,

Replying to @dkrenn:

I also want to discourage the view() command, right now it is just spaghetti code that does different things depending on the time of the day.
So I propose to use latex(...).compile() as an idiom to typeset LaTeX code.

First, to me the following facts are all completely independent:
A. discourage the use of view()
B. view() is spaghetti code
C. propose latex(...).compile()
So one can't use A or B to suggest C.

Second, I have never liked in Sage the fact that there plenty of ways of drawing things. For an outside person, it is tough to understand the difference plot, show and view ? To me there should be one fonction to do them all. For that reason, I do not like the idea of proposing a fourth one being latex(...).compile() or anything else.

That being said, I really like the idea of being able to show tikz pictures in the ipython notebook.

@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 13, 2015

comment:11

Replying to @vbraun:

I also want to discourage the view() command, right now it is just spaghetti code that does different things depending on the time of the day.

Ok, then the code should change.

So I propose to use latex(...).compile() as an idiom to typeset LaTeX code.

To me it is not clear from the command that this will show a picture.

@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 13, 2015

comment:12

Replying to @seblabbe:

Second, I have never liked in Sage the fact that there plenty of ways of drawing things. For an outside person, it is tough to understand the difference plot, show and view ? To me there should be one fonction to do them all. For that reason, I do not like the idea of proposing a fourth one being latex(...).compile() or anything else.

I agree.

@vbraun
Copy link
Member

vbraun commented Apr 13, 2015

comment:13

latex(...).compile() does not show a picture, it generates a PDF document. The document wrapper object pretty-prints graphically. You can also assign it to a variable, save as a pdf file, etc. In the latter case no picture is shown. Just like graphics objects (the return values of plot, for example)

You can't solve the "its impossible to guess the difference between view/show/pretty_print" conundrum without getting rid of 2 of them (or making them aliases, at least).

@vbraun
Copy link
Member

vbraun commented Apr 13, 2015

comment:14

Also, show acts immediately, like print. Plot does not act immediately, it returns a graphics object that you can use elsewhere and need not result in graphical output.

In other words: its the difference between

def f():
    print 'hello'

and

def f():
   return 'hello'

@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 13, 2015

comment:15

Replying to @vbraun:

Also, show acts immediately, like print. Plot does not act immediately, it returns a graphics object that you can use elsewhere and need not result in graphical output.

I see; thanks for this clearification.

@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 13, 2015

comment:16

Replying to @vbraun:

latex(...).compile() does not show a picture, it generates a PDF document. The document wrapper object pretty-prints graphically. You can also assign it to a variable, save as a pdf file, etc. In the latter case no picture is shown. Just like graphics objects (the return values of plot, for example)

You can't solve the "its impossible to guess the difference between view/show/pretty_print" conundrum without getting rid of 2 of them (or making them aliases, at least).

So view(A) does (or should do) the same as show(latex(A).compile()). Or am I wrong? If yes, can we just replace the code of view by this command?

@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 13, 2015

comment:17

Would it be possible to have an arguemtn to show which says to look for latex-output? ...like show(A, what='latex') (with a better name)

@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 13, 2015

comment:18

Anyhow, should the discussion about view be on another ticket (and/or on sage-devel)? My motivation for opening this ticket was to have inline-plots for tikz, which works with .compile().

@vbraun
Copy link
Member

vbraun commented Apr 13, 2015

comment:19

Making view an alias for show(latex(..).compile()) doesn't make it one bit more self-explanatory.

The only real alternative is make latex objects display graphically by default, i.e.

sage: latex(1/2)

would use the displayhook to show mathjax or pdf. Thats possible, but I think many people use latex to generate latex code to paste into their articles and not to get cute pictures in the notebook.

@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 13, 2015

comment:20

Replying to @vbraun:

Making view an alias for show(latex(..).compile()) doesn't make it one bit more self-explanatory.

True. (But having something (a function?) similar is/will be very handy.)

@seblabbe
Copy link
Contributor

comment:21

Replying to @vbraun:

The only real alternative is make latex objects display graphically by default, i.e.

sage: latex(1/2)

would use the displayhook to show mathjax or pdf.

+1, there should be a method of LatexExpr that shows it pretty like LatexExpr.__pprint__ that is used by the displayhook thing.

Thats possible, but I think many people use latex to generate latex code to paste into their articles and not to get cute pictures in the notebook.

Well, they could still do:

sage: latex(1/2) # shows graphically
sage: print latex(1/2) # prints the source

@vbraun
Copy link
Member

vbraun commented Apr 14, 2015

comment:22

Replying to @seblabbe:

+1, there should be a method of LatexExpr that shows it pretty like LatexExpr.__pprint__ that is used by the displayhook thing.

You say that because the objects that you are interested in have a broken plot() method, so you prefer graphical output generated by compiling latex. What if plot would actually work in the first place (i.e. have a proper tikz backend for Graphics objects)

@seblabbe
Copy link
Contributor

comment:23

Replying to @vbraun:

You say that because the objects that you are interested in have a broken plot() method, so you prefer graphical output generated by compiling latex. What if plot would actually work in the first place (i.e. have a proper tikz backend for Graphics objects)

  1. Through the years, I have been used in Sage for the plot() method to return a Graphics() object (and not anything else). If it can be made more general, why not?

  2. I have used cases where I use both : plot() method for returning a Graphics or a Graphics3D sage object and _latex_() method for returning the tikz code. This is the case for instance for polyhedron in Sage where you can first use jmol to choose a nice projection and then create the tikz code using a chosen projection. Therefore, if plot() can now return output generated by latex, I still want it to draw my other Graphics sage object output maybe using some other arguments.

  3. I think we don't have to hide the object LatexExpr to the user. I mean view or plot or show could just return the compiled default latex expression. But sometimes (graph for instance), there are many latex output (depending on which graphviz program I use). So, to me it is not the object that I draw, it is a latex expression. Therefore, there should be still a way to obtain the latex expression of an object and then draw it.

@vbraun
Copy link
Member

vbraun commented Apr 14, 2015

comment:24

Plot should still return a graphics object. I'm saying that graphics objects should support tikz (next to matplotlib) to draw graph-type graphics objects. Just like 3-d graphcs objects can be rendered in different ways.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 18, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

8577e87Refactor pretty_print/show to use the rich output system
42f4985remove the unused and broken print_or_typeset
70e4d3afix doctest in symbolic expression show()
6278235Merge tag '6.7.beta1' into #17821
41f0a57fix broken docstring
43b77c1Merge #17821 into #18116
b3e55dcadd a pdf.show(dpi=...) method

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 18, 2015

Changed commit from a6f2fa0 to b3e55dc

@vbraun
Copy link
Member

vbraun commented Apr 22, 2015

Changed dependencies from #17821 to #17821, #17942

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 22, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

91830deInitial implementation of a download link in the IPython notebook
16cb948Add SageNB support, automatic download in the ipython notebook
e9ad72afix doctests
abaf94bMerge branch 'develop' into #17942
18968d0Merge Sage-6.7.beta2 into #17942
c9f1718fix documentation build
ed9898ddocumentation fix
4360b79Merge #17942 into #18116
6c1b02aimplement pdf.save

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 22, 2015

Changed commit from b3e55dc to 6c1b02a

@vbraun
Copy link
Member

vbraun commented Apr 22, 2015

comment:28

This is now ready for review. I'll leave SVG support for later (#18280)

@seblabbe
Copy link
Contributor

seblabbe commented Nov 4, 2015

comment:29

The branch does not apply since sage-6.8.beta3.

@dkrenn
Copy link
Contributor Author

dkrenn commented May 22, 2016

comment:30

There is some kind of solution to the original problem of this ticket at #19515. The original problem was:

view(latex(transducers.GrayCode())) 

shows the transducer inplace in sagenb but it is a pitty that this does not work in the ipython notebook.

latex(transducers.GrayCode())

writes tikz-code.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 22, 2016

Changed commit from 6c1b02a to 17529b3

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 22, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

e4d709fMerge in sage-7.2
17529b3Fix doctest failures

@vbraun
Copy link
Member

vbraun commented May 22, 2016

comment:32

Updated...

@paulmasson
Copy link
Mannequin

paulmasson mannequin commented Sep 18, 2016

comment:33

Merge conflict with 7.4.beta5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants