Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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
add comment

2 Answers

up vote 3 down vote accepted

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.

share|improve this answer
    
You proabably mean \newlength –  mrf Jun 11 '12 at 12:29
    
@mrf: Indeed ;-) –  Marco Daniel Jun 11 '12 at 12:36
add comment

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.