Debian Codegraph @

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

raw
1 %% dot2texi.sty
2 %% Copyright (c) 2007-2008, Kjell Magne Fauske
3 %%
4 %% Author: Kjell Magne Fauske <[email protected]>
5 %% http://www.fauskes.net
6 %%
7 %% Defines the dot2tex environment for encapsulating graphs described
8 %% using the Grahviz[1] DOT-language. The dot2tex[2] command line tool is
9 %% used to convert output from Graphviz' graph layot tools to TikZ and
10 %% PGF, or PSTricks code. The package will automate this process if
11 %% shell-escape is enabled.
12 %%
13 %% This code is adapted from the packages dottex[3] and gnuplottex[4],
14 %% written by Lars Kotthoff. The platform detection code is from the
15 %% ifplatform[5] package.
16 %%
17 %% [1] http://www.graphviz.org/
18 %% [2] http://www.fauskes.net/code/dot2tex/
19 %% [3] http://http://www.ctan.org/tex-archive/help/Catalogue/entries/dottex.html
20 %% [4] http://www.ctan.org/tex-archive/help/Catalogue/entries/gnuplottex.html
21 %% [5] http://www.ctan.org/tex-archive/help/Catalogue/entries/ifplatform.html
22
23 %% Copyright (c) 2005, Lars Kotthoff <[email protected]>
24 %%
25 %% Large portions copied from pdftex,
26 %% Copyright (c) 2001-3, Radhakrishnan CV <[email protected]>
27 %% Rajagopal CV <[email protected]>
28 %% http://www.river-valley.com
29 %%
30 %% River Valley Technologies, Floor III, SJP Buildings, Cotton Hills
31 %% Trivandrum, India 695014
32 %%
33 %% Tel: +91 471 233 7501
34 %%
35 %% Antoine Chambert-Loir
36 %% <[email protected]>
37 %% http://www.math.polytechnique.fr/\protect \unhbox \voidb@x \penalty \@M \ {}chambert
38 %%
39 %% Ecole polytechnique, Palaiseau Cedex, France
40 %%
41 %% This program is free software; you can redistribute it and/or
42 %% modify it under the terms of the GNU General Public License
43 %% as published by the Free Software Foundation; either version 2
44 %% of the License, or (at your option) any later version.
45 %%
46 %% This program is distributed in the hope that it will be useful,
47 %% but WITHOUT ANY WARRANTY; without even the implied warranty of
48 %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49 %% GNU General Public License for more details.
50 %%
51 %% You should have received a copy of the GNU General Public License
52 %% along with this program (gpl.txt); if not, write to the Free
53 %% Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
54 %% MA 02111-1307, USA.
55 %%
56
57 %% Copyright (C) 2007 by Will Robertson & Johannes Große
58
59 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
60 \ProvidesPackage{dot2texi}[2008/05/07 v3.0p1 Run dot2tex from LaTeX]
61 \RequirePackage{moreverb}
62 \RequirePackage{xkeyval}[2005/02/22]
63
64 %
65 % fix for new moreverb according to the author of this file as state in
66 % https://groups.google.com/forum/?fromgroups#!topic/dot2tex-users/kbjZGRVT5SY
67 % fix included by Norbert Preining, renamed the version to v3.0p1
68 \@ifundefined{verbatim@out}{\newwrite\verbatim@out}{}%
69 %
70 \newif\ifdtt@ShellEscape
71 %\newif\ifmiktex \miktexfalse
72 \newif\ifdtt@ForceShellEscape \dtt@ForceShellEscapefalse
73 \newif\ifdtt@debug \dtt@debugfalse
74 \newif\ifdtt@autosize \dtt@autosizefalse
75 % Options related to shell escape
76 \DeclareOptionX{shell}{\dtt@ShellEscapetrue}
77 \DeclareOptionX{noshell}{\dtt@ShellEscapefalse}
78 \DeclareOptionX{forceshell}{\dtt@ForceShellEscapetrue\dtt@ShellEscapetrue}
79 \DeclareOptionX{miktex}{} % dummy (for backwards compatability)
80
81 % Options for setting output format
82 \DeclareOptionX{pgf}{\def\dtt@format{-fpgf}}
83 \DeclareOptionX{tikz}{\def\dtt@format{-ftikz}}
84 \DeclareOptionX{pstricks}{\def\dtt@format{-fpstricks}}
85 \def\dtt@format{-ftikz} % default output format
86
87
88 \DeclareOptionX{autosize}{\def\dtt@autosizeopt{--autosize}}
89 \def\dtt@autosizeopt{}
90
91 % Options for setting the graph layout program
92 \DeclareOptionX{dot}{\def\dtt@procprog{--prog=dot}}
93 \DeclareOptionX{neato}{\def\dtt@procprog{--prog=neato}}
94 \DeclareOptionX{circo}{\def\dtt@procprog{--prog=circo}}
95 \DeclareOptionX{fdp}{\def\dtt@procprog{--prog=fdp}}
96 \DeclareOptionX{twopi}{\def\dtt@procprog{--prog=twopi}}
97 \def\dtt@procprog{}
98
99 % Option for setting an output directory
100 \DeclareOptionX{outputdir}[]{\def\dtt@outputdir{#1}}
101 \def\dtt@outputdir{}
102 \DeclareOptionX{debug}{\dtt@debugtrue}
103
104 \newcommand\setoutputdir[1]{\def\dtt@outputdir{#1}}
105
106 \ExecuteOptionsX{shell}
107
108 \ProcessOptionsX\relax
109
110
111 %% The platform detection code is copied from the ifplatform package
112 %% avaialable from: http://tug.ctan.org/tex-archive/macros/latex/contrib/ifplatform/
113 %% Copyright (C) 2007 by Will Robertson & Johannes Große
114 \newif\ifdtt@ShellEscapeEnabled
115 \newif\ifwindows
116 \edef\ip@file{\jobname.w18}
117 \edef\ip@sig{write18-test-\the\year\the\month\the\day\the\time}
118 \edef\ip@win{'\ip@sig'}
119 \def\ip@read@file{%
120 \newread\instream
121 \openin\instream=\ip@file
122 \@tempcnta=\endlinechar
123 \endlinechar=-1
124 \read\instream to\@tempa
125 \endlinechar=\@tempcnta
126 \closein\instream}
127 \immediate\write18{echo \ip@win >"\ip@file"}
128 \IfFileExists{\ip@file}{\dtt@ShellEscapeEnabledtrue}{\dtt@ShellEscapeEnabledfalse}
129 \ifdtt@ShellEscapeEnabled
130 \ip@read@file
131 \ifx\@tempa\ip@sig
132 \windowsfalse
133 \else
134 \ifx\@tempa\ip@win
135 \windowstrue
136 \fi
137 \fi
138 \immediate\write18{\ifwindows del \else rm -- \fi "\ip@file"}
139 \fi
140
141 \ifdtt@ForceShellEscape
142 \PackageInfo{dot2texi}
143 {ForceShellEscape enabled}
144 \fi
145
146 \ifdtt@ShellEscapeEnabled
147 \PackageInfo{dot2texi}
148 {Automatically converting dot/neato files}
149 \else
150 \PackageWarningNoLine{dot2texi}
151 {Shell escape not enabled.\MessageBreak
152 You'll need to convert the graphs yourself.}
153 \fi
154 \newcounter{dtt@fignum}
155 \def\dtt@figname{\dtt@outputdir\jobname-dot2tex-fig\thedtt@fignum}
156
157
158 %%%%%%%%%%%%%%%%% dot2tex code
159 % Most of the code is from dottex.sty and gnuplottex.sty
160
161 % Options
162 \def\dtt@debugstr{}
163 \ifdtt@debug
164 \PackageInfo{dot2texi}{Dot2tex debugging enabled}
165 \def\dtt@debugstr{--debug}
166 \fi
167
168 \define@choicekey*{dtt}{prog}[\progval\nr]{dot,neato,circo,fdp,twopi}[dot]{%
169 \def\dtt@procprog{--prog=\progval}}
170 \define@choicekey*{dtt}{format}[\outputval\nr]{tikz,pgf,pstricks}[tikz]{%
171 \def\dtt@format{--format=\outputval}}
172 \define@key{dtt}{options}[]{%
173 \def\dtt@options{#1}
174 }
175 \def\dtt@options{}
176
177 \define@key{dtt}{outputdir}[]{%
178 \def\dtt@outputdir{#1}
179 }
180 \define@key{dtt}{file}[]{%
181 \def\dtt@figname{\dtt@outputdir#1}
182 }
183
184 \define@key{dtt}{shell}[]{\dtt@ShellEscapetrue}
185 \define@key{dtt}{noshell}[]{\dtt@ShellEscapefalse}
186 % graph layout
187 \define@key{dtt}{dot}[]{\def\dtt@procprog{--prog=dot}}
188 \define@key{dtt}{neato}[]{\def\dtt@procprog{--prog=neato}}
189 \define@key{dtt}{circo}[]{\def\dtt@procprog{--prog=circo}}
190 \define@key{dtt}{fdp}[]{\def\dtt@procprog{--prog=fdp}}
191 \define@key{dtt}{twopi}[]{\def\dtt@procprog{--prog=twopi}}
192 % output formats
193 \define@key{dtt}{pgf}[]{\def\dtt@format{--format=pgf}}
194 \define@key{dtt}{tikz}[]{\def\dtt@format{--format=tikz}}
195 \define@key{dtt}{pstricks}[]{\def\dtt@format{--format=pstricks}}
196 % command line shortcuts
197 \define@key{dtt}{styleonly}[]{\def\dtt@styleonly{--styleonly}}
198 \def\dtt@styleonly{}
199 \define@key{dtt}{codeonly}[]{\def\dtt@output{--codeonly}}
200 \def\dtt@output{--figonly}
201 \define@key{dtt}{autosize}[]{\def\dtt@autosizeopt{--autosize}}
202 \define@key{dtt}{noautosize}[]{\def\dtt@autosizeopt{}}
203
204 \define@key{dtt}{straightedges}[]{\def\dtt@straightedges{--straightedges}}
205 \def\dtt@straightedges{}
206 \define@key{dtt}{tikzedgelabels}[]{\def\dtt@tikzedgelabels{--tikzedgelabels}}
207 \def\dtt@tikzedgelabels{}
208
209 \define@key{dtt}{mathmode}[]{\def\dtt@mathmode{-tmath}}
210 \def\dtt@mathmode{}
211
212 \define@key{dtt}{graphstyle}[]{\def\dtt@graphstyle{--graphstyle="#1"}}
213 \def\dtt@graphstyle{}
214
215 \define@key{dtt}{scale}[]{\def\dtt@graphstyle{--graphstyle="scale=#1,transform shape"}}
216
217 \newif\ifdtt@writetofile \dtt@writetofiletrue
218
219 \def\dottotexverbatimwrite#1{%
220 \def\BeforeStream{
221 \message{Opening dot2tex stream #1}%
222 }%
223 \@bsphack
224 \immediate\openout \verbatim@out #1
225 \BeforeStream%
226 \let\do\@makeother\dospecials
227 \catcode`\^^M\active
228 \def\verbatim@processline{%
229 \immediate\write\verbatim@out
230 {\the\verbatim@line}}%
231 \verbatim@start%
232 }
233
234 \def\enddottotexverbatimwrite{%
235 \immediate\closeout\verbatim@out
236 \@esphack
237 \catcode`\\0
238 \catcode`\{1
239 \catcode`\}2
240 \catcode`\$3
241 \catcode`\&4
242 \catcode`\^^M5
243 \catcode`\#6
244 \catcode`\^7
245 \catcode`\_8
246 \catcode`\~9% Added this one
247 \catcode`\ 10
248 \catcode`\%14}
249
250 \newenvironment{dot2tex}[1][]{\stepcounter{dtt@fignum}%
251 \setkeys{dtt}{#1}
252 \ifdtt@ForceShellEscape
253 \dtt@ShellEscapetrue
254 \fi
255 \xdef\dottotexCutFile{\[email protected]}
256 \dottotexverbatimwrite{\dottotexCutFile}}
257 {\enddottotexverbatimwrite%
258 \dottotexgraphicsinclude}
259
260 \long\gdef\dottotexgraphicsprocess{%
261 \ifdtt@ShellEscape
262 \IfFileExists{\[email protected]}{%
263 \immediate\write18{dot2tex \dtt@output\space
264 \dtt@format\space
265 \dtt@tikzedgelabels\space
266 \dtt@straightedges\space
267 \dtt@styleonly\space
268 \dtt@autosizeopt\space
269 \dtt@debugstr\space
270 \dtt@procprog\space
271 \dtt@mathmode\space
272 \dtt@graphstyle\space
273 -o \[email protected] \dtt@options\space \[email protected]}
274 \IfFileExists{\[email protected]}{%
275 \PackageInfo{dot2texo}{\[email protected] converted}
276 }
277 {\PackageWarningNoLine{dot2texi}
278 {Conversion of \[email protected] failed.}}}{}
279 \fi
280 }
281
282 \long\gdef\dottotexgraphicsinclude{\dottotexgraphicsprocess%
283 \IfFileExists{\[email protected]}{{\input{\dtt@figname}}}
284 {\PackageWarningNoLine{dot2texi}
285 {Please convert \[email protected] manually}}
286 }
287
288 \endinput