LaTex formulas in python API

Dear Graphviz community,

Is there a way to include latex formulas as labels in the Python API of Graphviz?

I have looked at the examples: Examples — graphviz 0.19.1 documentation, but there is nothing similar to include formulas.

A minimal example is appreciated.


I’m a little unsure what you’re asking. Are you trying to render some mathematical formula, into the labels(?) of a graphviz diagram, using the LaTeX language for writing formulae? There are some systems that can do things like that for PDF that academics use I think. Are you trying to make, like, a PDF for an academic paper?

Thanks for your reply.

Are you trying to render some mathematical formula into the labels(?)

Yes, I am using this API Graphviz — graphviz 0.19.1 documentation, in which I can render graphs from python. However, in the given examples, there is no info about it.

Unfortunately, Graphviz does not directly take Latex as input nor does it produce Latex as output.

  • You can produce a non-Latex output (SVG)
    • by using Latex, TikZ or similar to create the individual nodes separately
    • producing those individual images as SVG
    • and using the image attribute (image | Graphviz) in your Graphviz (see below)
  • You can also look into these Latex-related tools from others: Resources | Graphviz - especially if you need Latex or TikZ as your output format

Here is a non-python Graphviz program that uses SVG icons as node contents using the image attribute:

digraph G {
 graph [rankdir=LR]
 node [shape=none label=""]
 n1  [ image="image_dir/Router.svg" ]
 n2  [ image="image_dir/Router.svg" ]
 n4  [ image="image_dir/Face-smile.svg" ]
 n5  [ image="image_dir/a.svg"]
 n6  [ image="image_dir/a.svg" ]

 n1 -> n2 -> n4 -> n5 -> n6