TransWikia.com

How to specify RGB color for xelatex/graphviz combo

TeX - LaTeX Asked by mi laborans on October 5, 2021

Xelatex, while processing graphviz code doubles the hashmark (#) char before the RGB color specification.

E.g. latex/graphviz code:

digraph [scale=1]{mygraph} {
  node [color="#365559"]
  a->b
}

Resulting mygraph.dot:

digraph mygraph {
  node [color="##365559"]
  a->b
}

How do I overcome this {bug/feature}, without touching the shell (e.g. sed)?

One Answer

In the graphviz package a macro is defined that has three arguments: the graph options, the name of the graph file and the contents. Within that macro the content of those arguments is written to a .dot file using the write command.

LaTeX tries to avoid that the # character inside the contents of a macro argument is seen as an argument itself, therefore the character is doubled. It would be a bit more intuitive in the current use case if the # was treated verbatim instead. However, you can define it as verbatim yourself with the newverbs package (similar to https://tex.stackexchange.com/a/37757) and use that macro in the code for the graph.

MWE:

documentclass{article}
usepackage{newverbs}
usepackage{graphviz}
begin{document}
Verbdefmyhash{#}
digraph [scale=1]{mygraph} {
  node [color="myhash FF0000"]
  a->b
}
end{document}

Result:

enter image description here

Correct answer by Marijn on October 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP