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.

Thanks.

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.
However,

  • 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
}

@sebas-a, where you able to find a way to do this? I am also wanting to be able to use LaTeX interpreter as for the label of my nodes; essentially to display equations.

Can’t speak to doing this in Python, but here are some LaTex images that I picked up here & there and incorporated into nodes with the image attribute (image | Graphviz):

digraph G {
 graph [rankdir=LR]
 node [shape=none label=""]
 node [imagescale=true]
 n1  [ image="image_dir/LaTeX-arrow.png" ]
 n2  [ image="image_dir/longeqns2.png" ]
 n3  [ image="image_dir/Eggequation.jpg" ]
 n4  [ shape=rect image="image_dir/LaTeX-arrow.png" ]
 n5  [ shape=circle image="image_dir/main-qimg.png"]
 n6  [ shape=rect image="image_dir/LaTeX-arrow.png" ]

 n1 -> { n2 n3}
 n2-> n4 -> n5 -> n6

subgraph clusterX {
 node [imagescale=true]
 J1  [ image="image_dir/LaTeX-arrow.png" ]
 J2  [ shape=rect image="image_dir/longeqns2.png" ]
 J4  [ image="image_dir/LaTeX-arrow.png" ]
 J5  [ shape=rect image="image_dir/main-qimg.png"]
 J6  [ shape=circle image="image_dir/LaTeX-arrow.png" ]
}
 J1 -> J2
 J1-> J6 -> J5 -> J4
}

Giving: