# Labeling within Loops in Asymptote

I'm fairly new to Asymptote, and am trying to create a basic number line using a for loop. I would like the for loop to also label the points for me. Could somebody tell me how to fix this?

\documentclass{article}

\begin{document}

\begin{figure}[hbt]
\centering
\begin{asy}
unitsize(0.1inch);

draw((0,0)--(50,0),);
draw((0,0)--(1,1));
draw((0,0)--(1,-1));
draw((50,0)--(49,1));
draw((50,0)--(49,-1));

draw((25,1)--(25,-1));
label("$0$",(25,0)+2*dir(270));

for(int i=1; i<12; ++i)
{
draw((25+2*i,1)--(25+2*i,-1));
label("$i$",(25+2*i,0)+2*dir(270));
}

\end{asy}
\end{figure}

\end{document}


When run, almost everything displays the way I would expect it to, except instead of labeling the numbers, it labels everything with my counter variable.

Also, earlier my system was working fine, but now it's stopped creating the .pdf files for the images. For example, my first image is supposed to be Neighborhoods-1.pdf. It creates the .asy file, but not the .pdf file. Can somebody tell me how to fix this?

• Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Adam Liter Jan 16 '14 at 18:06

The command label("$i$",(25+2*i,0)+2*dir(270)); indeed typeset a name of the counter in math mode $i$ for every tick. To typeset values of i, use "$"+string(i)+"$" as a label:

\documentclass{article}
\usepackage[inline]{asymptote}
\begin{document}
\begin{figure}[hbt]
\centering
\begin{asy}
unitsize(0.1inch);
draw((0,0)--(50,0));
draw((0,0)--(1,1));
draw((0,0)--(1,-1));
draw((50,0)--(49,1));
draw((50,0)--(49,-1));

draw((25,1)--(25,-1));
label("$0$",(25,0)+2*dir(270));

for(int i=1; i<12; ++i){
draw((25+2*i,1)--(25+2*i,-1));
label("$"+string(i)+"$",(25+2*i,0)+2*dir(270));
}

\end{asy}
\end{figure}
\end{document}


• Thank you! g.kov, do you know how to fix the other problem I listed? – Higgie2718 Jan 16 '14 at 18:46
• @Higgie2718: Usually, missing .pdf files mean that there are errors in the asy code (there is a typo in the MWE). I suggest to prepare your images as a compilable standalone .asy files first and then include them in the .tex document. Also, if you really need to use inline asy code, it is better to have come kind of a clear command, which deletes all the intermediate files, created by tex and asy. – g.kov Jan 16 '14 at 19:02
• Thank you for all of your help! Edit: I feel really, really stupid. I had a misplaced comma. :/ – Higgie2718 Jan 16 '14 at 19:25