1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
\setupcolors
[state=start]
\enableregime
[utf-8]
\setupinteraction
[state=start]
\usemodule
[gnuplot]
\setupexternalfigures
[directory={.,examples}]
\setuplayout
[backspace=1in,
width=middle,
topspace=1in,
heigh=middle,
header=0pt,
headerdistance=0pt]
\setuphead
[title]
[align=middle,
style=\bfc]
\setuphead
[section]
[style=\bfb]
\setuphead
[subsection]
[style=\bfa]
\setupitemize
[headstyle=bold]
% \usetypescript
% [antykwa-torunska]
% \setupbodyfont
% [antykwa]
\beginNEWTEX\usetypescript[lucida] \endNEWTEX
\beginOLDTEX\usetypescript[lucida][ec]\endOLDTEX
\setupbodyfont
[lucida]
\definecolor
[maincolor]
[darkblue]
\definecolor
[lightblue]
[r=0.9,g=0.9,b=1]
\definecolor
[screen]
[s=0.9]
\setuptyping
[TEX]
[tab=4]
\logo [TEXLIVE] {\TeX\ Live}
\logo [MIKTEX] {Mik\TeX}
\logo [TIKZ] {Tik{\it Z}}
\defineframedtext
[background]
[background=color,backgroundcolor=gray,width=\textwidth,frame=off,offset=2pt,style=type]
\defineframedtext
[myinput]
[background=color,backgroundcolor=lightblue,width=\textwidth,frame=off,offset=2pt,style=type]
% \setupbackgrounds
% [background]
% [background=color,backgroundcolor=gray,width=\textwidth,frame=off]
\starttext
\title{Using \color[maincolor]{\tt\bf context} and \color[maincolor]{\tt\bf tikz} terminal for gnuplot}
\centerline{Mojca Miklavec, \date[y=2011,m=2,d=10]}
\blank
\placelist[section]
\blank
\section{Requirements}
\startitemize[n,packed]
\item Any working \ConTeXt\ installation (\ConTeXt\ Minimals, \TEXLIVE\ 2010 or \MIKTEX\ 2.9 or newer).
\item The {\tt gnuplot} binary (or {\tt gnuplot.exe} under Windows) has to be in {\tt PATH} and needs to have support for {\tt context} and/or {\tt tikz} terminal built in.
\item The latest version of gnuplot module for ConTeXt.
\stopitemize
\section{Installation}
\subsection{\CONTEXT}
TODO
\subsection{Gnuplot}
TODO
You can check the list of supported terminals by typing \startlines
\tt{gnuplot>} \bf set term
\stoplines
into gnuplot shell.
\subsection{{\tt\bf t-gnuplot} module for \CONTEXT}
Under \CONTEXT\ Minimals you can install the gnuplot module and \TIKZ\ with an additional switch when running {\tt f\/irst-setup}, for example:
\startbackground
\tt f\/irst-setup.sh -\/-extras=t-gnuplot,t-tikz
\stopbackground
If you have installed a {\tt complete} or {\tt context} scheme under \TEXLIVE, gnuplot module and \TIKZ\ might already be installed. Else you can use:
\startbackground
tlmgr install context-gnuplot\\
tlmgr install pgf
\stopbackground
Under \MIKTEX\ the module is installed automatically when it is first used.
\section{Simple examples}
\subsection{Calling gnuplot directly}
Let's first create a simple file (we will call it {\tt\it example.plt}, but you may choose any name) with the contents below.
For {\tt context} terminal:
\startmyinput
set term context size 5in,3in standalone\\
set output "fullpage-example.tex"\\
plot sin(x)\\
plot cos(atan(x))*sin(x)
\stopmyinput
For {\tt tikz} terminal:
\startmyinput
set term tikz context size 5in,3in standalone createstyle\\
set output "fullpage-example.tex"\\
plot sin(x)\\
plot cos(atan(x))*sin(x)
\stopmyinput
In both cases the option {\tt standalone} is used to create a complete \CONTEXT\ document with one plot per page, including header and {\tt\textbackslash starttext \dots\ \textbackslash stoptext}, so that it can be compiled directly. The option {\tt createstyle} is used to create three files with required macros in working directory\footnote{An alternative is to place those three files somewhere where kpathsea can find them and omit the option {\tt createstyle}, just make sure that the versions of {\tt tikz} terminal and the files in your \TeX\ tree remain compatible.}
Both terminals should give you almost equivalent results apart from default plot size. You are highly encouraged to specify the disired plot size explicitely. You may scale the plot later on, but you probably want to get the desired proportions from the start.
Run gnuplot with
\startbackground
gnuplot example.plt
\stopbackground
and compile the result with any of the following three commands (depending on your preferred engine):
\startbackground
\hbox{\hbox to 25em{context fullpage-example.tex \hss} {\rm\# for \LuaTeX}}
\hbox{\hbox to 25em{texexec fullpage-example.tex \hss} {\rm\# for \pdfTeX}}
\hbox{\hbox to 25em{texexec --xtx fullpage-example.tex \hss} {\rm\# for \XeTeX} }
\stopbackground
They are almost equivalent except that \XeTeX\ lacks some advanced features (some patterns). The only major difference is the choice of fonts. If you want to typeset Arabic labels or use system fonts, you will probably want to choose \LuaTeX\ or \XeTeX. If you are using many graphical elements (like in 3D plots), you might want to go for \LuaTeX.
You should get a {\sc pdf} document with two full-page plots that you can include into your document with \type{\externalfigure[fullpage-example][page=2]} for example.
\placefigure[force]{}{\externalfigure[fullpage-example][page=2]}
\subsection{Calling gnuplot from \TeX}
As you can see you will always get Latin Modern font at 12pt unless you explicitely change it with {\tt header "\textbackslash setupbodyfont[...]"}. An easier way to make sure that the same font is used and to avoid having to call gnuplot manually is to simply type the gnuplot code inside your \CONTEXT\ document:
\startTEX
\usemodule
[gnuplot]
\setupGNUPLOTterminal
[context]
[width=5in,height=2.5in,textscale=0.8]
\setupGNUPLOTterminal
[tikz]
[width=5in,height=2.5in]
\starttext
\startGNUPLOTscript[myfunction]
set samples 400
set key left Left reverse
set format y "%.1f"
plot sin(x) t '$\sin(x)$' lw 3
plot cos(atan(x))*sin(x) t '$\cos(\arctan(x))\sin(x)$' lw 3 lc 3
\stopGNUPLOTscript
\placefigure{none}{\useGNUPLOTgraphic[myfunction][2]}
\setupGNUPLOT
[terminal=tikz]
\placefigure{none}{\useGNUPLOTgraphic[myfunction][1]}
\stoptext
\stopTEX
\bgroup
\setupGNUPLOTterminal
[context]
[width=5in,height=2.5in,textscale=0.8]
\setupGNUPLOTterminal
[tikz]
[width=5in,height=2.5in]
\startGNUPLOTscript[myfunction]
set samples 400
set key left Left reverse
set format y "%.1f"
plot sin(x) t '$\sin(x)$' lw 3
plot cos(atan(x))*sin(x) t '$\cos(\arctan(x))\sin(x)$' lw 3 lc 3
\stopGNUPLOTscript
\placefigure[force]{Framed second plot using {\tt context} terminal}
{\framed[offset=overlay,frame=off,background=color,backgroundcolor=lightblue]{\useGNUPLOTgraphic[myfunction][2]}}
\setupGNUPLOT[terminal=tikz]
\placefigure[force]{Framed first plot using {\tt tikz} terminal}
{\framed[offset=overlay,frame=off,background=color,backgroundcolor=lightblue]{\useGNUPLOTgraphic[myfunction][1]}}
\egroup
\subsection{Including pre-generated plots}
TODO
This is the syntax:
\startTEX
\processGNUPLOTfile[name][filename.tex]
\useGNUPLOTgraphic[name]
\stopTEX
\section{Terminal options}
\subsection{\tt\bf context}
TODO
\starttyping
set term context {default}
{defaultsize | size <scale> |
size <xsize> {in|cm}, <ysize> {in|cm}}
{input | standalone}
{noheader | header "<header>"}
{color | colour | monochrome}
{mitered | rounded | beveled}
{butt | round | squared}
{dashed | solid}
{dashlength | dl <DL>}
{linewidth | lw <LW>}
{textscale <textscale>}
{pointswithmetapost | pointswithmp | pointswithtex}
{defaultfont | font {<fontsize>} |
font "<fontname>{,<fontsize>}" {fontsize}}
\stoptyping
\subsection{\tt\bf tikz}
TODO
\section{High-level configuration from \ConTeXt}
TODO
\section{Comparison of supported terminals}
The gnuplot module for \ConTeXt\ supports the following terminals:
\startitemize[packed]
\head bitmap terminals\par
\startitemize[packed,joinedup]
\item\tt png, pngcairo
\stopitemize
\head vector terminals\par
\startitemize[packed,joinedup]
\item\tt {\bf context}, {\bf tikz}
\item\tt metapost, postscript, pdf, pdfcairo
\stopitemize
\stopitemize
\stoptext
|