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 write an fp macro that calculates the distance between frets on a guitar neck:

\def\ScaleLength{25.5}
\def\ScaleFactor{0.1}

\def\FretDist#1{\FPmul\resulta{-1}{#1}%
\FPdiv\resulta{\resulta}{12}%
\FPpow\resulta{2}{\resulta}%
\FPsub\resulta{1}{\resulta}%
\FPmul\resulta{25.5}{\resulta}
\FPmul\resulta{\resulta}{\ScaleFactor}
\resulta
}

And putting things like

\FretDist{3}

In latex gives the proper floating point value.

When I try to use that value in a package like

\put(3,\FretDist{3}){\circle{3}}

I get an error "Missing number, treated as zero", yet if I do

\put(3,3){\circle{3}}

works fine

share|improve this question
1  
Please consider assembling your code snippets in a "Minimum Working Example" (MWE) of LaTeX code. –  Mico Mar 15 '12 at 23:09
add comment

1 Answer

up vote 3 down vote accepted

You can't use \FretDist{3} as argument to \put, because this commands expects a number and not a whole set of instructions to print it. Change the definition of \FretDist as follows

\def\FretDist#1{\FPmul\resulta{-1}{#1}%
\FPdiv\resulta{\resulta}{12}%
\FPpow\resulta{2}{\resulta}%
\FPsub\resulta{1}{\resulta}%
\FPmul\resulta{25.5}{\resulta}
\FPmul\resulta{\resulta}{\ScaleFactor}
}

so that, after calling it, you'll have \resulta available for usage as a number:

\FretDist{3} % store the number in \resulta
\put(3,\resulta){\circle{3}}
share|improve this answer
    
This works but takes more work when you are looping over a variable. Counters and dimensions cannot be used as arguments for fretdist so I had to use one of fp's registers which means I had to add code to treat it like a counter. –  Uiy Mar 15 '12 at 23:23
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.