-
Notifications
You must be signed in to change notification settings - Fork 1
/
graphviz.sty
77 lines (63 loc) · 2.19 KB
/
graphviz.sty
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
% graphviz.sty
% by Mark Aufflick
% 2006-03-25
% http://mark.aufflick.com/
%
% based on graphviz.tex by Derek Rayside 2003
% Modified by Mike Prentice ([email protected])
% 2011-02-21
% To use PDF output directly from dot
% dot -Tpdf
% Modified by Remi Dubot ([email protected])
% 2012-12-3
% To distinguish errors from tex and from dot.
% Report dot errors
% Indications for non english writers
% add the following lines to your preamble:
% \usepackage[pdftex]{graphicx}
% \usepackage{graphviz}
% parameters to \digraph:
% 1 - parameters for \includegraphics (optional; default value is "scale=1")
% 2 - name of the digraph
% 3 - body of the digraph
% parameters to \includedot
% 1 - parameters for \includegraphics (optional; default value is "scale=1")
% 2 - name of the dot file (w/out file extension, which must be `.dot')
% ASSUMES pdflatex
% If you are not using pdflatex, go back on an older version of this style.
% If you are not writing english, pay attention to your charset.
% If is not UTF-8, you may have to indicate your charset to dot with "-Gccharset=XXXX".
\ProvidesPackage{graphviz}
\newcommand{\includedot}[2][scale=1]{%
\ifnum\pdfshellescape=1
% Yes, enabled
\immediate\write18{bash -c "dot -Tpdf #2.dot -o #2.pdf 2> #2.log"}%
\IfFileExists{#2.pdf}
% the pdf exists: include it
{\includegraphics[#1]{#2}}
% the pdf was not created - show a hint
{ \fbox{ \begin{tabular}{l}
The file \texttt{#2.pdf} hasn't been created from
\texttt{#2.dot} yet. \\
We attempted to create it with:\\
`\texttt{dot -Tpdf #2.dot -o #2.pdf}' \\
but that seems not to have worked.\\
\texttt{dot} said : \\
"\texttt{\input{#2.log}}"
\end{tabular}}
}
\else
\fbox{ \begin{tabular}{l}
You need to execute `\texttt{pdflatex}' with the `\texttt{-shell-escape}' option.\\
This allows the graphviz package to execute the program dot.
\end{tabular}}
\fi
}
\newcommand{\digraph}[3][scale=1]{
\newwrite\dotfile
\immediate\openout\dotfile=#2.dot
\immediate\write\dotfile{digraph #2 {\string#3}}
\immediate\closeout\dotfile
\includedot[#1]{#2}
}