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
%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
     [EMAIL PROTECTED] % like \externalfigure[name][optional args]
   \else
     [EMAIL PROTECTED] % 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
_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

Reply via email to