2 %% This is file `graphviz.sty',
3 %% generated with the docstrip utility.
5 %% The original source files were:
7 %% graphviz.dtx (with options: `package')
9 %% This is a generated file.
11 %% Copyright (C) 2003-13 by Derek Rayside <drayside@uwaterloo.ca>
13 %% This file may be distributed and/or modified under the conditions of
14 %% the LaTeX Project Public License, either version 1.3c of this license
15 %% or (at your option) any later version. The latest version of this
18 %% http://www.latex-project.org/lppl.txt
20 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
21 \ProvidesPackage{graphviz}
22 [2013/08/15 v0.94 .dtx graphviz file]
24 \DeclareOption{singlefile}{
26 \AtBeginDocument{% open a new file handle
27 \newwrite\masterdotfile%
28 \immediate\openout\masterdotfile=\@tmpdir tmpmaster.graphviz%
29 \newwrite\mastergvprfile%
30 \immediate\openout\mastergvprfile=\@tmpdir tmpmaster.gvpr}
31 \AtEndDocument{% close the file
32 % close the dot file and the gvpr file
33 \immediate\closeout\masterdotfile%
34 \immediate\closeout\mastergvprfile%
35 % execute the gvpr file
36 \immediate\write18{gvpr -f \@tmpdir tmpmaster.gvpr \@tmpdir tmpmaster.graphviz}%
39 \DeclareOption{psfrag}{ \psfragtrue }
40 \newcommand{\@outext}{ps}
41 \newcommand{\@outextspace}{ps }
43 \renewcommand{\@outext}{ps}
44 \renewcommand{\@outextspace}{ps }}
46 \renewcommand{\@outext}{pdf}%
47 \renewcommand{\@outextspace}{pdf }}
48 \newcommand{\@tmpdir}{}
49 \DeclareOption{tmpdir}{%
50 \immediate\write18{mkdir ./tmp/}%
51 \renewcommand{\@tmpdir}{./tmp/}}
53 \ProcessOptions\relax % LaTeX class guide says it is wise to relax
54 \RequirePackage{graphicx}
55 \ifpsfrag \RequirePackage{psfrag} \fi
56 \newcommand{\digraph}[2][scale=1]{
57 \inputdigraph[#1]{#2}{dot}% % Include the generated ps/pdf.
58 \@digraph{digraph}{#2}% % Generate the .dot file.
60 \newcommand{\neatograph}[2][scale=1]{
61 \inputdigraph[#1]{#2}{neato}% % Include the generated ps/pdf.
62 \@digraph{graph}{#2}% % Generate the .dot file.
65 \catcode`\^^M=\active%
66 \gdef\@digraph{\begingroup\catcode`\^^M=\active\def^^M{^^J}\@@digraph}%
68 \def\@@digraph#1#2#3{%
69 \ifsinglefile% write the graph to the master file
70 \expandafter\def\csname -\endcsname{\string\n}%
71 \immediate\write\masterdotfile{#1 #2 {#3}}%
72 \immediate\write\mastergvprfile{BEG_G { if ($.name == "#2") {writeG($G,"\@tmpdir#2.dot");} }}%
73 \else% open a new file handle
75 \immediate\openout\dotfile=\@tmpdir#2.dot%
76 \expandafter\def\csname -\endcsname{\string\n}%
77 \immediate\write\dotfile{#1 #2 {#3}}%
78 \immediate\closeout\dotfile%
81 \newcommand{\inputdigraph}[3][scale=1]{
82 % execute dot or neato (nb: requires latex -shell-escape)
83 \immediate\write18{#3 -T\@outextspace -o \@tmpdir#2.\@outextspace \@tmpdir#2.dot}
84 \IfFileExists{\@tmpdir#2.\@outext}{ % the postscript/pdf exists: include it
86 % per the ladot 2.2 source code, psfrag has a problem with
87 % graphviz 2.2, and some sed hackery is necessary to work around
88 \write18{sed -ibackup -e "s/xshow/pop show/g" \@tmpdir#2.ps}
90 \includegraphics[#1]{\@tmpdir#2.\@outext}
92 % else: the postscript/pdf doesn't exist: tell the user how to create it
94 \fbox{ \begin{tabular}{l}
95 The file \texttt{#2.\@outext} hasn't been created from
96 \texttt{\@tmpdir#2.dot} yet. \\
97 Run `\texttt{dot -T\@outextspace -o \@tmpdir#2.\@outextspace \@tmpdir#2.dot}'
99 Or invoke \LaTeX\ with the \texttt{-shell-escape} option
100 to have this done automatically. \\
106 %% End of file `graphviz.sty'.