Hi Mojca, if you're still looking for a gnuplot module, here is one: http://pmrb.free.fr/work/OS/ConTeXt/t-gnuplot.tex Cheers, Peter -- http://pmrb.free.fr/contact/
On 1/2/06, Peter Münster wrote:
Hi Mojca, if you're still looking for a gnuplot module, here is one:
Yes, I'm still looking for it.
Thanks a lot. I've learnt a lot from the example, it's only that in the way it's written now it's not compatible with windows. I've made a gnuplot.bat. It can be called with gnuplot somescript epstopdf somescript where somescript is something like set terminal postscript eps # should be added automatically set output "someuniquename" # should be added automatically plot sin(x) # between \startGnuplot ... \stopGnuplot My question is: how can I put this into the same buffer (file) without using OS-specific commands? (piping didn't work) The rewritten version of the module works if I add the first two lines manually between \startGnuplot ... \stopGnuplot, but that should be done automatically by the module itself. I looked into metafun code, but it's still too complicated for me to understand it and use it for gnuplot. Gnuplot would also need some kind of \startGnuplotinclusions for stuff like set nokey set xlabel "time" plus the lines for setting the terminal which would automatically be added. (I don't like the postscript terminal itself, but that module s a good start.) Mojca
On Tue, 3 Jan 2006, Mojca Miklavec wrote:
Thanks a lot. I've learnt a lot from the example, it's only that in the way it's written now it's not compatible with windows.
Hello Mojca, if you are using Windows, you can install MinGW, it's free and bash is included.
Gnuplot would also need some kind of \startGnuplotinclusions for stuff like set nokey set xlabel "time" plus the lines for setting the terminal which would automatically be added.
or something like \setupGnuplot with keys=vals!
(I don't like the postscript terminal itself, but that module s a good start.)
At least, it's not bitmap. But there is a white border around the plot. It would be nice to have a clipping-option in \externalfigure. Cheers, Peter -- http://pmrb.free.fr/contact/
On 1/3/06, Peter Münster wrote:
On Tue, 3 Jan 2006, Mojca Miklavec wrote:
Thanks a lot. I've learnt a lot from the example, it's only that in the way it's written now it's not compatible with windows.
Hello Mojca, if you are using Windows, you can install MinGW, it's free and bash is included.
OK, that could be file for me and maybe for two others, but this can't be a general solution. (Beginners wouldn't install it and the skilled ones have linux anyway.) So my question for gurus remains: how to write a macro, so that \startGnuplotinclusions set title "trigonometry" \stopGnuplotinclusions \startGnuplot plot sin(x) \stopGnuplot \startGnuplot plot cos(x) \stopGnuplot would result in one file with set terminal postscript set output "filename1" set title "trigonometry" plot sin(x) and the other one with set terminal postscript set output "filename2" # If too complicated, the filename may remain the same set title "trigonometry" plot cos(x) Out of curiosity: does "metafun" check if the buffers were changed, so that compiling again the same file is skipped next time? (For a little module as this one it's too little gain for too much anyway.)
Gnuplot would also need some kind of \startGnuplotinclusions for stuff like set nokey set xlabel "time" plus the lines for setting the terminal which would automatically be added.
or something like \setupGnuplot with keys=vals!
Well, ... yes. That also, of course. Those could be use to set engine to postscript/eps/metapost/png/... or even LaTeX. (But for the beginning, I would be greatful for even the dummiest possible solution.) If ConTeXt terminal would be written, maybe this could be used also for setting symbols, default colors, ... etc.
(I don't like the postscript terminal itself, but that module s a good start.)
At least, it's not bitmap.
I use LaTeX as the terminal otherwise (but your module can be modoified to use LaTeX terminal and convert into PDF as well). If I will find some time and additional motivation (sorry, less motivation for other things), I would like to modify the "metapost.trm". It's only 1000 lines (postscript is a bit longer), but very well structured code and much better understandable than TeX which is still cryptography for me. (Even in that case I would still need a lot of help from the ConTeXt side.)
But there is a white border around the plot. It would be nice to have a clipping-option in \externalfigure.
I would prefer to leave the border in this case as the default behaviour (for example if you have two graphs with different labels, you want the graphs to have the same size, not cropped because of slightly different name for the y axis), but I vote for that feature too. (Hans?) Some time ago Hans mentioned that texexec can crop, but I didn't manage to make it work (it was converting from PDF to PS and back, but it didn't crop anything). There's a nice working script on CTAN (http://www.ctan.org/tex-archive/support/pdfcrop/) for cropping. I guess that texexec could do that as well, but some half year ago as I tried it, I had no luck. Thanks again for all that, Mojca
Mojca Miklavec wrote:
Out of curiosity: does "metafun" check if the buffers were changed, so that compiling again the same file is skipped next time? (For a little module as this one it's too little gain for too much anyway.)
if you process between runs (texexec --automp) such a check is done Hans
Mojca Miklavec wrote:
Some time ago Hans mentioned that texexec can crop, but I didn't manage to make it work (it was converting from PDF to PS and back, but it didn't crop anything). There's a nice working script on CTAN (http://www.ctan.org/tex-archive/support/pdfcrop/) for cropping. I guess that texexec could do that as well, but some half year ago as I tried it, I had no luck.
(new)pstopdf can crop (bound) long ago i made a perl script called "cropcrap" which will be in the next distribution under the name "pdftrimwhite" (the more decent name as suggested by karl berry); however, this script works on pdf files Hans
Mojca Miklavec wrote:
On 1/3/06, Peter Münster wrote:
On Tue, 3 Jan 2006, Mojca Miklavec wrote:
Thanks a lot. I've learnt a lot from the example, it's only that in the way it's written now it's not compatible with windows.
Hello Mojca, if you are using Windows, you can install MinGW, it's free and bash is included.
OK, that could be file for me and maybe for two others, but this can't be a general solution. (Beginners wouldn't install it and the skilled ones have linux anyway.)
that makes me a beginner
So my question for gurus remains: how to write a macro, so that
\startGnuplotinclusions set title "trigonometry" \stopGnuplotinclusions \startGnuplot plot sin(x) \stopGnuplot \startGnuplot plot cos(x) \stopGnuplot
would result in one file with
set terminal postscript set output "filename1" set title "trigonometry" plot sin(x)
and the other one with
set terminal postscript set output "filename2" # If too complicated, the filename may remain the same
why should it change an option is to collect *all graphic data* and do it in one run, in which case we can gain some speed
set title "trigonometry" plot cos(x)
% output=pdf \def\startGNUPLOTinclusions {\bgroup \obeylines \dostartGNUPLOTinclusions} \def\dostartGNUPLOTinclusions#1\stopGNUPLOTinclusions {\gdef\GNUPLOTinclusions{#1}% \egroup} \def\startGNUPLOTgraphic {\bgroup \obeylines \dostartGNUPLOTgraphic} \def\dostartGNUPLOTgraphic#1\stopGNUPLOTgraphic {\def\par{\rawcharacter{13}}% \immediate\openout\scratchwrite=\bufferprefix gnuplot.job \immediate\write\scratchwrite{\GNUPLOTinclusions}% \immediate\write\scratchwrite{set output "\bufferprefix gnuplot.ps"}% \immediate\write\scratchwrite{#1}% \immediate\closeout\scratchwrite \egroup \processGNUPLOTgraphic{\bufferprefix gnuplot}} \def\processGNUPLOTgraphic#1% {\executesystemcommand{start d:/gnuplot/bin/pgnuplot #1.job}% \executesystemcommand{texmfstart newpstopdf #1.ps}% \externalfigure[#1.pdf]} \starttext \startGNUPLOTinclusions set title "trigonometry" set terminal postscript \stopGNUPLOTinclusions \startGNUPLOTgraphic plot sin(x) \stopGNUPLOTgraphic \startGNUPLOTgraphic plot cos(x) \stopGNUPLOTgraphic \stoptext i leave it to you to figure out why i don't get output Hans
On Tue, 3 Jan 2006, Hans Hagen wrote:
i leave it to you to figure out why i don't get output
Hello Hans, really nice example, that's the way I love to learn ConTeXt! I don't have Windows, so I had to modify your code a bit:
{\def\par{\rawcharacter{13}}%
changed to {\def\par{\rawcharacter{10}}% because 13 is CR (\r), but gnuplot needs LF (\n) here (Linux) But I don't understand, why the \par must be redefined, is it because \obeylines transforms newlines to paragraphs?
{\executesystemcommand{start d:/gnuplot/bin/pgnuplot #1.job}%
just {\executesystemcommand{gnuplot #1.job}% here It works well, but it's two time the cos-function, that gets included. I think, one needs a counter as in my module, to get distinguished file names for \externalfigure. Greetings, Peter -- http://pmrb.free.fr/contact/
� wrote:
On Tue, 3 Jan 2006, Hans Hagen wrote:
i leave it to you to figure out why i don't get output
Hello Hans, really nice example, that's the way I love to learn ConTeXt!
I don't have Windows, so I had to modify your code a bit:
{\def\par{\rawcharacter{13}}%
changed to {\def\par{\rawcharacter{10}}% because 13 is CR (\r), but gnuplot needs LF (\n) here (Linux)
this is indeed an issue; either i let texexec set the platform character (no problem) or taco extends pdftex with \pdfnewline
But I don't understand, why the \par must be redefined, is it because \obeylines transforms newlines to paragraphs?
indeed, just comment the def and see what happens (you get a \par)
{\executesystemcommand{start d:/gnuplot/bin/pgnuplot #1.job}%
just {\executesystemcommand{gnuplot #1.job}% here
It works well, but it's two time the cos-function, that gets included. I think, one needs a counter as in my module, to get distinguished file names for \externalfigure.
ah, add [object=no] in order to disable reuse Hans
Hi, Hans Hagen wrote:
see attached file for usage %D [ file=m-gnuplot,
This does not work here, the produced .gpd file looks like: ----------------------- ^Mset title "trigonometry"^Mset terminal postscript set output "gpl-gnuplot-1.ps" ^Mplot sin(x) end ----------------------- ^M stands for \r (Carridge, decimal 13, hex 0d, oct 015). I frankly don't understand why one does not get a \n (linefeed, decimal 10/0A/012) or a ";\n" for that matter ["\def\par{;\rawcharacter{10}}"]. Tobias
Tobias Burnus wrote:
Hi,
Hans Hagen wrote:
see attached file for usage %D [ file=m-gnuplot,
This does not work here, the produced .gpd file looks like: ----------------------- ^Mset title "trigonometry"^Mset terminal postscript set output "gpl-gnuplot-1.ps" ^Mplot sin(x) end ----------------------- ^M stands for \r (Carridge, decimal 13, hex 0d, oct 015).
I frankly don't understand why one does not get a \n (linefeed, decimal 10/0A/012) or a ";\n" for that matter ["\def\par{;\rawcharacter{10}}"].
do you use the natural.ctx file when building the format? don't ask me why, but for some obscure reasons tex distributions like to default to a not so 255 tcx setup (called 255 -) you really need to make sure that locales are ignored maybe \def\par{; } also works here, i dunny how long gnuplot lines may be Hans
Wow! Thank you a lot for this one, Hans! (And to Peter as well!) Hans Hagen wrote:
Tobias Burnus wrote:
Hi,
Hans Hagen wrote:
see attached file for usage %D [ file=m-gnuplot,
This does not work here, the produced .gpd file looks like: ----------------------- ^Mset title "trigonometry"^Mset terminal postscript set output "gpl-gnuplot-1.ps" ^Mplot sin(x) end ----------------------- ^M stands for \r (Carridge, decimal 13, hex 0d, oct 015).
I frankly don't understand why one does not get a \n (linefeed, decimal 10/0A/012) or a ";\n" for that matter ["\def\par{;\rawcharacter{10}}"].
I experience exactly the same problem here both under Windows and Linux. ^M should be replaced by some "newline". If I do that manually, the module works perfectly. A bit weird request (and not urgent at all since there are other ways to solve this): could "rotate=" be added to \externalfigure once in the distant future? The resulting graphs in postscript are rotated 90 degrees counterclocwise.
do you use the natural.ctx file when building the format?
I think so (but not sure).
maybe \def\par{; } also works here, i dunny how long gnuplot lines may be
The problem is not in \def\par{} I guess. It doesn't have any influence on the way how input lines appear in the file. Even if I redefined the \par and put strange chars in there, it didn't have any influence. I tried to play with \obeylines a bit, but without success. I managed to get ^E (0x05) instead of ^M in the gnuplot file if I redefined \endchar to be ^^L (if I remember correctly), but just anything else led to errors. Two not-so-important remarks: 1. \immediate\write\scratchwrite{end} "end" should be changed into "quit" or even better: left out completely since gnuplot exits anyway after executing the script 2. The default file extension is .plt (instead of gpd; the ending really doesn't matter, but this one is recognized by default when you "open file" from gnuplot) Some terminals are more ugly than the others. The best idea to specify the terminal is really by placing it manually into \startGNUPLOTinclusion, not by prepending it automatically (as I asked first), since it can have some additional parameters (color, landscape, ...). There are also "set terminal pdf" (only in the "latest" versions, perhaps not even included in the binaries), "set terminal png", "set terminal mp", "set terminal latex", ... Another humble request from me would be to support more than a single terminal: %%%%% \setupGNUPLOT[terminal=postscript] % should result in \immediate\write\scratchwrite{set output "\bufferprefix gnuplot-\GNUPLOTnumber.ps"}% ... \convertGNUPLOTgraphic{\bufferprefix gnuplot-\GNUPLOTnumber}% % perhaps a better name, suggesting ps2pdf conversion %%%%% \setupGNUPLOT[terminal=pdf] % only recent; should result in \immediate\write\scratchwrite{set output "\bufferprefix gnuplot-\GNUPLOTnumber.pdf"}% % no postprocessing/conversion needed. %%%%% \setupGNUPLOT[terminal=png] % should result in \immediate\write\scratchwrite{set output "\bufferprefix gnuplot-\GNUPLOTnumber.png"}% % no postprocessing/conversion needed. %%%%% \setupGNUPLOT[terminal=mp] % should result in \immediate\write\scratchwrite{set output "\bufferprefix gnuplot-\GNUPLOTnumber.mp"}% % plus mpost + mptopdf postprocessing %%%%% \setupGNUPLOT[terminal=latex] % somewhat more tricky; should result in \immediate\write\scratchwrite{set output "\bufferprefix gnuplot-\GNUPLOTnumber.tex"}% % another auxilary file has to be used in this case with \documentclass ... % \begindocument ... \input \bufferprefix gnuplot-\GNUPLOTnumber.tex % and then processed with pdflatex; that's what I currently use: most beautiful results Thanks a lot, Mojca PS: Does this module really mean that I have no more excuses for not finishing my report(s) for physics in time? ;)
Mojca Miklavec wrote:
I experience exactly the same problem here both under Windows and Linux. ^M should be replaced by some "newline". If I do that manually, the module works perfectly.
i hate locales
A bit weird request (and not urgent at all since there are other ways to solve this): could "rotate=" be added to \externalfigure once in the distant future? The resulting graphs in postscript are rotated 90 degrees counterclocwise.
hm, i have to think about it
maybe \def\par{; } also works here, i dunny how long gnuplot lines may be
did \def\par{;} work out ok?
The problem is not in \def\par{} I guess. It doesn't have any influence on the way how input lines appear in the file. Even if I redefined the \par and put strange chars in there, it didn't have any influence.
strange, maybe i have a better tex binary
I tried to play with \obeylines a bit, but without success. I managed to get ^E (0x05) instead of ^M in the gnuplot file if I redefined \endchar to be ^^L (if I remember correctly), but just anything else led to errors.
Two not-so-important remarks: 1. \immediate\write\scratchwrite{end} "end" should be changed into "quit" or even better: left out completely since gnuplot exits anyway after executing the script
ok, quit then
2. The default file extension is .plt (instead of gpd; the ending really doesn't matter, but this one is recognized by default when you "open file" from gnuplot)
hm, we don't want to overwrite files, do we?
Some terminals are more ugly than the others. The best idea to specify the terminal is really by placing it manually into \startGNUPLOTinclusion, not by prepending it automatically (as I asked first), since it can have some additional parameters (color, landscape, ...).
it's not prepended now; however, it makes sense to think about it because in the case of mp we need a different treatment
There are also "set terminal pdf" (only in the "latest" versions, perhaps not even included in the binaries), "set terminal png", "set terminal mp", "set terminal latex", ...
Another humble request from me would be to support more than a single terminal:
%%%%% \setupGNUPLOT[terminal=postscript] % should result in \immediate\write\scratchwrite{set output "\bufferprefix gnuplot-\GNUPLOTnumber.ps"}% ... \convertGNUPLOTgraphic{\bufferprefix gnuplot-\GNUPLOTnumber}% % perhaps a better name, suggesting ps2pdf conversion
%%%%% \setupGNUPLOT[terminal=pdf] % only recent; should result in
\immediate\write\scratchwrite{set output "\bufferprefix gnuplot-\GNUPLOTnumber.pdf"}% % no postprocessing/conversion needed.
%%%%% \setupGNUPLOT[terminal=png] % should result in
\immediate\write\scratchwrite{set output "\bufferprefix gnuplot-\GNUPLOTnumber.png"}% % no postprocessing/conversion needed.
%%%%% \setupGNUPLOT[terminal=mp] % should result in
\immediate\write\scratchwrite{set output "\bufferprefix gnuplot-\GNUPLOTnumber.mp"}% % plus mpost + mptopdf postprocessing
%%%%% \setupGNUPLOT[terminal=latex] % somewhat more tricky; should result in
\immediate\write\scratchwrite{set output "\bufferprefix gnuplot-\GNUPLOTnumber.tex"}% % another auxilary file has to be used in this case with \documentclass ... % \begindocument ... \input \bufferprefix gnuplot-\GNUPLOTnumber.tex % and then processed with pdflatex; that's what I currently use: most beautiful results
that's a big list ... why isn't there a context mode?
Thanks a lot, Mojca
PS: Does this module really mean that I have no more excuses for not finishing my report(s) for physics in time? ;)
no, worse, you now can finish it faster see attached file (bottom of file); should be enough to get your reports done Hans
Hans, great! I love the design (including the fact that one graphic can be reused with multiple "terminals"). Just a few comments: replace \immediate\write\scratchwrite{set terminal "\@@GNUPLOTmethod"}% with \immediate\write\scratchwrite{set terminal \@@GNUPLOToutput}% (No quotes and ps should be postscript.) {\executesystemcommand{start gnuplot #1.gpd}} Here both "guplot filename" and "start gnuplot filename" work equally well (but even if "start" is left there, I would rename "pgnuplot" into "gnuplot"). Something is terribly wrong with the windows machine I'm currently working on, but on linux it worked OK (except for problems with text in the metapost sample, but I have to figure out what went wrong first). When executing these lines on MikTeX: {\doifelse\operatingsystem{mswin} {\executesystemcommand{start gnuplot \GNUPLOTfile.gpd}\message{[win]}} {\executesystemcommand{gnuplot \GNUPLOTfile.gpd}\message{[lin]}}} I got [lin] a couple of times and no traces of any gnuplot work (though gnuplot compiled the two remaining files ok when called separately). But this has nothing to do with the module itself. Most probably problem with permissions. write18 was enabled. On 1/5/06, Hans Hagen wrote:
Mojca Miklavec wrote:
did \def\par{;} work out ok?
No, it didn't. Neither under linux nor under windows. So this remains the only serious thing to fix. The example you sent worked (almost) OK, but since it had only one line in the \startGNUPLOTinclusions. As soon as I add set terminal mp color (which only overrides the already defined "set terminal mp" on the proper place, so it's OK) I get: set terminal mp ^M set title trigonometry^Mset terminal mp color^M set output "m-gnuplot-gnuplot-1-mp" ^Mplot sin(x)^M quit gnuplot didn't complain about ^M, but it can't have more than one line compressed in one.
The problem is not in \def\par{} I guess. It doesn't have any influence on the way how input lines appear in the file. Even if I redefined the \par and put strange chars in there, it didn't have any influence.
strange, maybe i have a better tex binary
;) It's 1.30.0 on linux (from your distribution) and 1.21a under MikTeX.
ok, quit then
2. The default file extension is .plt (instead of gpd; the ending really doesn't matter, but this one is recognized by default when you "open file" from gnuplot)
hm, we don't want to overwrite files, do we?
Does the ending matter in (not)overwriting files? I would only change \immediate\openout\scratchwrite=\GNUPLOTfile.gpd into \immediate\openout\scratchwrite=\GNUPLOTfile.plt (or even \scratchwrite=\GNUPLOTfile-\@@GNUPLOTsuffix.plt, so that the files don't overwrite each other) and gnuplot \GNUPLOTfile.gpd into gnuplot \GNUPLOTfile.plt but that's only cosmetics, doesn't really change the functionality.
that's a big list ... why isn't there a context mode?
Perhaps because nobody (including me) knew that there's a module to support gnuplot inside ConTeXt source :). Well ... after I spent approximately 2 or 3 hours to figure out how to compile it I started writing the code. It's true that it's tempting to do just anything else except learning during the period of exams, but it will nevertheless take me some time to finish, so please don't expect anything that soon. Besides that: PDF support has been written 5 years ago and it is still not present in standard binaries. I have no idea how much time is needed once the support is written so that: - a new version appears - it's included in distributions - people/admins upgrade the software
PS: Does this module really mean that I have no more excuses for not finishing my report(s) for physics in time? ;)
no, worse, you now can finish it faster
see attached file (bottom of file); should be enough to get your reports done
So ... I have to get back to work then ;) Thanks again, Mojca
participants (4)
-
Hans Hagen
-
Mojca Miklavec
-
Peter Münster
-
Tobias Burnus