Debian Codegraph @

texmf-dist/tex/latex/gnuplottex/gnuplottex.sty

raw
1 %%
2 %% This is file `gnuplottex.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% gnuplottex.dtx (with options: `package')
8 %%
9 %% Copyright (c) 2006-13, Lars Kotthoff <[email protected]> and contributors
10 %%
11 %% Large portions copied from pdftex,
12 %% Copyright (c) 2001-3, Radhakrishnan CV <[email protected]>
13 %% Rajagopal CV <[email protected]>
14 %% http://www.river-valley.com
15 %%
16 %% River Valley Technologies, Floor III, SJP Buildings, Cotton Hills
17 %% Trivandrum, India 695014
18 %%
19 %% Tel: +91 471 233 7501
20 %%
21 %% Antoine Chambert-Loir
22 %% <[email protected]>
23 %% http://www.math.polytechnique.fr/\protect \unhbox \voidb@x \protect \penalty \@M \ {}chambert
24 %%
25 %% Ecole polytechnique, Palaiseau Cedex, France
26 %%
27 %% This program is free software; you can redistribute it and/or
28 %% modify it under the terms of the GNU General Public License
29 %% as published by the Free Software Foundation; either version 2
30 %% of the License, or (at your option) any later version.
31 %%
32 %% This program is distributed in the hope that it will be useful,
33 %% but WITHOUT ANY WARRANTY; without even the implied warranty of
34 %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 %% GNU General Public License for more details.
36 %%
37 %% You should have received a copy of the GNU General Public License
38 %% along with this program (gpl.txt); if not, write to the Free
39 %% Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
40 %% MA 02111-1307, USA.
41 %%
42 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
43 \ProvidesPackage{gnuplottex}
44 [2020/03/19 v0.9.5 gnuplot graphs in LaTeX]
45 \RequirePackage{graphicx,moreverb,keyval,ifthen,catchfile}
46 \newif\ifShellEscape
47 \newif\ifmiktex \miktexfalse
48 \newif\ifusesiunitx
49 \newif\ifcleanup
50 \newif\ifusesubfolder
51
52 \newwrite\verbatim@out
53
54 \DeclareOption{shell}{\ShellEscapetrue}
55 \DeclareOption{noshell}{\ShellEscapefalse}
56 \DeclareOption{miktex}{\global\miktextrue}
57 \DeclareOption{siunitx}{\usesiunitxtrue}
58 \DeclareOption{cleanup}{\cleanuptrue}
59 \DeclareOption{subfolder}{\usesubfoldertrue}
60
61 \@ifundefined{gnuplotexe}{\def\gnuplotexe{gnuplot}}{}
62
63 \ExecuteOptions{shell}
64 \ProcessOptions\relax
65 %% test if shell escape really works
66 \ifShellEscape
67 \def\tmpfile{w18-test-\the\year\the\month\the\day\the\time.tex}
68 \ifmiktex
69 \immediate\write18{echo t > "\tmpfile"}
70 \else
71 \immediate\write18{touch \tmpfile}
72 \fi
73 \ifmiktex
74 \IfFileExists{\tmpfile}{\ShellEscapetrue}{\ShellEscapefalse}
75 \immediate\write18{del "\tmpfile"}
76 \else
77 \IfFileExists{\tmpfile}{\ShellEscapetrue}{\ShellEscapefalse}
78 \immediate\write18{rm -f \tmpfile}
79 \immediate\write18{rm -f "\jobname.gnuploterrors"}
80 \fi
81 \fi
82
83 \ifusesubfolder
84 \def\subfolder{gnuplottex}
85 \ifShellEscape
86 \ifmiktex
87 \immediate\write18{mkdir \subfolder}
88 \immediate\write18{echo test > "\subfolder/\tmpfile"}
89 \else
90 \immediate\write18{mkdir -p "\subfolder"}
91 \immediate\write18{touch "\subfolder/\tmpfile"}
92 \fi
93 \IfFileExists{gnuplottex/\tmpfile}{
94 \ifmiktex
95 \immediate\write18{del "\subfolder\@backslashchar\tmpfile"}
96 \else
97 \immediate\write18{rm -f "\subfolder/\tmpfile"}
98 \fi
99 }{
100 \PackageWarningNoLine{gnuplottex}
101 {Creation of subfolder failed.\MessageBreak
102 You'll need to create the folder yourself}
103 \def\subfolder{}
104 }
105 \fi
106 \else
107 \def\subfolder{.}
108 \fi
109
110 \ifShellEscape
111 \PackageInfo{gnuplottex}
112 {Automatically converting gnuplot files}
113 \else
114 \PackageWarningNoLine{gnuplottex}
115 {Shell escape not enabled.\MessageBreak
116 You'll need to convert the graphs yourself}
117 \fi
118 \newcounter{fignum}
119 \def\figname{\jobname-gnuplottex-fig\thefignum}
120
121 \def\usesiunitxingnuplot{\immediate\write\verbatim@out{set format '\@backslashchar num{\@percentchar g}'}}
122
123 \def\gnuplotverbatimwrite#1{%
124 \def\BeforeStream
125 {\message{Opening gnuplot stream #1}%
126 \immediate\write\verbatim@out{\string set terminal \gnuplotterminal \gnuplotterminaloptions}%
127 \immediate\write\verbatim@out{\string set output '\subfolder/\figname.\gnuplottexextension{\gnuplotterminal}'}%
128 \ifusesiunitx
129 \ifthenelse{\equal{\extension}{\string tex}}{\usesiunitxingnuplot}{\PackageWarningNoLine{gnuplottex}{Axis numbers not written in \noexpand\num{}. Use a terminal that allows TeX output to enable this feature.}}
130 \else
131 \relax
132 \fi
133 }%
134 \@bsphack%
135 \immediate\openout \verbatim@out #1%
136 \BeforeStream%
137 \let\do\@makeother\dospecials%
138 \catcode`\^^M\active
139 \def\verbatim@processline{%
140 \immediate\write\verbatim@out
141 {\the\verbatim@line}}%
142 \verbatim@start}
143 \def\endgnuplotverbatimwrite{%
144 \immediate\closeout\verbatim@out
145 \@esphack
146 \catcode`\\0
147 \catcode`\{1
148 \catcode`\}2
149 \catcode`\$3
150 \catcode`\&4
151 \catcode`\^^M5
152 \catcode`\#6
153 \catcode`\^7
154 \catcode`\_8
155 \catcode`\ 10
156 \catcode`\%14}
157 \def\gnuplottexextension@latex{\string tex}
158 \def\gnuplottexextension@epslatex{\string tex}
159 \def\gnuplottexextension@cairolatex{\string tex}
160 \def\gnuplottexextension@eepic{\string tex}
161 \def\gnuplottexextension@pstricks{\string tex}
162 \def\gnuplottexextension@pslatex{\string tex}
163 \def\gnuplottexextension@pstex{\string tex}
164 \def\gnuplottexextension@emtex{\string tex}
165 \def\gnuplottexextension@jpeg{\string jpg}
166 \def\gnuplottexextension@tikz{\string tex}
167 \def\gnuplottexextension@lua{\string tex}
168 \def\gnuplottexextension#1{\@ifundefined{gnuplottexextension@#1}{#1}{\csname gnuplottexextension@#1\endcsname}}
169 \define@key{pic}{scale}[1]{\def\gnuplotscale{#1}}
170 \define@key{pic}{terminal}[latex]{\def\gnuplotterminal{#1}}
171 \define@key{pic}{terminaloptions}{\def\gnuplotterminaloptions{ #1}}
172 \newenvironment{gnuplot}[1][]{\stepcounter{fignum}%
173 \def\gnuplotterminal{latex}%%
174 \def\gnuplotterminaloptions{}%%
175 \def\gnuplotscale{1}%%
176 \setkeys{pic}{#1}%%
177 \xdef\gnuplotCutFile{\subfolder/\figname.gnuplot}%%
178 \gnuplotverbatimwrite{\gnuplotCutFile}}
179 {\endgnuplotverbatimwrite%
180 \gnuplotgraphicsprocess%
181 \gnuplotgraphicsinclude}
182 \def\extension{\gnuplottexextension{\gnuplotterminal}}
183 \long\gdef\gnuplotgraphicsprocess{%
184 \ifShellEscape%
185 \IfFileExists{\subfolder/\figname.gnuplot}{%
186 \ifmiktex
187 \immediate\write18{\gnuplotexe\space \subfolder/\figname.gnuplot}%
188 \else
189 \immediate\write18{\gnuplotexe\space \subfolder/\figname.gnuplot\space 2>>\jobname.gnuploterrors}%
190 \fi%
191 \IfFileExists{\subfolder/\figname.\extension}{%
192 \PackageInfo{gnuplottex}{\subfolder/\figname.gnuplot converted}%
193 \ifcleanup
194 \ifmiktex
195 \immediate\write18{del "\subfolder/\figname.gnuplot"}%
196 \else
197 \immediate\write18{rm -f "\subfolder/\figname.gnuplot"}%
198 \fi%
199 \fi%
200 }
201 {\PackageWarningNoLine{gnuplottex}
202 {Conversion of \subfolder/\figname.gnuplot failed}}}{}%
203 \fi}
204 \long\def\gnuploterrors@eatpar#1#2\@nil{\def\gnuploterrors@{#2}}
205 \AtEndDocument{%
206 \ifmiktex
207 \else
208 \IfFileExists{\jobname.gnuploterrors}{%
209 \CatchFileDef\gnuploterrors@{\jobname.gnuploterrors}{\endlinechar=`^^J \catcode`\ =12 }%
210 \expandafter\gnuploterrors@eatpar\gnuploterrors@\@nil
211 \ifx\gnuploterrors@\@empty\else
212 \PackageWarningNoLine{gnuplottex}{Gnuplot execution produced errors:^^J%
213 \detokenize\expandafter{\gnuploterrors@}}%
214 \fi
215 }{}
216 \fi
217 }
218 \long\gdef\gnuplotgraphicsinclude{%
219 \IfFileExists{\subfolder/\figname.\extension}{%
220 \ifthenelse{\equal{\extension}{\string tex}}
221 {\scalebox{\gnuplotscale}{\input{\subfolder/\figname.\extension}}}
222 {\includegraphics[scale=\gnuplotscale]{\subfolder/\figname.\extension}}
223 }
224 {\PackageWarningNoLine{gnuplottex}
225 {Please convert \subfolder/\figname.gnuplot manually}}
226 }
227 \newcommand{\gnuplotloadfilewrite}[2]{%
228 \immediate\openout \verbatim@out #1%
229 \message{Opening gnuplot stream #1}%
230 \immediate\write\verbatim@out{\string set terminal \gnuplotterminal \gnuplotterminaloptions}%
231 \immediate\write\verbatim@out{\string set output '\subfolder/\figname.\gnuplottexextension{\gnuplotterminal}'}%
232 \ifusesiunitx
233 \ifthenelse{\equal{\extension}{\string tex}}{\usesiunitxingnuplot}{\PackageWarningNoLine{gnuplottex}{Axis numbers not written in \noexpand\num{}. Use a terminal that allows TeX output to enable this feature.}}
234 \else
235 \relax
236 \fi
237 \ifusesiunitx
238 {\escapechar=-1\edef\percentforgnuplot{\string\%}
239 \escapechar=-1\edef\backslashforgnuplot{\string\\}
240 \immediate\write\verbatim@out{set format '\backslashforgnuplot num{\percentforgnuplot g}'}}
241 \else
242 \relax
243 \fi
244 \immediate\write\verbatim@out{\string load '#2'}%
245 \immediate\closeout\verbatim@out%
246 }
247
248 \newcommand{\gnuplotloadfile}[2][]{
249 \stepcounter{fignum}%
250 \def\gnuplotterminal{latex}
251 \def\gnuplotterminaloptions{}
252 \def\gnuplotscale{1}
253 \setkeys{pic}{#1}
254 \xdef\gnuplotCutFile{\subfolder/\figname.gnuplot}
255 \gnuplotloadfilewrite{\gnuplotCutFile}{#2}
256 \gnuplotgraphicsprocess%
257 \gnuplotgraphicsinclude
258 }
259 \endinput
260 %%
261 %% End of file `gnuplottex.sty'.