# LaTex formulas in python API

**URL:** <https://forum.graphviz.org/t/latex-formulas-in-python-api/1021>\
**Category:** Uncategorized\
**Created:** [February 4, 2022, 10:34am UTC](https://forum.graphviz.org/t/latex-formulas-in-python-api/1021 "2022-02-04T10:34:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebas-a](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@sebas-a](https://forum.graphviz.org/u/sebas-a)\
**Post date:** [February 4, 2022, 10:34am UTC](https://forum.graphviz.org/t/latex-formulas-in-python-api/1021/1 "2022-02-04T10:34:14Z")

</div>

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.20.1 documentation](https://graphviz.readthedocs.io/en/stable/examples.html), but there is nothing similar to include formulas.

A minimal example is appreciated.

Thanks.

---

<div class="post-metadata">

**Author:** ![mark](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/mark/32/84_2.png) [@mark](https://forum.graphviz.org/u/mark)\
**Post date:** [February 4, 2022, 10:57am UTC](https://forum.graphviz.org/t/latex-formulas-in-python-api/1021/2 "2022-02-04T10:57:02Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sebas-a](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@sebas-a](https://forum.graphviz.org/u/sebas-a)\
**Post date:** [February 4, 2022, 12:00pm UTC](https://forum.graphviz.org/t/latex-formulas-in-python-api/1021/3 "2022-02-04T12:00:46Z")

</div>

Thanks for your reply.

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

Yes, I am using this API [Graphviz — graphviz 0.20.1 documentation](https://graphviz.readthedocs.io/en/stable/index.html), in which I can render graphs from python. However, in the given examples, there is no info about it.

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [February 4, 2022, 4:37pm UTC](https://forum.graphviz.org/t/latex-formulas-in-python-api/1021/4 "2022-02-04T16:37:38Z")

</div>

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](https://graphviz.org/docs/attrs/image/)) in your Graphviz (see below)

- You can also look into these Latex-related tools from others: [External Resources | Graphviz](https://graphviz.org/resources/#latex) - 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:

```auto
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
}

```

---

<div class="post-metadata">

**Author:** ![RubenJC](https://avatars.discourse-cdn.com/v4/letter/r/898d66/32.png) [@RubenJC](https://forum.graphviz.org/u/RubenJC)\
**Post date:** [July 29, 2022, 8:34pm UTC](https://forum.graphviz.org/t/latex-formulas-in-python-api/1021/5 "2022-07-29T20:34:21Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [July 30, 2022, 3:18am UTC](https://forum.graphviz.org/t/latex-formulas-in-python-api/1021/6 "2022-07-30T03:18:32Z")

</div>

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](https://graphviz.org/docs/attrs/image/)):

```auto
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:

 ![latexImages](https://global.discourse-cdn.com/graphviz/original/1X/a6d719067d798e36d2787bea31149cdb467861e5.jpeg)

---

<div class="post-metadata">

**Author:** ![HermannSW](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/hermannsw/32/2158_2.png) [@HermannSW](https://forum.graphviz.org/u/HermannSW)\
**Post date:** [September 3, 2026, 11:35pm UTC](https://forum.graphviz.org/t/latex-formulas-in-python-api/1021/7 "2026-09-03T23:35:21Z")

</div>

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

A bit late, but yes since today, see [Latex labels for Graphviz (work in progress)](https://forum.graphviz.org/t/latex-labels-for-graphviz-work-in-progress/3402) posting.
