maths-help-seeker
maths-help-seeker

Reputation: 966

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

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]

Upvotes: 18

Views: 13576

Answers (2)

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.

Upvotes: 4

dgw
dgw

Reputation: 13646

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

Upvotes: 25

Related Questions