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 want to label a scale based on a variable value and I wrote a metapost code like this.

$ := 1;
for i = -.3cm step .6cm until 3.6cm:
    $ := incr($);

It just labels "$" instead of its value. How to output the variables value?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

To get the value of the variable, use the decimal macro. The following works:

for i = -.3cm step .6cm until 3.6cm:
    label.bot(decimal $,(i,-3.7cm));
    $ := incr($);

To quote the MetaPost manual:

The str operator is generally for emergency use only.


The decimal operator takes a number and returns the string representation.

share|improve this answer
add comment

Your Answer


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.