Bi-color nodes and special characters

I’m using dot to re-create handwritten trees, and there are two little things that would make it better:

  1. Can I change the text color within a node? (Edit: Yes! with HTML-like labels.)
  2. I want to add special characters, like schwa and vowels with macrons. (I checked HTML resources, and it doesn’t look like it has encodings for those characters.) Are there codes for special characters besides the three line-breaks? And if so, do I have to choose between special characters and HTML-like labels?
1 Like

For the special characters, can you put them directly in your source file? Should “just work” if the source file is UTF8 encoded

1 Like

That would be great. I’m gonna need specifics; I’ve tried a lot of things and none of them work. What (Windows) program do I use to edit the source file and how do I make sure it’s a UTF8 format?

digraph nota {
  rankdir=LR
  { rank=same
  A [label="Entered using Notepad"]
  B [label="schwa using html encoding: Ə and ə"]

  D [label="Masron examples: Ā ē ū  ǡ Ӣ "]
x1[label="https://en.wikipedia.org/wiki/%C6%8F"]
x2[label="https://en.wikipedia.org/wiki/Macron_(diacritic)"]
  }
}

Produces this:
nonascii1

1 Like

As noted, you can use special, non-ascii characters without using HTML-like labels. You can use the UTF-8 encoding explicitly, but as some of the bytes are not ascii, this can be cumbersome depending on the text editor you use. You can avoid non-ascii characters entirely either by using the numeric representation as shown by steveroush above or. if available, a descriptive form. For example, lower-case beta can be represented as either β or β . See the Character Encoding section in the dot lang page.

Note that, by default, Graphviz assumes the input character encoding is UTF-8. The programs can usually infer if this isn’t the case and report it. Also note that for all this to work, the font used in rendering must supply the glyphs you want.

1 Like

For whatever reason, pasting characters into Notepad and saving works now. The references on this page also work: https://www.graphviz.org/doc/char.html (That page links to two pages on w3.org: the first has the same information, but the second (“an official version of this reference”) is not the same at all and not useful for GV.)

At any rate, problem solved! Thanks for all your help.

1 Like

Thanks for the feedback. I’ve removed the second link: https://gitlab.com/graphviz/graphviz.gitlab.io/-/merge_requests/182

1 Like

I wonder if we should stop documenting these entity references and encourage UTF-8 instead, now that UTF-8 is near-universal.

1 Like