How to insert mathematical symbols like Greek characters in a Graphviz dot file?
Asked Answered
F

2

18

I have an unique problem. I am using dot to represent a graph which is generic in nature. So, instead of using numbers, I was planning to use symbols like greek letters like alpha, beta, etc. I am curious to know how can we label nodes/edges in .dot file using some symbols?

for example,

node1 -> node2 [label= <something here which will show up as symbol of beta> style=dashed]
Fervency answered 13/3, 2012 at 13:23 Comment(0)
O
25

You can use HTML-like a labels:

digraph G {
  a [ label=<&#945;>]
  b [ label=<&#946;>]
  c [ label=<&#947;>]

  a -> b -> c
}

will show alpha -> beta -> gamma:

enter image description here

You could also used named HTML references to make it even clearer (mentioned in a comment):

label=<I love &alpha; and &beta;>

The surrounding <> indicate that the label should be parsed as a custom language that looks like an HTML subset: http://www.graphviz.org/doc/info/lang.html#html

Oppen answered 13/3, 2012 at 14:44 Comment(4)
Even cleaner: label="I love &alpha; and &beta;"Ozuna
@Ozuna I didn't knew that you could use these named variants as well. Good to know.Oppen
I get this error with HTML-like: ``` Error: not well-formed (invalid token) in line 1 ... <HTML>&##945; ... ```Nadbus
Works fine, but how can one use this inside a node record?label=<&#945;|&#946> doesn't work :((Cornelison
S
4

Unicode characters

Sometimes you can get away with Unicode https://en.wikipedia.org/wiki/Greek_alphabet#Greek_in_Unicode

graph {
    "α" -- "β"
}

Output:

enter image description here

You can also emulate some more math with Unicode, e.g.:

Tested on Ubuntu 16.10, graphviz 2.38.

Stave answered 27/12, 2016 at 13:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.