Debian Codegraph @

texmf-dist/source/latex/dottex/dottex.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (c) 2005-2007, Lars Kotthoff <[email protected]>
4 %
5 % Large portions copied from pdftex,
6 % Copyright (c) 2001-3, Radhakrishnan CV <[email protected]>
7 % Rajagopal CV <[email protected]>
8 % http://www.river-valley.com
9 %
10 % River Valley Technologies, Floor III, SJP Buildings, Cotton Hills
11 % Trivandrum, India 695014
12 %
13 % Tel: +91 471 233 7501
14 %
15 % Antoine Chambert-Loir
16 % <[email protected]>
17 % http://www.math.polytechnique.fr/~chambert
18 %
19 % Ecole polytechnique, Palaiseau Cedex, France
20 %
21 % This program is free software; you can redistribute it and/or
22 % modify it under the terms of the GNU General Public License
23 % as published by the Free Software Foundation; either version 2
24 % of the License, or (at your option) any later version.
25 %
26 % This program is distributed in the hope that it will be useful,
27 % but WITHOUT ANY WARRANTY; without even the implied warranty of
28 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 % GNU General Public License for more details.
30 %
31 % You should have received a copy of the GNU General Public License
32 % along with this program (gpl.txt); if not, write to the Free
33 % Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
34 % MA 02111-1307, USA.
35 %
36 % \fi
37 %
38 % \iffalse
39 %<*driver>
40 \ProvidesFile{dottex.dtx}
41 %</driver>
42 %<package> \NeedsTeXFormat{LaTeX2e}[1999/12/01]
43 %<package> \ProvidesPackage{dottex}
44 %<*package>
45 [2007/08/22 v0.6 dot/neato graphs in LaTeX]
46 \RequirePackage{graphicx,moreverb,keyval}
47 %</package>
48 %
49 %<*driver>
50 \documentclass{ltxdoc}
51 \usepackage{dottex}
52 \EnableCrossrefs
53 \CodelineIndex
54 \RecordChanges
55 \begin{document}
56 \DocInput{dottex.dtx}
57 \PrintChanges
58 \PrintIndex
59 \end{document}
60 %</driver>
61 % \fi
62 %
63 % \CheckSum{397}
64 %
65 % \CharacterTable
66 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
67 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
68 % Digits \0\1\2\3\4\5\6\7\8\9
69 % Exclamation \! Double quote \" Hash (number) \#
70 % Dollar \$ Percent \% Ampersand \&
71 % Acute accent \' Left paren \( Right paren \)
72 % Asterisk \* Plus \+ Comma \,
73 % Minus \- Point \. Solidus \/
74 % Colon \: Semicolon \; Less than \<
75 % Equals \= Greater than \> Question mark \?
76 % Commercial at \@ Left bracket \[ Backslash \\
77 % Right bracket \] Circumflex \^ Underscore \_
78 % Grave accent \` Left brace \{ Vertical bar \|
79 % Right brace \} Tilde \~}
80 %
81 %
82 % \changes{v0.1}{2005/08/06}{Initial version.}
83 % \changes{v0.2}{2005/08/13}{New way to set graph width, neatopic environment.}
84 % \changes{v0.3}{2005/11/16}{Added pdf option to package.}
85 % \changes{v0.4}{2006/01/23}{Changed pdf support to ps -> eps -> pdf conversion.
86 % Fixed bugs.}
87 % \changes{v0.5}{2006/04/02}{Added keyval interface for picture dimensions.}
88 % \changes{v0.6}{2007/08/22}{Improved Miktex support.}
89 %
90 % \GetFileInfo{dottex.dtx}
91 %
92 % \DoNotIndex{\the,\year,\month,\day,\time}
93 %
94 % \title{The \textsf{dottex} package\thanks{This document
95 % corresponds to \textsf{dottex}~\fileversion, dated \filedate.}}
96 % \author{Lars Kotthoff\\ \texttt{[email protected]}}
97 %
98 % \maketitle
99 %
100 % \section{Introduction}
101 %
102 % This package allows you to include dot and neato graphs in your \LaTeX{} documents.
103 %
104 % The dot/neato code is extracted from the document and written to
105 % \texttt{.dot}/\texttt{.neato}
106 % files. Then, if shell escape is used, the graph files are automatically
107 % processed and converted to PostScript files, which will then be included. If
108 % shell escape isn't used, the user will have to manually convert the
109 % files.
110 %
111 % Shell escape is available in the web2c \TeX{} compiler, it allows the execution
112 % of shell code during the compilation of a \TeX{} document. It's disabled by
113 % default, you'll have to edit your configuration files or give the
114 % \texttt{-shell-escape} option to \texttt{latex}.
115 % A check is performed whether shell escape really works, so you might get
116 % warnings that the \texttt{.dot}/\texttt{.neato} files need to be converted manually although
117 % you enabled shell escape.
118 %
119 % \section{Requirements}
120 %
121 % To use dottex, you'll need the \texttt{graphicx}, \texttt{keyval} and
122 % \texttt{moreverb} packages, ps2pdf if you want to use the pdf
123 % option, and of course, dot / neato of the Graphviz package. All the binaries
124 % need to be in your PATH, i.e.\ you should be able to call them without
125 % specifying the absolute path to the binary.
126 %
127 % \section{Usage}
128 %
129 % To load the package, simply \verb=\usepackage{dottex}= in your document
130 % preamble. Options that can be passed to the package are
131 % \begin{description}
132 % \item[\oarg{shell}] Use shell escape to automatically generate the graphs
133 % from the dot source files. This is the default. Normally, you don't need
134 % to specify it.
135 % \item[\oarg{noshell}] Don't use shell escape, graphs must be generated
136 % manually.
137 % \item[\oarg{miktex}] We're using mikTeX.
138 % \item[\oarg{pdf}] PDF output, generate .pdf files of the graphs out of
139 % .ps.
140 % \end{description}
141 %
142 % The following environments can be used to include graphs:
143 %
144 % \DescribeEnv{dotpic}
145 % Within this environment, you can specify arbitrary dot code, for example\\
146 % \texttt{a -> b;\\b -> a;}.\\
147 % The \texttt{digraph} preamble and the surrounding braces are inserted
148 % automatically.
149 %
150 % \DescribeEnv{neatopic}
151 % Within this environment, you can specify arbitrary neato code, for example\\
152 % \texttt{a -- b;\\b -- a;}.\\
153 % The \texttt{graph} preamble and the surrounding braces are inserted
154 % automatically.
155 %
156 % For both environments, you may specify width or height of the picture using
157 % [width=\meta{width}] or [height=\meta{height}] as in the \texttt{includegraphics} command.
158 %
159 % \section{Acknowledgements}
160 %
161 % Thanks to Klaus Storch for several suggestions to improve the Miktex
162 % compatibility.
163 %
164 % \StopEventually{}
165 %
166 % \section{Implementation}
167 %
168 % \subsection{Initialization}
169 % \begin{macrocode}
170 \newif\ifShellEscape
171 \newif\ifmiktex \miktexfalse
172 \newif\ifpdf \pdffalse
173
174 \DeclareOption{shell}{\ShellEscapetrue}
175 \DeclareOption{noshell}{\ShellEscapefalse}
176 \DeclareOption{miktex}{\global\miktextrue}
177 \DeclareOption{pdf}{\pdftrue}
178
179 \ExecuteOptions{shell}
180 \ProcessOptions\relax
181 %% test if shell escape really works
182 \ifShellEscape
183 \def\tmpfile{/tmp/w18-test-\the\year\the\month\the\day\the\time}
184 \ifmiktex
185 \def\tmpfile{w18-test-\the\year\the\month\the\day\the\time}
186 \immediate\write18{echo t > "\tmpfile"}
187 \else
188 \immediate\write18{touch \tmpfile}
189 \fi
190 \ifmiktex
191 \IfFileExists{\tmpfile.}{\ShellEscapetrue}{\ShellEscapefalse}
192 \immediate\write18{del "\tmpfile"}
193 \else
194 \IfFileExists{\tmpfile}{\ShellEscapetrue}{\ShellEscapefalse}
195 \immediate\write18{rm -f \tmpfile}
196 \fi
197 \fi
198
199 \ifShellEscape
200 \PackageInfo{dottex}
201 {Automatically converting dot/neato files}
202 \else
203 \PackageWarningNoLine{dottex}
204 {Shell escape not enabled.\MessageBreak
205 You'll need to convert the graphs yourself.}
206 \fi
207 \newcounter{fignum}
208 % \end{macrocode}
209 %
210 % \subsection{\texttt{.dot}/\texttt{.neato} write out}
211 % \begin{macrocode}
212 \def\figname{\jobname-dottex-fig\thefignum}
213
214 \def\dotverbatimwrite#1{%
215 \def\BeforeStream
216 {\message{Opening Dot stream=\figname.dot}%
217 \immediate\write\verbatim@out{\string digraph\space G\space {/*}*/}
218 }
219 \@bsphack
220 \immediate\openout \verbatim@out #1
221 \BeforeStream%
222 \let\do\@makeother\dospecials
223 \catcode`\^^M\active
224 \def\verbatim@processline{%
225 \immediate\write\verbatim@out
226 {\the\verbatim@line}}%
227 \verbatim@start}
228 \def\enddotverbatimwrite{%
229 \immediate\write\verbatim@out{/*{*/}}
230 \immediate\closeout\verbatim@out
231 \@esphack}
232
233 \def\neatoverbatimwrite#1{%
234 \def\BeforeStream
235 {\message{Opening Neato stream=\figname.neato}%
236 \immediate\write\verbatim@out{\string graph\space G\space {/*}*/}
237 }
238 \@bsphack
239 \immediate\openout \verbatim@out #1
240 \BeforeStream%
241 \let\do\@makeother\dospecials
242 \catcode`\^^M\active
243 \def\verbatim@processline{%
244 \immediate\write\verbatim@out
245 {\the\verbatim@line}}%
246 \verbatim@start}
247 \def\endneatoverbatimwrite{%
248 \immediate\write\verbatim@out{/*{*/}}
249 \immediate\closeout\verbatim@out
250 \@esphack}
251 % \end{macrocode}
252 %
253 % The spurious braces (commented out in the \texttt{.dot}/\texttt{.neato} file) are necessary
254 % because \LaTeX{} gets confused with only one brace.
255 %
256 %
257 % \subsection{Environment definition}
258 % \begin{macrocode}
259 \define@key{pic}{width}{\def\dotwidth{#1}}
260 \define@key{pic}{height}{\def\dotheight{#1}}
261 \newenvironment{dotpic}[1][]{\stepcounter{fignum}%
262 \let\dotwidth\undefined
263 \let\dotheight\undefined
264 \setkeys{pic}{#1}
265 \xdef\dotCutFile{\figname.dot}
266 \dotverbatimwrite{\dotCutFile}}
267 {\enddotverbatimwrite%
268 \dotgraphicsinclude}
269
270 \newenvironment{neatopic}[1][]{\stepcounter{fignum}%
271 \let\dotwidth\undefined
272 \let\dotheight\undefined
273 \setkeys{pic}{#1}
274 \xdef\neatoCutFile{\figname.neato}
275 \neatoverbatimwrite{\neatoCutFile}}
276 {\endneatoverbatimwrite%
277 \neatographicsinclude}
278 % \end{macrocode}
279 %
280 % \subsection{\texttt{.dot}/\texttt{.neato} file processing}
281 % \begin{macrocode}
282 \long\gdef\dotgraphicsprocess{%
283 \ifShellEscape
284 \IfFileExists{\figname.dot}{%
285 \immediate\write18{dot -Tps2 -o \figname.ps \figname.dot}
286 \IfFileExists{\figname.ps}{%
287 \ifpdf
288 \immediate\write18{ps2pdf \figname.ps \figname.pdf}
289 \IfFileExists{\figname.pdf}{%
290 \PackageInfo{dottex}
291 {\figname.dot converted}}
292 {\PackageWarningNoLine{dottex}
293 {Conversion of \figname.dot failed.}}
294 \else
295 \PackageInfo{dottex}
296 {\figname.dot converted}
297 \fi}
298 {\PackageWarningNoLine{dottex}
299 {Conversion of \figname.dot failed.}}}{}
300 \fi}
301
302 \long\gdef\neatographicsprocess{%
303 \ifShellEscape
304 \IfFileExists{\figname.neato}{%
305 \immediate\write18{neato -Tps2 -o \figname.ps \figname.neato}
306 \IfFileExists{\figname.ps}{%
307 \ifpdf
308 \immediate\write18{ps2pdf \figname.ps \figname.pdf}
309 \IfFileExists{\figname.pdf}{%
310 \PackageInfo{dottex}
311 {\figname.dot converted}}
312 {\PackageWarningNoLine{dottex}
313 {Conversion of \figname.dot failed.}}
314 \else
315 \PackageInfo{dottex}
316 {\figname.neato converted}
317 \fi}
318 {\PackageWarningNoLine{dottex}
319 {Conversion of \figname.neato failed.}}}{}
320 \fi}
321 % \end{macrocode}
322 %
323 % \subsection{Graph inclusion}
324 % \begin{macrocode}
325 \long\gdef\dotgraphicsinclude{\dotgraphicsprocess%
326 \ifpdf
327 \IfFileExists{\figname.pdf}{%
328 \ifx\dotwidth\undefined
329 \ifx\dotheight\undefined
330 \includegraphics{\figname}
331 \else
332 \includegraphics[height=\dotheight]{\figname}
333 \fi
334 \else
335 \ifx\dotheight\undefined
336 \includegraphics[width=\dotwidth]{\figname}
337 \else
338 \includegraphics[width=\dotwidth,height=\dotheight]{\figname}
339 \fi
340 \fi
341 }
342 {\PackageWarningNoLine{dottex}
343 {Please convert \figname.dot manually}}
344 \else
345 \IfFileExists{\figname.ps}{%
346 \ifx\dotwidth\undefined
347 \ifx\dotheight\undefined
348 \includegraphics{\figname}
349 \else
350 \includegraphics[height=\dotheight]{\figname}
351 \fi
352 \else
353 \ifx\dotheight\undefined
354 \includegraphics[width=\dotwidth]{\figname}
355 \else
356 \includegraphics[width=\dotwidth,height=\dotheight]{\figname}
357 \fi
358 \fi
359 }
360 {\PackageWarningNoLine{dottex}
361 {Please convert \figname.dot manually}}
362 \fi
363 }
364
365 \long\gdef\neatographicsinclude{\neatographicsprocess%
366 \ifpdf
367 \IfFileExists{\figname.pdf}{%
368 \ifx\dotwidth\undefined
369 \ifx\dotheight\undefined
370 \includegraphics{\figname}
371 \else
372 \includegraphics[height=\dotheight]{\figname}
373 \fi
374 \else
375 \ifx\dotheight\undefined
376 \includegraphics[width=\dotwidth]{\figname}
377 \else
378 \includegraphics[width=\dotwidth,height=\dotheight]{\figname}
379 \fi
380 \fi
381 }
382 {\PackageWarningNoLine{dottex}
383 {Please convert \figname.neato manually}}
384 \else
385 \IfFileExists{\figname.ps}{%
386 \ifx\dotwidth\undefined
387 \ifx\dotheight\undefined
388 \includegraphics{\figname}
389 \else
390 \includegraphics[height=\dotheight]{\figname}
391 \fi
392 \else
393 \ifx\dotheight\undefined
394 \includegraphics[width=\dotwidth]{\figname}
395 \else
396 \includegraphics[width=\dotwidth,height=\dotheight]{\figname}
397 \fi
398 \fi
399 }
400 {\PackageWarningNoLine{dottex}
401 {Please convert \figname.neato manually}}
402 \fi
403 }
404 % \end{macrocode}
405 %
406 % \Finale
407 \endinput