# Using merged variablenames

I have variables in the form: dim1a, dim1b, dim1c...; dim2a, dim2b, dim2c...

I want to create a \newcommand with the dimension as argument, but constant a/b/c.

\documentclass[12pt,a4paper]{article}

\begin{document}

\newcount\lengtha \lengtha = 500
\newcount\lengthb \lengthb = 800
\newcount\speeda \speeda = 100
\newcount\speedb \speedb = 600

\newcommand{\dim}[1]{\#1a}

\divide\dim{length} by 10
\divide\dim{speed} by 10

\end{document}


I cant figure out how to transport e.g the string "\speed" to form \speeda without latex looking for the (non-existing) variable \speed.

-
LaTeX offers \@nameuse{#1a}, but as you see from the @ in the name, it's for use in packages only, or you need to say \makeatletter. –  Stephan Lehmke Jun 11 '12 at 10:40

The command \newcount is a TeX-primitive. Instead you should use the LaTeX2e command \newcounter. However the command \newcounter can only handle integer expressions. Based on your name definition I guess you want to use dimensions. So the correct command is \newlength.

If you want to compute floating points I recommend the expl3 module l3fp or the older package fp. The package pgf offers some equal material for computing.

-
You proabably mean \newlength –  mrf Jun 11 '12 at 12:29
@mrf: Indeed ;-) –  Marco Daniel Jun 11 '12 at 12:36

Stephan has already mentioned \@nameuse from the LaTeX kernel. The etoolbox package provides a user-level command \csuse to generate a control sequence token:

\documentclass[12pt,a4paper]{article}
\usepackage{etoolbox}

\begin{document}

\newcount\lengtha \lengtha = 500
\newcount\lengthb \lengthb = 800
\newcount\speeda \speeda = 100
\newcount\speedb \speedb = 600

\newcommand{\mydim}[1]{\csuse{#1a}}

\divide\mydim{length} by 10
\divide\mydim{speed} by 10

\end{document}

-