# Dynamic length name

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)

\newcommand{\umlClass}[1]{
\newlength{\umlPositionX#1}
\setlength{\umlPositionX#1}{\umlPositionX}
\newlength{\umlPositionY#1}
\setlength{\umlPositionY#1}{\umlPositionY}
}


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

\newcommand{\umlXPositionOf}[1]{\setlength{\umlPositionX}{\umlPositionX#1}
\newcommand{\umlYPositionOf}[1]{\setlength{\umlPositionY}{\umlPositionY#1}


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

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

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

\documentclass[12pt]{article}
\newlength{\umlPositionX}
\newlength{\umlPositionY}
\setlength{\umlPositionX}{1pt}
\setlength{\umlPositionY}{2pt}
\newcommand{\umlClass}[1]{%
\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}}%
\temp%
}
\begin{document}
\umlClass{A}\the\umlPositionXA \the\umlPositionYA
\end{document}


• 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. – Ahrtaler Apr 27 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. – Ahrtaler Apr 27 at 22:39