Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

graphviz

dot

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]
like image 905
maths-help-seeker Avatar asked Mar 13 '12 13:03

maths-help-seeker


People also ask

How will you add mathematical expression in a document?

In Word, you can insert mathematical symbols into equations or text by using the equation tools. On the Insert tab, in the Symbols group, click the arrow under Equation, and then click Insert New Equation. Under Equation Tools, on the Design tab, in the Symbols group, click the More arrow.


2 Answers

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

like image 88
dgw Avatar answered Sep 28 '22 04:09

dgw


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

  • https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts
  • https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode

Tested on Ubuntu 16.10, graphviz 2.38.