Begin main content

Embedding GraphViz in LaTeX documents

I have to say I'm loving using LaTeX for my Uni papers. It is so delightfully straightforward and powerful.

I am embedding some GraphViz diagrams in my documents, but I didn't want a round trip to a different editor buffer and the shell to edit/compile/insert the diagram.

Based on graphviz.tex code by Derek Rayside I have created a custom LaTeX function that will automatically compile and embed inline GraphViz code (man those wacky capitilisations are getting boring!)

You embed a graph like so:

   \digraph[scale=0.5]{MyGraph}{rankdir=LR; a->b; b->c}
Be careful not to have any double newlines or your dot file will have some bogus \par comments in it (which I should replace with newlines in the function...). Another possible enhancement would be to add a dynamic dot command to set the maximum diagram height & width to the current page/column dimensions.

You need my graphviz.sty and you need the following in your document preamble:

   \usepackage[pdftex]{graphicx}
   \usepackage{graphviz}
Remember to run texhash if you install the style in a system-wide location. Note this assumes pdflatex. Modifying the command for regular latex is an exercise left for the reader. Update: Derek now has an updated version available on GitHub (which didn't exist in 2007 :). https://github.com/drayside/graphviz.sty/blob/master/graphviz.sty.

08:09 AM, 25 Mar 2007 by Mark Aufflick Permalink

Todo

Change this style to use the excellent dot2tex: http://www.fauskes.net/nb/introducing-dot2tex/

by Mark Aufflick on 05/21/07

cool

Awesome! This was very useful for me.

by Unregistered Visitor on 02/13/09

Thank you

I really like this, and I fiddled around with dot2tex as suggested in your comment to yourself. Here are my results. I've never written a latex sty file before, so please feel free to improve it.

% graphviz.sty
% by Mark Aufflick
% 2006-03-25
% mark@aufflick.com
% http://mark.aufflick.com/
%
% based on graphviz.tex by Derek Rayside 2003

% 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

% assumes pdflatex. to modify this command for regular latex,
% replace all .pdf with .ps, and the command becomes simply:
% dot -Tps #1.dot

\ProvidesPackage{dottotex}

\newcommand{\dottotex}[2]{ 
  \newwrite\dotfile 
  \immediate\openout\dotfile=#1.dot 
  \immediate\write\dotfile{digraph #1 {\string#2}} 
  \immediate\closeout\dotfile
  \write18{bash -c "`which neato` -Txdot #1.dot | `which dot2tex` -tmath --figonly --usepdflatex -ftikz --tikzedgelabels --styleonly -o #1tikz.tex"}  
  \IfFileExists{#1tikz.tex}
  % the tex exists: include it 
  { \include{#1tikz} } 
  % the tex was not created - show a hint
  { \fbox{ \begin{tabular}{l} 
        The file \texttt{#1tikz.tex} hasn't been created from 
        \texttt{#1.dot} yet. \\
        We attempted to create it with:\\
        `\texttt{neato -Txdot #1.dot | dot2tex  --figonly --usepdflatex -ftikz --tikzedgelabels --styleonly -o #1tikz.tex}` \\
        but that seems not to have worked. You need to execute `\texttt{pdflatex}` with \\
        the `\texttt{-shell-escape}` option.
      \end{tabular}} 
  } 
}

by Unregistered Visitor on 04/02/09

Something to be wary of

You should not have the \newwrite directive in your \newcommand. If you do and use it a lot you will exhaust the write buffers available. Just move that command out of the \newcommand block. Like: \newwrite\dotfile \newcommand{\digraph}[4][scale=1]{ \immediate\openout\dotfile=#2.dot etc.

by Unregistered Visitor on 10/06/10

Updated version on Github

For an updated version of GraphViz.sty see Mike Prentice's Github version: https://github.com/mprentice/GraphViz-sty

by Mark Aufflick on 02/23/11

Filenames with hyphens

If you want filenames with hyphens in them, put quotes around #2 in the following line: \immediate\write\dotfile{digraph #2 {\string#3}}

by Unregistered Visitor on 04/02/13

Accents and labels with spaces

Very nice functionality! But how do you prevent PDFLaTeX from introducing strange codes when using spaces and accented characters in, e.g. label? Example: try the following \digraph[scale=0.5]{MyGraph}{rankdir=LR; a [label="This is A"]; a->b; b->c} If I drop the double quotes there will be three nodes instead of one, and any replacement of the quotes by single quotes or braces, will result in strange nodes labeled with LaTeX items from when it processes the box; just like when the label string contains accented characters. Solving this would, for my use, make graphviz.sty full featured. Best regards, Morten Lind.

by Unregistered Visitor on 06/27/13

Updated version on Github

I just uploaded a newer version of this to Github: https://github.com/drayside/graphviz.sty cheers, Derek.

by Unregistered Visitor on 08/15/13

william

Only aspire to mention ones content can be as incredible. This clarity with your post is superb and that i may think you’re a guru for this issue. High-quality along with your concur permit me to to seize your current give to keep modified by using approaching blog post. Thanks a lot hundreds of along with you should go on the pleasurable get the job done. cochack.biz

by Unregistered Visitor on 02/17/15

prova senza rischi

Effectively, the article is really the best theme on this registry related issue. I fit in with your decisions and will excitedly anticipate your next overhauls. prova senza rischi

by ahmed raza on 02/17/15

rebelmouse

Effortlessly, the article is really the best point on this registry related issue. I fit in with your decisions and will energetically anticipate your next overhauls. mehr Bewertungen

by ahmed raza on 02/17/15

I really

Only aspire to mention ones content can be as incredible. This clarity with your post is superb and that i may think you’re a guru for this issue. High-quality along with your concur permit me to to seize your current give to keep modified by using approaching blog post. Thanks a lot hundreds of along with you should go on the pleasurable get the job done. Viajes

by Unregistered Visitor on 02/17/15

folder lock crack free downloa

Only aspire to mention ones content can be as incredible. This clarity with your post is superb and that i may think you’re a guru for this issue. High-quality along with your concur permit me to to seize your current give to keep modified by using approaching blog post. Thanks a lot hundreds of along with you should go on the pleasurable get the job done folder lock crack free downloa

by Unregistered Visitor on 02/17/15

http://www.freehomedeposit.com

I enjoy what you guys are usually up too. This type of clever work and exposure! Keep up the amazing works guys I’ve incorporated you guys to my personal blogroll. http://www.freehomedeposit.com

by Unregistered Visitor on 02/18/15

abdbxvabaf

hack clash of clans gems Worst of Clash of Clans is that your empire will be attacked again and again, and if you're tired of seeing your city destroyed, the best you can do is take advantage of the 12 hours of shield featuring not attack immediately but to strengthen your defenses (or welded) during this period. gems for clash of clans

by Unregistered Visitor on 02/18/15

fut 15 coins

the immediate hours following the film, and looking to the future. Do you ask yourself the question “what must I do, or what can I do?” After watching the documentary several times I chose to devote a year my life to service. Not just service, but service that directly affects the lives of children. fut 15 coins

by Unregistered Visitor on 02/18/15

jhonalex

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. game killer

by Unregistered Visitor on 02/18/15

asdasd

Nice blog and absolutely outstanding. You can do something much better but i still say this perfect.Keep trying for the best. guest post services

by Unregistered Visitor on 02/19/15

awfaw23

trucchi clash of clans gemme Abbiamo iniziato sentire lamentele da parte degli utenti al di fuori degli Stati Uniti che sono stati primi a ricevere l'aggiornamento, così come alcuni utenti in Canada che ha ottenuto l'aggiornamento alla fine di gennaio e all'inizio di questo mese. Numerose discussioni oltre a Reddit e altri forum hanno parlato dei problemi, la mancanza di caratteristiche, e più dopo l'aggiornamento di Android 5.0 per il Lollipop One M8, e questi problemi sono frustrare molti proprietari. clash of clans truco

by Unregistered Visitor on 02/19/15

many reasons a person

There are many reasons a person may lose their hair. It could be from things as simple as stress, depression or diet. It could even be for more complex reasons such as hormonal imbalances and genes. hair program jared gates

by Unregistered Visitor on 02/19/15

SDASDASD

Great post, you have pointed out some fantastic points , I likewise think this s a very wonderful website. auto binary signals reviews

by Unregistered Visitor on 02/19/15

rozi

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.twitter

by Unregistered Visitor on 02/19/15

JAMS

This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work! Franklin Homes

by Unregistered Visitor on 02/19/15

vitamin b12

will have some bogus \par comments in it (which I should replace with newlines in the function...). Another possible enhancement would be to add a dynamic dot command to set the maximum diagram height & width to the current page/column dimensions. vitamin b12

by Unregistered Visitor on 02/19/15

binary options trading

I really like this, and I fiddled around with dot2tex as suggested in your comment to yourself. Here are my results. I've never written a latex sty file before, so please feel free to improve it. binary options trading

by Unregistered Visitor on 02/20/15

Thanks

Really nice of you for sure. ultra europe festival

by Unregistered Visitor on 02/20/15

anton

thanks your share information http://www.tokojamtanganfashion.com

by Unregistered Visitor on 02/21/15

suci

thanks your share information http://www.tokojamtanganfashion.com

by Unregistered Visitor on 02/21/15

ana

Thanks a lot for sharing. Will check back later for more of your articles. http://jam-tanganonline.org http://jualjam-tangan.com http://grosir-bajuanak.net http://tokotasbrandedonline.com

by Unregistered Visitor on 02/21/15

meta

thanks for his articel can menembah my insight on the internet, http://daftarhargahargamobil.blogspot.com http://harga-ikanhias.blogspot.com http://bursamobilkita.blogspot.com http://daftarhargahargamotor.blogspot.com http://koleksibatu-akik.blogspot.com

by Unregistered Visitor on 02/21/15

singapore accounting software

This is a very well written article. I’ll make sure to bookmark it and come back to read more of your useful info. singapore accounting software

by Unregistered Visitor on 02/22/15

jhonalex

Wow, this is really interesting reading. I am glad I found this and got to read it. Great job on this content. I like it. best link building service

by Unregistered Visitor on 02/22/15

asdasd

I went over this website and I believe you have a lot of wonderful information, saved to my bookmarks http://www.ceag-ag.com/

by Unregistered Visitor on 02/22/15

franklin7

I found your this post while searching for some related information on blog search... clash of clans cheats

by Unregistered Visitor on 02/23/15

franklin7

I think that thanks for the valuabe information and insights you have so provided here. online here hack brave frontier

by Unregistered Visitor on 02/23/15

william

Thank you for some other informative blog. Where else could I get that type of information written in such an ideal means? I have a mission that I’m just now working on, and I have been at the look out for such information. health news

by Unregistered Visitor on 02/23/15

franklin7

I read that Post and got it fine and informative. Please share more like that... voyance

by Unregistered Visitor on 02/23/15

SDASDASD

Excellent .. Amazing .. I’ll bookmark your blog and take the feeds also…I’m happy to find so many useful info here in the post, we need work out more techniques in this regard, thanks for sharing. www.abc12.com/story/27971908/girlfriend-activation-system-review-teaches-obsession-story-secrets-steps-of-gfas-v2

by Unregistered Visitor on 02/23/15

adads

I admire what you have done here. I like the part where you say you are doing this to give back but I would assume by all the comments that this is working for you as well. abc12.com

by Unregistered Visitor on 02/23/15

SDASDASD

Thank you a bunch for sharing this with all of us you actually realize what you are talking about! Bookmarked. Please also seek advice from my site =). We could have a hyperlink change contract between us! ultrasound technician 2015

by Unregistered Visitor on 02/23/15

aaaa

I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. Victorino Noval Producer

by Unregistered Visitor on 02/23/15

sae1

I enjoy what you guys are usually up too. This type of clever work and exposure! Keep up the amazing works guys I’ve incorporated you guys to my personal blogroll. Calculatoare Second Hand

by Unregistered Visitor on 02/24/15

sa21

My blog goes over a lot of the same topics as yours and I believe we could greatly benefit from each other. If you happen to be interested feel free to shoot me an e-mail. https://www.rebelmouse.com/howtopottytrainatoddler/

by Unregistered Visitor on 02/24/15

solar installation gold coast area

I am new to weblog and definitely liked this blog site. Very likely I’m going to bookmark your blog . solar installation gold coast area

by Unregistered Visitor on 02/24/15

holi images

choose the best holi images, sms, wallpapers from our beautiful collection and share with friends on whatapp, facebook,twiiter and other social media http://www.worldaroundu.com/2015/02/Happy-holi-whatsapp-images-whatsapp-sms-messages-greetings-facebook-sharing.html

by Unregistered Visitor on 02/25/15

franklin7

I found this much informative, as to what I was exactly searching for. Thanks for such post and please keep it up. fibroids miracle book

by Unregistered Visitor on 02/25/15

Embarazo

Consulta de Ginecología y Obstetricia en Madrid tratan las necesidades de las mujeres en todas las etapas de la vida, en la adolescencia, el embarazo, la menopausia y más allá.Proporcionar asistencia sanitaria para mujeres que requiere de una sensibilidad especial, en la Clínica DAM somos conscientes de ello y nos aseguramos de trabajar con profesionales competentes y atentos a las necesidades especiales de nuestras clientes.Cómo no, realizamos también todos los procesos de control y seguimiento del embarazo, para la detección temprana de problemas en el feto, siempre asegurando los cuidados necesarios para la madre.Embarazo

by Unregistered Visitor on 02/25/15

xx

Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. Ernest Caracter

by Unregistered Visitor on 02/25/15

sa3

Happy Anniversary! I’d do it again . . . and again . . . and again! MLB Luxury Suites

by Unregistered Visitor on 02/25/15

Nonton video online di vidio.com

temukan nonton film online subtitle indonesia tanpa download vidio.com temukan nonton movie online sub indo vidio.com temukan video lucu banget bikin ngakak abis vidio.com temukan video musik dangdut koplo pantura vidio.com temukan video klip musik barat terbaik sepanjang masa vidio.com

by Unregistered Visitor on 02/25/15

Nonton video lucu online di vidio.com

temukan video penampakan hantu nyata terekam cctv vidio.com temukan nonton drama korea online indonesian subtitle vidio.com temukan video tutorial make up natural untuk kulit sawo matang vidio.com temukan video gosip terbaru aliando dan prilly vidio.com temukan video ganteng ganteng serigala episode terakhir vidio.com

by Unregistered Visitor on 02/25/15

It is so delightfully

It is so delightfully straightforward and powerful. I am embedding some GraphViz diagrams in my documents, but I didn't want a round trip to a different editor buffer and the shell to edit/compile/insert the diagram. Based on graphviz.tex code by Derek Rayside I have created a custom LaTeX function that will automatically vimax pills

by Unregistered Visitor on 02/26/15

imti

have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon.. car rental in jaipur

by Unregistered Visitor on 02/26/15

sad2

The post is written in very a good manner and it contains many useful information for me. odwiedź stronę autora

by Unregistered Visitor on 02/26/15

franklin7

I know your expertise on this. I must say we should have an online discussion on this. Tax planning IFAs

by Unregistered Visitor on 02/26/15

asdsad

Im no expert, but I believe you just made an excellent point. You certainly fully understand what youre speaking about, and I can truly get behind that. phen375 reviews

by Unregistered Visitor on 02/26/15

dolor de cabeza

Thanks a lot for providing individuals with a spectacular possibility to read critical reviews and posts from this site. Simply wanted to write down a word in order to say thanks. dolor de cabeza

by Unregistered Visitor on 02/26/15

franklin7

This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck. best vitamin c serum

by Unregistered Visitor on 02/27/15

Buy Custom Essay

You can teach a student a lesson for a day; but if you can teach him to learn by creating curiosity, he will continue the learning process as long as he lives. Buy Essay | Buy Custom Essay

by Unregistered Visitor on 02/27/15

Essay writing help

I've worked too hard and too long to let anything stand in the way of my goals. I will not let my teammates down and I will not let myself down. Buy Essay | Buy Essay Writing Help

by Unregistered Visitor on 02/27/15

utorrent plus 3.3 crack

Only aspire to mention ones content can be as incredible. This clarity with your post is superb and that i may think you’re a guru for this issue. High-quality along with your concur permit me to to seize your current give to keep modified by using approaching blog post. Thanks a lot hundreds of along with you should go on the pleasurable get the job done. utorrent plus 3.3 crack

by Unregistered Visitor on 02/27/15

Vegas SEO conference

Court with your history For our other court appointed services, our goal is to help provide the most up to date and relevant interventions.Vegas SEO conference

by Unregistered Visitor on 02/28/15

franklin7

Great content material and great layout. Your website deserves all of the positive feedback it’s been getting. pregnancy miracle ebook by lisa olson

by Unregistered Visitor on 02/28/15

SEO Media Norge

We keep up with the latest techniques of building and have qualified tradesmen to ensure that your job/project is carried out safely. SEO Media Norge

by Unregistered Visitor on 02/28/15

wholesale prom dresses under 100

Excellent and decent post. I found this much informative. wholesale prom dresses under 100

by Unregistered Visitor on 02/28/15

lacrosse recruits

I also found your posts very interesting. In fact after reading, I had to go show it to my friend and he ejoyed it as well! lacrosse recruits

by Unregistered Visitor on 02/28/15

vaporite budy pen

I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. vaporite budy pen

by Unregistered Visitor on 02/28/15

www.bedbathandbeyondinsider.com

I have found this article very exciting. Do you have any others on this topic? I am also sending it to my friend to enjoy your writing style. www.bedbathandbeyondinsider.com

by Unregistered Visitor on 02/28/15

mobile home roofing

Thank you for another important article about ultrasound technician.mobile home roofing

by Unregistered Visitor on 02/28/15

Yıldırım Turan

I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page! Yıldırım Turan

by Unregistered Visitor on 02/28/15

San Francisco sports massage

That is a good idea, I am very happy to read this article, and I agree with the issues of this post. San Francisco sports massage

by Unregistered Visitor on 02/28/15

have a peek here

Easily, the article is actually the best topic on this registry related issue. have a peek here

by Unregistered Visitor on 02/28/15

JAMS

Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!THANKS!!!!!! math.fullerton.edu/?film-streaming

by Unregistered Visitor on 02/28/15

gold ira companies

This is actually the kind of information I have been trying to find. Thank you for writing this information. gold ira

by Unregistered Visitor on 02/28/15

Chicago Park high speed internet

I'm impressed by the details that you have on this web site. It reveals how nicely you perceive this subject. Chicago Park high speed internet

by Unregistered Visitor on 02/28/15

Graphics

wow, great, I was wondering how to cure acne naturally. and found your site by google, learned a lot, now i’m a bit clear. I’ve bookmark your site and also add rss. keep us updated. Graphics

by Unregistered Visitor on 02/28/15

pdf to word

Anyway I wanted to say that it's nice to know that someone else also mentioned this as I had trouble finding the same info elsewhere. pdf to word

by Unregistered Visitor on 02/28/15

Mobile Spy App

Thank you for this post. Thats all I are able to say. You most absolutely have built this blog website into something speciel. Mobile Spy App

by Unregistered Visitor on 02/28/15

Kidney Failure

Everything is beautifully define in your blog. Thanks for your useful info. Kidney Failure

by Unregistered Visitor on 02/28/15

gold ira companies

I am always searching online for articles that can help me. There is obviously a lot to know about this. I think you made some good points in Features also. gold ira companies

by Unregistered Visitor on 02/28/15

wood shoe storage bench

I found your blog using louis vuitton outlet. This is a very well written article. wood shoe storage bench

by Unregistered Visitor on 02/28/15

asd

Great stuff from you, man. Ive read your stuff before and you’re just too awesome. I love what you’ve got here, love what you’re saying and the way you say it. archive.org

by Unregistered Visitor on 02/28/15

Add comment