Asymptote: Labeling

Asymptote (Vector Graphics Language)
Getting Started - Basics - Drawing - Labeling - Filling - Useful functions - Examples - Macros and Packages

Help - Reference - Advanced Asymptote - 3D Graphics - CSE5 Package - How to

Let's say you have a point that you want to label, for example, Point A.

This is extremely simple. First, draw a dot.

dot((0,0));

[asy] dot((0,0)); [/asy]

Now we use the label command.

dot((0,0));
label("A",(0,0));

[asy] dot((0,0)); label("A",(0,0)); [/asy]

However, it is likely that this is not what you want your point to look like. We now fix an attribute to this label:

dot((0,0));
label("A",(0,0),S);

[asy] dot((0,0)); label("A",(0,0),S); [/asy]

The location of the label could also be changed.

dot((0,0));
label("A",(0,0),N);

[asy] dot((0,0)); label("A",(0,0),N); [/asy]

In fact, you can use North, West, East, South, Northwest (NW), Southeast (SE), etc etc.

Now, lets get fancy with labeling. Let's say we want to label a length. In this case, we can use $\LaTeX$:

dot((0,0));
dot((1,1));
draw((0,0)--(1,1));
label("The length is $\sqrt{2}$",(0,0)--(1,1),SE);

[asy] dot((0,0)); dot((1,1)); draw((0,0)--(1,1)); label("The length is $\sqrt{2}$",(0,0)--(1,1),SE); [/asy]

Notice that I labeled a line.

Even fancier:

dot((0,0));
dot((1,1));
draw((0,0)--(1,1));
label("The length is $\sqrt{2}$",(0,0)--(1,1),SE,green);

[asy] dot((0,0)); dot((1,1)); draw((0,0)--(1,1)); label("The length is $\sqrt{2}$",(0,0)--(1,1),SE,green); [/asy]