I want to create something like in object, that saves it's own location in latex. Because I don't know how to create a objec in latex, I want to create a length with seperating name for each object. Like that: (Dont worry \umlPositionX and \umlPositionY is defined before)


Now I want to get the position of the object like that:


But it is not possible, to create a length with dynamic name like that. I always get the error:

Command \umlPositionX already defined.

I think it is because the #1 does not belong to the name of the length.


1 Answer 1


To patch a macro together in the way you seem to want one can use \csname ...\endcsname.

    \edef\temp{\noexpand\newlength{\csname umlPositionX#1\endcsname}%
     \noexpand\setlength{\csname umlPositionX#1\endcsname}{\umlPositionX}%
     \noexpand\newlength{\csname umlPositionY#1\endcsname}%
     \noexpand\setlength{\csname umlPositionY#1\endcsname}{\umlPositionY}}%
\umlClass{A}\the\umlPositionXA \the\umlPositionYA

enter image description here

  • Thank you marmot. That is what I was searching for. But how to acces the value dynamicly like I tried to explain with the seccond source example.
    – NelDav
    Apr 27, 2019 at 22:23
  • Never mind. I typed the \csname wrong. Because of that it didn't worked. For every else you have only to type \csname umlPosition#1\endcsname (without \noexpand), if you want to acces the value dynamicly.
    – NelDav
    Apr 27, 2019 at 22:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .