ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* gnuplot for Mojca
@ 2006-01-02 10:34 Peter Münster
  2006-01-03  8:18 ` Mojca Miklavec
  0 siblings, 1 reply; 15+ messages in thread
From: Peter Münster @ 2006-01-02 10:34 UTC (permalink / raw)


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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: gnuplot for Mojca
  2006-01-02 10:34 gnuplot for Mojca Peter Münster
@ 2006-01-03  8:18 ` Mojca Miklavec
  2006-01-03 17:49   ` Peter Münster
  0 siblings, 1 reply; 15+ messages in thread
From: Mojca Miklavec @ 2006-01-03  8:18 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 1320 bytes --]

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.

> http://pmrb.free.fr/work/OS/ConTeXt/t-gnuplot.tex

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

[-- Attachment #2: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: gnuplot for Mojca
  2006-01-03  8:18 ` Mojca Miklavec
@ 2006-01-03 17:49   ` Peter Münster
  2006-01-03 20:27     ` Mojca Miklavec
  0 siblings, 1 reply; 15+ messages in thread
From: Peter Münster @ 2006-01-03 17:49 UTC (permalink / raw)


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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: gnuplot for Mojca
  2006-01-03 17:49   ` Peter Münster
@ 2006-01-03 20:27     ` Mojca Miklavec
  2006-01-03 21:19       ` Hans Hagen
                         ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Mojca Miklavec @ 2006-01-03 20:27 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 3170 bytes --]

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

[-- Attachment #2: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: gnuplot for Mojca
  2006-01-03 20:27     ` Mojca Miklavec
@ 2006-01-03 21:19       ` Hans Hagen
  2006-01-03 21:22       ` Hans Hagen
  2006-01-03 22:07       ` Hans Hagen
  2 siblings, 0 replies; 15+ messages in thread
From: Hans Hagen @ 2006-01-03 21:19 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: gnuplot for Mojca
  2006-01-03 20:27     ` Mojca Miklavec
  2006-01-03 21:19       ` Hans Hagen
@ 2006-01-03 21:22       ` Hans Hagen
  2006-01-03 22:07       ` Hans Hagen
  2 siblings, 0 replies; 15+ messages in thread
From: Hans Hagen @ 2006-01-03 21:22 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: gnuplot for Mojca
  2006-01-03 20:27     ` Mojca Miklavec
  2006-01-03 21:19       ` Hans Hagen
  2006-01-03 21:22       ` Hans Hagen
@ 2006-01-03 22:07       ` Hans Hagen
  2006-01-03 22:41         ` Peter Münster
  2 siblings, 1 reply; 15+ messages in thread
From: Hans Hagen @ 2006-01-03 22:07 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: gnuplot for Mojca
  2006-01-03 22:07       ` Hans Hagen
@ 2006-01-03 22:41         ` Peter Münster
  2006-01-04  8:55           ` Hans Hagen
  2006-01-04 14:45           ` present for mojca Hans Hagen
  0 siblings, 2 replies; 15+ messages in thread
From: Peter Münster @ 2006-01-03 22:41 UTC (permalink / raw)


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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: gnuplot for Mojca
  2006-01-03 22:41         ` Peter Münster
@ 2006-01-04  8:55           ` Hans Hagen
  2006-01-04 14:45           ` present for mojca Hans Hagen
  1 sibling, 0 replies; 15+ messages in thread
From: Hans Hagen @ 2006-01-04  8:55 UTC (permalink / raw)


� 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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* present for mojca
  2006-01-03 22:41         ` Peter Münster
  2006-01-04  8:55           ` Hans Hagen
@ 2006-01-04 14:45           ` Hans Hagen
  2006-01-04 15:34             ` Tobias Burnus
  1 sibling, 1 reply; 15+ messages in thread
From: Hans Hagen @ 2006-01-04 14:45 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 34 bytes --]

see attached file for usage

Hans

[-- Attachment #2: m-gnuplot.tex --]
[-- Type: text/x-tex, Size: 3142 bytes --]

%D \module
%D   [       file=m-gnuplot,
%D        version=2006.01.04,
%D          title=\CONTEXT\ Extra Modules,
%D       subtitle=\GNUPLOT\ Inclusion,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright=\PRAGMA]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% todo: reuse (only if really needed)

% \enablemode[demo]

%D example:
%D
%D \starttyping
%D texexec --pdf --mode=demo m-gnuplot
%D \stoptyping

\unprotect

\ifx\operatingsystem\undefined \def\operatingsystem{unix} \fi % texexec will set that

\newcounter\GNUPLOTnumber

\def\startGNUPLOTinclusions
  {\bgroup
   \obeylines
   \dostartGNUPLOTinclusions}

\def\dostartGNUPLOTinclusions#1\stopGNUPLOTinclusions
  {\gdef\GNUPLOTinclusions{#1}%
   \egroup}

\def\startGNUPLOTgraphic#1%
  {\bgroup
   \obeylines
   \dostartGNUPLOTgraphic{#1}}

\def\dostartGNUPLOTgraphic#1#2\stopGNUPLOTgraphic
  {\doglobal\increment\GNUPLOTnumber
   \letgvalue{gpg:n:#1}\GNUPLOTnumber
   \setgvalue{gpg:d:\GNUPLOTnumber}{#2}%
   \egroup}

\def\useGNUPLOTgraphic
  {\dodoubleempty\douseGNUPLOTgraphic}

\def\douseGNUPLOTgraphic[#1][#2]%
  {\iffirstargument
     \@EA\dodouseGNUPLOTgraphic % like \externalfigure[name][optional args]
   \else
     \@EA\redouseGNUPLOTgraphic % like \useMPgraphic{name}
   \fi[#1][#2]}

\def\redouseGNUPLOTgraphic[#1][#2]#3%
  {\dodouseGNUPLOTgraphic[#3][]}

\def\dodouseGNUPLOTgraphic[#1][#2]%
  {\bgroup
   \doifdefined{gpg:n:#1}
     {\edef\GNUPLOTnumber{\getvalue{gpg:n:#1}}%
      \bgroup
      % hm, gnuplot only seems to handle lf so we cannot use \mappartolineend
      % also, in order to prevent fuzzy runs (or no runs) we add a ; to each line
      \def\par{;\rawcharacter{10}}%
      \immediate\openout\scratchwrite=\bufferprefix gnuplot-\GNUPLOTnumber.gpd
      \immediate\write\scratchwrite{\GNUPLOTinclusions}%
      \immediate\write\scratchwrite{set output "\bufferprefix gnuplot-\GNUPLOTnumber.ps"}%
      \immediate\write\scratchwrite{\getvalue{gpg:d:\GNUPLOTnumber}}%
      \immediate\write\scratchwrite{end}%
      \immediate\closeout\scratchwrite
      \egroup
      \processGNUPLOTgraphic{\bufferprefix gnuplot-\GNUPLOTnumber}%
      \convertGNUPLOTgraphic{\bufferprefix gnuplot-\GNUPLOTnumber}%
      \externalfigure[\bufferprefix gnuplot-\GNUPLOTnumber.pdf][#2]}%
   \egroup}

% we assume pdf inclusion, eps wil be implemented when applicable

\def\processGNUPLOTgraphic#1%
  {\doifelse\operatingsystem{mswin}
     {\executesystemcommand{start pgnuplot #1.gpd}} % start is needed else gp fails
     {\executesystemcommand{gnuplot #1.gpd}}}

\def\convertGNUPLOTgraphic#1%
  {\executesystemcommand{texmfstart newpstopdf #1.ps}}

\protect \doifnotmode{demo}{\endinput}

\starttext

\startGNUPLOTinclusions
    set title "trigonometry"
    set terminal postscript
\stopGNUPLOTinclusions

\startGNUPLOTgraphic{sin}
    plot sin(x)
\stopGNUPLOTgraphic

\startGNUPLOTgraphic{cos}
    plot cos(x)
\stopGNUPLOTgraphic

\useGNUPLOTgraphic{sin}

\useGNUPLOTgraphic{cos}

\useGNUPLOTgraphic[cos]

\useGNUPLOTgraphic[sin][height=3cm]

\stoptext

[-- Attachment #3: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: present for mojca
  2006-01-04 14:45           ` present for mojca Hans Hagen
@ 2006-01-04 15:34             ` Tobias Burnus
  2006-01-04 16:14               ` Hans Hagen
  0 siblings, 1 reply; 15+ messages in thread
From: Tobias Burnus @ 2006-01-04 15:34 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: present for mojca
  2006-01-04 15:34             ` Tobias Burnus
@ 2006-01-04 16:14               ` Hans Hagen
  2006-01-05 15:57                 ` Mojca Miklavec
  0 siblings, 1 reply; 15+ messages in thread
From: Hans Hagen @ 2006-01-04 16:14 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: present for mojca
  2006-01-04 16:14               ` Hans Hagen
@ 2006-01-05 15:57                 ` Mojca Miklavec
  2006-01-05 18:43                   ` Hans Hagen
  0 siblings, 1 reply; 15+ messages in thread
From: Mojca Miklavec @ 2006-01-05 15:57 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 3930 bytes --]

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? ;)

[-- Attachment #2: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: present for mojca
  2006-01-05 15:57                 ` Mojca Miklavec
@ 2006-01-05 18:43                   ` Hans Hagen
  2006-01-06 12:35                     ` Mojca Miklavec
  0 siblings, 1 reply; 15+ messages in thread
From: Hans Hagen @ 2006-01-05 18:43 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 3810 bytes --]

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

[-- Attachment #2: m-gnuplot.tex --]
[-- Type: text/x-tex, Size: 4597 bytes --]

%D \module
%D   [       file=m-gnuplot,
%D        version=2006.01.04,
%D          title=\CONTEXT\ Extra Modules,
%D       subtitle=\GNUPLOT\ Inclusion,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright=\PRAGMA]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% todo: reuse (only if really needed)

% \enablemode[demo]

%D example:
%D
%D \starttyping
%D texexec --pdf --mode=demo m-gnuplot
%D \stoptyping

\unprotect

\ifx\operatingsystem\undefined \def\operatingsystem{unix} \fi % texexec will set that

\newcounter\GNUPLOTnumber

\def\startGNUPLOTinclusions
  {\bgroup
   \obeylines
   \dostartGNUPLOTinclusions}

\def\dostartGNUPLOTinclusions#1\stopGNUPLOTinclusions
  {\gdef\GNUPLOTinclusions{#1}%
   \egroup}

\def\startGNUPLOTgraphic#1%
  {\bgroup
   \obeylines
   \dostartGNUPLOTgraphic{#1}}

\def\dostartGNUPLOTgraphic#1#2\stopGNUPLOTgraphic
  {\doglobal\increment\GNUPLOTnumber
   \letgvalue{gpg:n:#1}\GNUPLOTnumber
   \setgvalue{gpg:d:\GNUPLOTnumber}{#2}%
   \egroup}

\def\useGNUPLOTgraphic
  {\dodoubleempty\douseGNUPLOTgraphic}

\def\douseGNUPLOTgraphic[#1][#2]%
  {\iffirstargument
     \@EA\dodouseGNUPLOTgraphic % like \externalfigure[name][optional args]
   \else
     \@EA\redouseGNUPLOTgraphic % like \useMPgraphic{name}
   \fi[#1][#2]}

\def\redouseGNUPLOTgraphic[#1][#2]#3%
  {\dodouseGNUPLOTgraphic[#3][]}

\def\dodouseGNUPLOTgraphic[#1][#2]%
  {\bgroup
   \doifdefined{gpg:n:#1}
     {\edef\GNUPLOTnumber{\getvalue{gpg:n:#1}}%
      \edef\GNUPLOTfile  {\bufferprefix gnuplot-\GNUPLOTnumber}%
      \bgroup
      % hm, gnuplot only seems to handle lf so we cannot use \mappartolineend
      % also, in order to prevent fuzzy runs (or no runs) we add a ; to each line
      \def\par{;\rawcharacter{10}}%
      \immediate\openout\scratchwrite=\GNUPLOTfile.gpd
      \immediate\write\scratchwrite{set terminal "\@@GNUPLOTmethod"}%
      \immediate\write\scratchwrite{\GNUPLOTinclusions}%
      \immediate\write\scratchwrite{set output "\GNUPLOTfile.\@@GNUPLOTsuffix"}%
      \immediate\write\scratchwrite{\getvalue{gpg:d:\GNUPLOTnumber}}%
      \immediate\write\scratchwrite{quit}%
      \immediate\closeout\scratchwrite
      \egroup
      \processGNUPLOTgraphic
      \convertGNUPLOTgraphic
      \externalfigure[\@@GNUPLOTresult][#2]}%
   \egroup}

% we assume pdf inclusion, eps wil be implemented when applicable

\def\setupGNUPLOT
  {\dodoubleempty\getparameters[@@GNUPLOT]}

\def\processGNUPLOTgraphic
  {\doifelse\operatingsystem{mswin}
     {\executesystemcommand{start pgnuplot \GNUPLOTfile.gpd}} % start is needed else gp fails
     {\executesystemcommand{gnuplot \GNUPLOTfile.gpd}}}

\def\convertGNUPLOTgraphic
  {\doifsomething\@@GNUPLOThandle{\executesystemcommand{\@@GNUPLOThandle}}}

\def\defineGNUPLOThandle#1#2#3#4#5% name output suffix conversion-method result
  {\setvalue{@@GNUPLOT-#1}{{#2}{#3}{#4}{#5}}}

\def\@@GNUPLOToutput{\filterfromvalue{@@GNUPLOT-\@@GNUPLOTmethod}41}
\def\@@GNUPLOTsuffix{\filterfromvalue{@@GNUPLOT-\@@GNUPLOTmethod}42}
\def\@@GNUPLOThandle{\filterfromvalue{@@GNUPLOT-\@@GNUPLOTmethod}43}
\def\@@GNUPLOTresult{\filterfromvalue{@@GNUPLOT-\@@GNUPLOTmethod}44}

\defineGNUPLOThandle{postscript}{postscript}{ps} {texmfstart newpstopdf \GNUPLOTfile.ps}{\GNUPLOTfile.pdf}
\defineGNUPLOThandle{ps}        {postscript}{ps} {texmfstart newpstopdf \GNUPLOTfile.ps}{\GNUPLOTfile.pdf}
\defineGNUPLOThandle{pdf}       {pdf}       {pdf}{}                                     {\GNUPLOTfile.pdf}
\defineGNUPLOThandle{metapost}  {mp}        {mp} {texmfstart mptopdf    \GNUPLOTfile.mp}{\GNUPLOTfile-0.pdf}
\defineGNUPLOThandle{mp}        {mp}        {mp} {texmfstart mptopdf    \GNUPLOTfile.mp}{\GNUPLOTfile-0.pdf}
\defineGNUPLOThandle{png}       {png}       {png}{}                                     {\GNUPLOTfile.png}

\setupGNUPLOT[\c!method=ps]

\protect \doifnotmode{demo}{\endinput}

\starttext

\startGNUPLOTinclusions
    set title "trigonometry"
\stopGNUPLOTinclusions

\startGNUPLOTgraphic{sin}
    plot sin(x)
\stopGNUPLOTgraphic

\startGNUPLOTgraphic{cos}
    plot cos(x)
\stopGNUPLOTgraphic

\useGNUPLOTgraphic{sin} \endgraf
\useGNUPLOTgraphic{cos} \endgraf
\useGNUPLOTgraphic[cos] \endgraf

\setupGNUPLOT[method=ps]  \useGNUPLOTgraphic[sin][object=no,height=2cm] \blank
%setupGNUPLOT[method=pdf] \useGNUPLOTgraphic[sin][object=no,height=2cm] \blank
\setupGNUPLOT[method=png] \useGNUPLOTgraphic[sin][object=no,height=2cm] \blank
\setupGNUPLOT[method=mp]  \useGNUPLOTgraphic[sin][object=no,height=2cm] \blank

\stoptext

[-- Attachment #3: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: present for mojca
  2006-01-05 18:43                   ` Hans Hagen
@ 2006-01-06 12:35                     ` Mojca Miklavec
  0 siblings, 0 replies; 15+ messages in thread
From: Mojca Miklavec @ 2006-01-06 12:35 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 3931 bytes --]

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

[-- Attachment #2: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2006-01-06 12:35 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-02 10:34 gnuplot for Mojca Peter Münster
2006-01-03  8:18 ` Mojca Miklavec
2006-01-03 17:49   ` Peter Münster
2006-01-03 20:27     ` Mojca Miklavec
2006-01-03 21:19       ` Hans Hagen
2006-01-03 21:22       ` Hans Hagen
2006-01-03 22:07       ` Hans Hagen
2006-01-03 22:41         ` Peter Münster
2006-01-04  8:55           ` Hans Hagen
2006-01-04 14:45           ` present for mojca Hans Hagen
2006-01-04 15:34             ` Tobias Burnus
2006-01-04 16:14               ` Hans Hagen
2006-01-05 15:57                 ` Mojca Miklavec
2006-01-05 18:43                   ` Hans Hagen
2006-01-06 12:35                     ` Mojca Miklavec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).