Opened 12 years ago

Closed 12 years ago

#1766 closed enhancement (fixed)

[with patch, positive review] enhancing latex embedding with plots

Reported by: schilly Owned by: mhansen
Priority: major Milestone: sage-3.0
Component: documentation Keywords: latex, sagetex, latex_embed
Cc: Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

This is patch for the latex_embed inside the ${SAGE_BASE}/examples directory.
Now embedding plots works and makes it more usable!
Read included README.txt for more information and open the included PDF example.pdf to see the result.

Attachments (4)

latex_embedding.hg (8 bytes) - added by schilly 12 years ago.
latex_embed_updates.hg (203.7 KB) - added by ddrake 12 years ago.
patch to current version of sagetex.{sty,py}
latex_embed_updates.2.hg (203.7 KB) - added by ddrake 12 years ago.
patch to current version of sagetex.{sty,py}
sagetex.patch (93.1 KB) - added by ddrake 12 years ago.

Download all attachments as: .zip

Change History (30)

Changed 12 years ago by schilly

comment:2 in reply to: ↑ description Changed 12 years ago by schilly

ignore the .hg, it is outdated and i cannot upload the current one because of it's size

use the link above to the zip file!

comment:3 Changed 12 years ago by schilly

  • Type changed from defect to enhancement

comment:4 follow-up: Changed 12 years ago by wjp

It might be nice to change the filenames used for plotting to .pdf instead of .png. This should automagically turn the included plots into vector graphics instead of bitmaps. It works for the example.tex in the .zip, but I'm not familiar enough with the plotting code to know if it has any drawbacks.

comment:5 Changed 12 years ago by was

Plotting pdf's by default may have drawbacks -- at least last time I checked the pdf rendering for matplotlib was less mature than the png renderer. This could be an issue in some cases. However, of course getting vector graphics is a huge plus.

comment:6 in reply to: ↑ 4 Changed 12 years ago by schilly

Replying to wjp:

This should automagically turn the included plots into vector graphics instead of bitmaps.

ahh okay, if this works for all types of plots (plot, matrix_plot, graphs, 3d graphs, ...) then it should be done that way. i'll try this. perhaps i'm able to make the extension customizable, then the user can select it and pdf is default. or if there are useful errors, it fallbacks from pdf to png.

comment:7 follow-up: Changed 12 years ago by schilly

I've updated the code to default to .pdf files now. Plots are fine and output-quality much better now!
It's also possible to pass more arguments to the show command. Therefore it is possible to switch back to .png if there are problems.
But plotting 3d-Graphs doesn't work (and has never) because the .show(..) command of the tachyon renderer has no filename= option. essentially, this .show() is entirely different (also docstring missing) - i'll open a ticket for this and possibly related problems.

comment:8 in reply to: ↑ 7 Changed 12 years ago by schilly

Replying to schilly:

...the .show(..) command of the tachyon renderer has no filename= option. essentially, this .show() is entirely different (also docstring missing) - i'll open a ticket for this and possibly related problems.

This is now #1925

comment:9 Changed 12 years ago by mabshoff

  • Summary changed from [with patch] enhancing latex embedding with plots to [with patch, needs review] enhancing latex embedding with plots

Changed 12 years ago by ddrake

patch to current version of sagetex.{sty,py}

Changed 12 years ago by ddrake

patch to current version of sagetex.{sty,py}

comment:10 Changed 12 years ago by ddrake

Please ignore the bundles! I'm still new to Mercurial.

The patch updates sagetex.{sty,py}, but there's more to be done. The biggest issue is that when running Sage on the produced .sage file, it pops up windows with all the plots. (In Ubuntu gutsy, at least.) We need to find a way to keep Sage from doing this while processing the script.

comment:11 Changed 12 years ago by ddrake

  • Keywords latex sagetex latex_embed added

I've made huge improvements to the sagetex stuff. The .sty file has been rewritten and now works much better; all the previous problems have been fixed. The source code for both the .sty and .py files are bundled into a Docstrip .dtx file, which allows much better documentation.

Please try this out! I'd like to get it in soon.

comment:12 follow-up: Changed 12 years ago by dfdeshom

I can't apply this cleanly...

dfdeshom@sage:~/custom/sage/examples$ ../sage -hg import 1766.patch
applying 1766.patch
not in dirstate: latex_embed/auto/example.el!
not in dirstate: latex_embed/auto/sagetex.el!

Should I have the above-mentioned files? in latex_embed/?

comment:13 in reply to: ↑ 12 ; follow-up: Changed 12 years ago by ddrake

Replying to dfdeshom:

I can't apply this cleanly...

...

Should I have the above-mentioned files? in latex_embed/?

Those aren't related to the sagetex stuff; they are something that emacs makes. I deleted them since they're not directly related to sagetex (and because I'm a vim person :).

At any rate, they are not important and you can ignore problems related to them. I can redo the patch if you'd like.

comment:14 in reply to: ↑ 13 Changed 12 years ago by dfdeshom

Replying to ddrake:

At any rate, they are not important and you can ignore problems related to them. I can redo the patch if you'd like.

Yes, could you please redo it?

comment:15 follow-up: Changed 12 years ago by jason

  • Summary changed from [with patch, needs review] enhancing latex embedding with plots to [with patch, positive review pending a few concerns] enhancing latex embedding with plots

This patch applies cleanly to 2.10.2 for me.

Overall, I think this is great stuff! I give this a positive review pending addressing a few concerns:

  • when latexing a file, if a plot does not exist, the texing stops and gives an error. Pressing enter through the errors, running sage, and then texing again works, but it is still disconcerting. Is there any way to ignore the non-existence of a plot file, maybe with a warning that sage needs to be run?
  • The patch says that E2.sobj changed. Can we delete the file?
  • In the readme, at first glance, it looks like I just need to follow the 1, 2, 3, 4 instructions, which of course give an error if I haven't latexed the dtx file yet. Can you somehow highlight that in the readme instead of it being buried right before what looks like the important, step-by-step instructions?
  • credit: somewhere, I think you ought to mention the people that did the original interface. Maybe a note in the readme might be appropriate. It also looks weird to have "and others" in the documentation...how about either explicitly putting their names there or just put your name there and a note mentioning that it is based on an original interface by whoever. I'm not sure the best way to handle this (you're the one that knows how much code was there before and how much code you've done), but some note somewhere probably is in order.

That said, as soon as I saw this patch I immediately tested it, saw that it worked great, and sent the example pdf and tex file to a friend who was discussing the sage and tex combination just this last weekend. I know he'll be excited!

comment:16 in reply to: ↑ 15 Changed 12 years ago by ddrake

Replying to jason:

  • when latexing a file, if a plot does not exist, the texing stops and gives an error. Pressing enter through the errors, running sage, and then texing again works, but it is still disconcerting. Is there any way to ignore the non-existence of a plot file, maybe with a warning that sage needs to be run?

This can be done, but then the only way to tell that you need to run Sage is the package warning issued at the end of running latex, which I tried to make reasonably obvious but can be missed. As it is, the missing file error looks like

! LaTeX Error: File `sage-plots-for-example.tex/plot-0' not found.

which, along with the package warning at the end of the run, is reasonably informative, and it behaves like \includegraphics commands.

If you really want latex to run without stopping, you can always use latex -interaction=nonstopmode.

The current behavior seems more natural to me, but I can change it if that's the consensus. I can also have the behavior be toggle-able via a package option.

  • The patch says that E2.sobj changed. Can we delete the file?

Yes. It's just cruft that example.tex produces. It gets regenerated when you run Sage on the example.sage script.

  • In the readme, at first glance, it looks like I just need to follow the 1, 2, 3, 4 instructions, which of course give an error if I haven't latexed the dtx file yet. Can you somehow highlight that in the readme instead of it being buried right before what looks like the important, step-by-step instructions?

Ah, so you couldn't be bothered to read the text, and took the easy way out? :)

I changed the readme to make that a bit more obvious. Perhaps I'm just too accustomed to .dtx and .ins files -- ideally we will eventually distribute this with some processing already done, so that the prospective user can read the documentation and see the example file without doing any processing.

  • credit: somewhere, I think you ought to mention the people that did the original interface. Maybe a note in the readme might be appropriate. It also looks weird to have "and others" in the documentation...how about either explicitly putting their names there or just put your name there and a note mentioning that it is based on an original interface by whoever. I'm not sure the best way to handle this (you're the one that knows how much code was there before and how much code you've done), but some note somewhere probably is in order.

I already had some credits at the end of the documentation, but I added a line in the readme pointing to them.

That said, as soon as I saw this patch I immediately tested it, saw that it worked great, and sent the example pdf and tex file to a friend who was discussing the sage and tex combination just this last weekend. I know he'll be excited!

Sweet! I'm glad to hear that other people think this is as cool as I do.

comment:17 Changed 12 years ago by ddrake

The current version of the patch only modifies files and adds them; this will avoid problems with missing cruft files. It addresses all of jason's concerns except for the first bullet point; I'm not sure what to do with that yet.

I do think we need to get those files out of the repo; we are version controlling .aux and .log files from LaTeX, as well as a .pyc file! Is it okay for me to upload bundles, or should I stick to patches? On #sage-devel it seemed like patches are preferred.

comment:18 follow-up: Changed 12 years ago by schilly

I've updated the all-in-one zip file.

In my opinion the README should be more detailed and there is a small problem: when just running the latex/sage/latex commands, the graphics are not included (white boxes with black border). I don't know why that's just how it does it ;) ... using pdflatex at the last step does what's now in the .zip file!

The repository must be cleaned up, because there are files tracked which should not. See .zip file for all necessary files plus the prerendered .pdf docs - they could be included in the repository, because i think it's nice for a new user to instantaneously see what's possible.

thx again to dan.

comment:19 Changed 12 years ago by ddrake

The current version of the patch addresses Jason's first bullet point: missing graphics files no longer cause an error, but they do make LaTeX issue a warning.

comment:20 in reply to: ↑ 18 Changed 12 years ago by ddrake

Replying to schilly:

and there is a small problem: when just running the latex/sage/latex commands, the graphics are not included (white boxes with black border). I don't know why that's just how it does it ;) ... using pdflatex at the last step does what's now in the .zip file!

Hrm, that's odd. I don't have that behavior. But the current version deals with graphics better, so perhaps that will work for you.

The repository must be cleaned up, because there are files tracked which should not. See .zip file for all necessary files plus the prerendered .pdf docs - they could be included in the repository, because i think it's nice for a new user to instantaneously see what's possible.

I agree. No extra cruft beyond the source files, except for PDFs of the documentation and the example file.

comment:21 Changed 12 years ago by ddrake

The current version of the patch fixes a misplaced brace, and adds the imagemagick option.

Changed 12 years ago by ddrake

comment:22 Changed 12 years ago by was

  • Milestone changed from sage-2.11 to sage-2.10.4

comment:23 Changed 12 years ago by schilly

last words on this: sage-devel info about SageTeX@CTAN.

Therefore the entire latex_embed directory should be replaced by these files.

comment:24 Changed 12 years ago by mhansen

  • Owner changed from tba to mhansen
  • Status changed from new to assigned

comment:25 Changed 12 years ago by mhansen

  • Summary changed from [with patch, positive review pending a few concerns] enhancing latex embedding with plots to [with patch, positive review] enhancing latex embedding with plots

I've made http://sage.math.washington.edu/home/mhansen/1766.hg which replaces the current contents of examples/latex_embed with the CTAN files.

comment:26 Changed 12 years ago by mabshoff

  • Resolution set to fixed
  • Status changed from assigned to closed

Merged in Sage 3.0.alpha5

Note: See TracTickets for help on using tickets.