Opened 13 years ago

Closed 13 years ago

#6012 closed enhancement (fixed)

[with patch, positive review] allow use of pdflatex instead of latex

Reported by: John Palmieri Owned by: John Palmieri
Priority: major Milestone: sage-4.0
Component: misc Keywords:
Cc: Rob Beezer, Fidel Barrera-Cruz Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

With this patch, you can use pdflatex instead of latex, in two different ways: use a %pdflatex cell in the notebook, or call

latex.pdflatex(True)

after which any use of latex (in a %latex cell or using the view command) will use pdflatex.

This way, if you have the most recent version of pgf installed, as well as the tkz-graph package, you can get pictures like those at http://altermundus.com/pages/graph.html in your notebook. (I think that tkz-graph might require using pdflatex instead of latex. In any case, I could successfully get the graph in a %pdflatex cell -- see graph.png -- but not in a %latex cell.)

Attachments (2)

pdflatex.patch (7.2 KB) - added by John Palmieri 13 years ago.
graph.png (99.2 KB) - added by John Palmieri 13 years ago.
screenshot

Download all attachments as: .zip

Change History (9)

Changed 13 years ago by John Palmieri

Attachment: pdflatex.patch added

Changed 13 years ago by John Palmieri

Attachment: graph.png added

screenshot

comment:1 Changed 13 years ago by John Palmieri

Cc: Rob Beezer added

comment:2 Changed 13 years ago by Rob Beezer

Cc: Fidel Barrera-Cruz added

%latex seems to fail on the use of dvipng. When I run dvipng outside of Sage on a dvi file having graphs in it, I get boatloads of warnings:

dvipng warning: PostScript environment contains DVI commands

the failures seem to occur when dvipng calls Ghostscript - I see errors from Ghostscript when I run dvipng outside of Sage, and if I use %latex_debug in the notebook, the last output is a Ghostscript error message.

Outside of Sage, I can take source with tkz-graph code, run (plain)latex, then convert the dvi to Postscript with dvips, then convert to PNG with imagemagick's convert. I get full pages with numbers, and the resolution looks a bit crummy, but I presume that can be fixed with options.

(1) Is it reasonable to expect dvipng to process these dvi files right? Should we (me) contact the tkz-graph author to inquire?

(2) Is it worth the trouble to go latex->dvi->ps->png for a %latex cell, or just be content with %pdflatex working properly?

This is very nice. To be able to go get a pretty PNG of a graph in the notebook with just a few lines of code will be fantastic. I'll be working on a review.

comment:3 Changed 13 years ago by John Palmieri

%latex seems to fail on the use of dvipng.

This isn't because of this patch, is it? I can't get these graphs to appear using a %latex cell with or without the patch -- I can only use %pdflatex with the patch.

Outside of Sage, I can take source with tkz-graph code, run (plain)latex, then convert the dvi to Postscript with dvips, then convert to PNG with imagemagick's convert. I get full pages with numbers, and the resolution looks a bit crummy, but I presume that can be fixed with options.

Can you temporarily move dvipng out of your path and see what Sage does then? (If it can't find dvipng, then it should use dvips and convert.) That works for me. I don't know what the problem with dvipng is. Is it worth trying to see (in Latex()) if dvipng gives error messages and if so, switching to the latex -> dvi -> ps -> png conversion?

comment:4 in reply to:  3 Changed 13 years ago by Rob Beezer

Replying to jhpalmieri:

This isn't because of this patch, is it? I can't get these graphs to appear using a %latex cell with or without the patch -- I can only use %pdflatex with the patch.

It's not the patch's fault. It's dvipng failing no matter what on the dvi created by tkz-graph. Somewhere I got the impression tkz-graph played fast and loose with \special's or something like that, which is why I previously thought pdflatex was *required*. But I'm not sure I understand the exact nature of the problem here, so I shouldn't throw stones.

Can you temporarily move dvipng out of your path and see what Sage does then? (If it can't find dvipng, then it should use dvips and convert.) That works for me. I don't know what the problem with dvipng is. Is it worth trying to see (in Latex()) if dvipng gives error messages and if so, switching to the latex -> dvi -> ps -> png conversion?

have_dvipng() caches its result. :-( That cost me 5 minutes. ;-) But, yes, that works - renamed dvipng temporarily, loaded up the preamble in one cell, used %latex_debug in a second cell, followed with the Altermundus graph in the screenshot, Great-looking PNG in the notebook results.

dvipng has a --picky switch which is designed for just this (I think, \specials etc). It results in no output on warnings - I just tested it. Guess you could then test for the presence of output (are filenames unique across runs?) or perhaps test for newer output with the right name. Or maybe there is something easier.

I got view() tested in the notebook, which was a bit of a hack to get the right string in. Let me know how you want to proceed and I'm ready to give this a positive review. I'll be in/out the rest of the afternoon before a 6 PM engagement and have IRC on.

comment:5 Changed 13 years ago by John Palmieri

I think that if you're happy with the patch, we should put it in. The issue with dvipng (or whatever) is separate, so should be dealt with separately, if at all.

comment:6 Changed 13 years ago by Rob Beezer

Summary: [with patch, needs review] allow use of pdflatex instead of latex[with patch, positive review] allow use of pdflatex instead of latex

Sounds good. I'm very happy with this patch. Has a limited scope and passes tests on affected files. Positive review.

Adds a "pdflatex" chain, so %pdflatex in notebook cells will produce PNG's using pdflatex, or at the command-line view() will produce a PDF and call a PDF viewer. This functionality allows the tkz-graph package to work, once the package is included in the latex preamble.

Exposes some problems with the dvipng utility on some dvi files, which could be routed through this new pdflatex chain as an alternative.

comment:7 Changed 13 years ago by Michael Abshoff

Milestone: sage-4.0.1sage-4.0
Resolution: fixed
Status: newclosed

Merged in Sage 4.0.alpha0.

Cheers,

Michael

Note: See TracTickets for help on using tickets.