summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/third/gnuplot/t-gnuplot.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/third/gnuplot/t-gnuplot.tex')
-rw-r--r--Master/texmf-dist/tex/context/third/gnuplot/t-gnuplot.tex174
1 files changed, 137 insertions, 37 deletions
diff --git a/Master/texmf-dist/tex/context/third/gnuplot/t-gnuplot.tex b/Master/texmf-dist/tex/context/third/gnuplot/t-gnuplot.tex
index f5fcff50815..365c229c17b 100644
--- a/Master/texmf-dist/tex/context/third/gnuplot/t-gnuplot.tex
+++ b/Master/texmf-dist/tex/context/third/gnuplot/t-gnuplot.tex
@@ -1,6 +1,6 @@
%D \module
%D [ file=t-gnuplot,
-%D version=2011.01.10,
+%D version=2011.02.10,
%D title=\CONTEXT\ Extra Modules,
%D subtitle=\GNUPLOT\ Inclusion,
%D author={Hans Hagen, Taco Hoekwater, Mojca Miklavec, (Aditya Mahajan)},
@@ -11,6 +11,15 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+% begin info
+%
+% title : Gnuplot module
+%
+% comment : simplifies inclusion of gnuplot-generated graphs into ConTeXt documents
+% status : stable, supports both MKII and MKIV
+%
+% end info
+
%D This module is used for creating gnuplot graphs on-the-fly and including them
%D into documents.
%D
@@ -163,6 +172,18 @@
%\runMPTEXgraphicstrue
\newcounter\GNUPLOTnumber
+\newdimen\GNUPLOThcharsize
+\newdimen\GNUPLOTvcharsize
+\newcounter\tikzGNUPLOTnumber
+
+% macro to calculate true character size from current font
+% (However it is not 100 % that it gets the job properly done
+% in case that other font settings are used inside the picture.)
+\def\calculateGNUPLOTcharsize{%
+ \global\GNUPLOThcharsize=1.05\fontcharwd\font`0%
+ \global\GNUPLOTvcharsize=1.05\fontcharht\font`0%
+ \global\advance\GNUPLOTvcharsize by 1.05\fontchardp\font`g%
+}
%D \macros
%D {startGNUPLOTinclusions, resetGNUPLOTinclusions}
@@ -379,6 +400,10 @@
% it would be better to call this \undefineMPgraphic{gpg:#1:\recurselevel} or something similar
{\letbeundefined{@@MPGgpg:#1:\recurselevel}}%
{\exitloop}}%
+ \doloop
+ {\doifdefinedelse{TKZp:#1:\recurselevel}%
+ {\letbeundefined{TKZp:#1:\recurselevel}}%
+ {\exitloop}}%
}%
% TODO: this can probably be done in a better way
@@ -406,6 +431,9 @@
% call to gnuplot and processing/converting the graphics is only needed in the first ConTeXt run
\doifmode{*\v!first}{% (perhaps also: if files haven't changed)
\bgroup
+ % for TikZ we want to calculate character size, so that it gets printed
+ % to inclusions with \@@GNUPLOToptions
+ \calculateGNUPLOTcharsize
% catcodes trickery & alike
%\the\everyGNUPLOTscript
% open file for writing
@@ -443,6 +471,7 @@
}%
% for ConTeXt terminal only - read the result
\doif{\@@GNUPLOTterminal}{context}{\processGNUPLOTfile[#1][\@@GNUPLOTresult]}%
+ \doif{\@@GNUPLOTterminal}{tikz} {\processGNUPLOTfile[#1][\@@GNUPLOTresult]}%
}}}
% \dodouseGNUPLOTgraphic[name][numbers][options]
@@ -450,7 +479,7 @@
{\bgroup
\doifdefinedelse{gps:n:#1}
{\edef\GNUPLOTnumber{\getvalue{gps:n:#1}}%
- \edef\GNUPLOTfile {\bufferprefix gnuplot-\GNUPLOTnumber}%
+ \edef\GNUPLOTfile {\jobname-gnuplot-\GNUPLOTnumber}%
\writeandprocessGNUPLOTscript{#1}%
% "ctxtools --purge" should delete the gnuplot script and other intermediate files
% (but it seems that they are deleted automatically already; preferred or not?)
@@ -475,6 +504,25 @@
\processcommalist[#2]\useGNUPLOTgraphicN
\endgroup
}%
+ }{%
+ % for TikZ terminal only
+ \doifelse{\@@GNUPLOTterminal}{tikz}%
+ {\doifelse{#2}{}%
+ % if no explicit figure number was specified, include all the figures
+ {\doloop
+ {\doifdefinedelse{TKZp:#1:\recurselevel}%
+ {\scale[#3]{\getvalue{TKZp:#1:\recurselevel}}}%
+ {\exitloop}}}%
+ % if numbers were specified, include the figures specified in the list only
+ {\begingroup
+ \def\useGNUPLOTgraphicN##1{\doifdefinedelse
+ {TKZp:#1:##1}%
+ {\scale[#3]{\getvalue{TKZp:#1:##1}}}%
+ % if graphic doesn't exist: draw a dummy frame instead and warn the user
+ {\scale[#3]{\framed[frame=on,width=5in,height=3in,align={middle,lohi}]{GNUPLOT graphic #1, Nr. ##1 doesn't exist}}}}%
+ \processcommalist[#2]\useGNUPLOTgraphicN
+ \endgroup
+ }%
}%
% for all the other terminals
% TODO: add more safety switches (if pages don't exist for example)
@@ -489,7 +537,7 @@
\processcommalist[#2]\useGNUPLOTgraphicN
\endgroup
}%
- }%
+ }}%
}%
% else part - in case that graphic gets included with \processGNUPLOTfile[name][file]
{\doifelse{\@@GNUPLOTterminal}{context}
@@ -548,6 +596,9 @@
\doloop{\doifelseconversionnumber{\@@GNUPLOTpointset}{\recurselevel}%
{\edef\gp:num:pointswithtex{\recurselevel}}%
{\exitloop}}%
+ % in case of TikZ terminal we have to generate the needed style files first
+ \doif{\@@GNUPLOTterminal}{tikz}
+ {\executesystemcommand{gnuplot -e "set term tikz context createstyle"}\usemodule[gnuplot-lua-tikz]}
% TODO:
% - issue a warning if user wants to use points with TeX,
% but pointset= is undefined (if the first point doesn't exist)
@@ -588,38 +639,48 @@
{\dodoubleargument\doprocessGNUPLOTfile}
\def\doprocessGNUPLOTfile[#1][#2]%
- {% we first define two commands: \startGNUPLOTgraphic & \stopGNUPLOTgraphic to read the files in;
- % files that gnuplot creates in non-standalone mode look approximately like this:
- %
- % \startGNUPLOTgraphic[1]
- % ... metapost commands to draw the graph ...
- % \stopGNUPLOTgraphic
- % \startGNUPLOTgraphic[2]
- % ... metapost commands to draw the graph ...
- % \stopGNUPLOTgraphic
- % ...
- %
- % while reading the file in, metapost graphics named "gpg:{name}:{number}" are defined
- %
- % (we might need some additional arguments later on, but for now the figure number should suffice)
- \def\startGNUPLOTgraphic
- {%\obeyMPlines % <- no longer a problem
- \def\obeyedline{}% <- thanks to this
- \dosingleargument\dostartGNUPLOTgraphic}%
- \long\def\dostartGNUPLOTgraphic[##1]##2\stopGNUPLOTgraphic
- {\startreusableMPgraphic{gpg:#1:##1}##2\stopreusableMPgraphic}%
- %
- % if gps:n:{name} (which is a number) is not defined,
- % then we first have to increase the \GNUPLOTnumber counter and associate this name with the new number
-
- % , then we should now also define
- % gpe:{number}:context which should signal later on that the graphic
-% \doifdefined{gps:n:#1}
- % input the file
- % TODO: error / warning if the files doesn't exist
- \readlocfile{#2}{}{}% the third argument should be: if file not found
- % this file is known
- % TODO \letgvalue{gpf:#1}\plusone
+ {\bgroup
+ % for ConTeXt teminal
+ %--------------------
+ % we first define two commands: \startGNUPLOTgraphic & \stopGNUPLOTgraphic to read the files in;
+ % files that gnuplot creates in non-standalone mode look approximately like this:
+ %
+ % \startGNUPLOTgraphic[1]
+ % ... metapost commands to draw the graph ...
+ % \stopGNUPLOTgraphic
+ % \startGNUPLOTgraphic[2]
+ % ... metapost commands to draw the graph ...
+ % \stopGNUPLOTgraphic
+ % ...
+ %
+ % while reading the file in, metapost graphics named "gpg:{name}:{number}" are defined
+ %
+ % (we might need some additional arguments later on, but for now the figure number should suffice)
+ \def\startGNUPLOTgraphic
+ {%\obeyMPlines % <- no longer a problem
+ \def\obeyedline{}% <- thanks to this
+ \dosingleargument\dostartGNUPLOTgraphic}%
+ \long\def\dostartGNUPLOTgraphic[##1]##2\stopGNUPLOTgraphic
+ {\startreusableMPgraphic{gpg:#1:##1}##2\stopreusableMPgraphic}%
+ %------------------
+ % for TikZ terminal
+ %------------------
+ \setcounter\tikzGNUPLOTnumber\zerocount
+ \let\normalstarttikzpicture=\starttikzpicture
+ \let\normalstoptikzpicture=\stoptikzpicture
+ \long\def\starttikzpicture##1\stoptikzpicture%
+ {\increment\tikzGNUPLOTnumber
+ % \long\setgvalue{TKZp:#1:\tikzGNUPLOTnumber}{##1}}
+ \long\setgvalue{TKZp:#1:\tikzGNUPLOTnumber}{\hbox{\starttikzpicture##1\stoptikzpicture}}}
+ %---------
+ % for both
+ %---------
+ % input the file
+ % TODO: error / warning if the files doesn't exist
+ \readlocfile{#2}{}{}% the third argument should be: if file not found
+ % this file is known
+ % TODO \letgvalue{gpf:#1}\plusone
+ \egroup
}
%D \macros
@@ -673,6 +734,9 @@
{pdf}{pdf}{pdf}{}
{\GNUPLOTfile-pdf.pdf}{\GNUPLOTfile-pdf.pdf}
\defineGNUPLOThandle
+ {pdfcairo}{pdfcairo}{pdf}{}
+ {\GNUPLOTfile-pdfcairo.pdf}{\GNUPLOTfile-pdfcairo.pdf}
+\defineGNUPLOThandle
{metapost}{mp}{mp}{mtxrun mptopdf \GNUPLOTfile-mp.mp}
{\GNUPLOTfile-mp.mp}{\GNUPLOTfile-mp-0.pdf}
\defineGNUPLOThandle
@@ -682,7 +746,16 @@
{png}{png}{png}{}
{\GNUPLOTfile-png.png}{\GNUPLOTfile-png.png}
\defineGNUPLOThandle
- {context}{context textscale \@@GNUPLOT@term@context@textscale}{tex}{}
+ {pngcairo}{pngcairo}{png}{}
+ {\GNUPLOTfile-pngcairo.png}{\GNUPLOTfile-pngcairo.png}
+\defineGNUPLOThandle
+ {tikz}{tikz context createstyle
+ size \@@GNUPLOT@term@tikz@width,\@@GNUPLOT@term@tikz@height\space
+ charsize \the\GNUPLOThcharsize,\the\GNUPLOTvcharsize
+ }{tex}{}
+ {\GNUPLOTfile-tikz.tex}{\GNUPLOTfile-tikz.tex}
+\defineGNUPLOThandle
+ {context}{context size \@@GNUPLOT@term@context@width,\@@GNUPLOT@term@context@height\space textscale \@@GNUPLOT@term@context@textscale}{tex}{}
{\GNUPLOTfile-ctx.tex}{\GNUPLOTfile-ctx.tex}
% \doifnotempty{\@@GNUPLOT@term@context@textscale}{textscale \@@GNUPLOT@term@context@textscale}
@@ -746,6 +819,15 @@
convertwith=,
finalresult=\GNUPLOTfile-pdf.pdf,
]
+\defineGNUPLOTterminal
+ [pdfcairo]
+ [terminal=pdfcairo,
+ defaultoptions=,
+ suffix=pdf,
+ result=\GNUPLOTfile-pdfcairo.pdf,
+ convertwith=,
+ finalresult=\GNUPLOTfile-pdfcairo.pdf,
+ ]
%D \METAPOST\ terminal:
%D - deprecated: use the \CONTEXT\ terminal instead,
@@ -780,7 +862,15 @@
convertwith=,
finalresult=\GNUPLOTfile-png.png,
]
-
+\defineGNUPLOTterminal
+ [pngcairo]
+ [terminal=pngcairo,
+ defaultoptions=,
+ suffix=png,
+ result=\GNUPLOTfile-pngcairo.png,
+ convertwith=,
+ finalresult=\GNUPLOTfile-pngcairo.png,
+ ]
%D \CONTEXT\ terminal (native)
\defineGNUPLOTterminal
[context]
@@ -806,6 +896,10 @@
\doifsamestringelse{\@@GNUPLOT@term@context@dashed}{yes}% yes or no
{\edef\@@GNUPLOT@term@context@is@dashed{true}}%
{\edef\@@GNUPLOT@term@context@is@dashed{false}}%
+ \doifsamestring{\@@GNUPLOT@term@context@width}{default}
+ {\edef\@@GNUPLOT@term@context@width{5in}}
+ \doifsamestring{\@@GNUPLOT@term@context@height}{default}
+ {\edef\@@GNUPLOT@term@context@height{3in}}
% {\edef\gp:term:context:dashed{true}}%
% {\edef\gp:term:context:dashed{false}}%
% % dashlength scale
@@ -827,6 +921,12 @@
textscale=1, % scaling factor for text labels
points=metapost] % *metapost* | tex (Should points be drawn with MetaPost or TeX?)
+\setupGNUPLOTterminal
+ [tikz]
+ [width=5in, % *5in* | default (todo) | <dimension>
+ height=3in, % *3in* | default (todo) | <dimension>
+ ]
+
% TODO: better scaling
\defineconversion
[gnuplot:pointset]