2

tikz-uml's umlinherit command breaks when passing in names containing underscores, consider:

\documentclass{standalone}
\usepackage{tikz-uml}

\begin{document} \begin{tikzpicture} \umlinterface[x=-2]{a}{}{}

\umlclass[x=2]{a_impl}{}{}

\umlinherit{a_impl}{a} \end{tikzpicture} \end{document}

This fails to compile: Package pgf Error: No shape named 'a_impl' is known. It seems to me that this is clearly a bug, but I've already used tikz-uml for several diagrams in my document so I wonder if there is a workaround for this.

Peter
  • 178
  • tikz-uml is not part of a standard installation!? The only manual I can find is from 2016: https://perso.ensta-paris.fr/~kielbasi/tikzuml/var/files/doc/tikzumlmanual.pdf Under Installation, it says "Coming soon". To me it looks like a dead project. – hpekristiansen Jun 17 '21 at 15:11
  • @hpekristiansen: Yes, I'm working on an old document that already uses tikz-uml. – Peter Jun 17 '21 at 15:15

1 Answers1

3

You can set the category code of the underscore to 11 or 12 (letter/other) within the tikzpicture environment. This means you don't need to escape it. It also means that you cannot use _ for math subscript anymore, you can use \sb{} instead. Moreover it means that you need to use T1 font encoding otherwise LaTeX does not know how to map _ to an actual underscore character. Finally it is advised to choose a different font, because Computer Modern has a very low underscore (visibly below the baseline), and Latin Modern has a very wide underscore. In the MWE below I used Palatino.

If you set the catcode within the environment then the change is local so you can use the underscore as normal in the rest of your document.

MWE:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{palatino}
\usepackage{tikz-uml}

\begin{document} \begin{tikzpicture} \catcode`_=12 \umlinterface[x=-2]{a}{}{}

\umlclass[x=2]{a_impl}{$a\sb{1\dots n}$}{}

\umlinherit{a_impl}{a} \end{tikzpicture} \end{document}

Result:

enter image description here

Sources: How to use arbitrary text as node name in tikz graph in a simple way?

Is it safe to set underscore to a non-active character?

Decrease length of underscore character in normal text (gender_gap)

Marijn
  • 37,699
  • Amazing! Works perfectly. – Peter Jun 18 '21 at 07:56
  • this doesn't seem to work anymore. however, because tikz-uml has to be locally installed by the user, an alternative approach is to add lang-tex\detokenize{} applications to the defines for lang-tex \tikzumlClassName, lang-tex \tikzumlClassAttributes, and lang-tex \tikzumlClassOperations; possibly others, these were the ones in use for what i need to work again. – regnirpsj Apr 02 '23 at 23:11
  • @regnirpsj I just tried to compile it again with TeX Live 2022 and that still works, maybe in TL 2023 it broke? I will check again when I have access to that version (if I remember). – Marijn Apr 03 '23 at 09:20
  • with TeX Live 2022/CVE-2023-32700 under fedora 38 the detokenize approach doesn't anymore as well. i guess there's no useable uml support for TeX these days – regnirpsj Aug 24 '23 at 21:11
  • @regnirpsj I just tried my code above with TeX Live 2023 and that also works - so I'm guessing there is a problem with the way you use the code or with your installation (maybe a different tikz-uml version?) – Marijn Aug 25 '23 at 08:42