Asymptote FAQ - Section 4
Questions about labels


Question 4.1. How do I get Greek letters like omega to show up in my labels?

In (La)TeX, Greek letters can be obtained in math mode by prepending a backslash to the letter name. So for a omega symbol, use "$\omega$". Everything between the dollar signs is considered to be a math formula. Uppercase Greek letters can be used by capitalizing the first letter of the name:
label("$\omega$",(0,0));
label("$\Omega$",(20,0));

Question 4.2. Can Asymptote use matrices as labels?

Yes:
usepackage("amsmath");
label("$\begin{matrix} 1 & 2 \\\ 1 & 1 \end{matrix}$",(0,0));

Question 4.3. How do I tell Asymptote to load a particular LaTeX package, like mathptmx?

Put
usepackage("mathptmx");
at the beginning of your file. Note: to enable the Adobe Times Roman font for text, you will also need to say:
defaultpen(TimesRoman());

Question 4.4. How can I use international fonts in Asymptote labels?

See https://asymptote.sourceforge.io/doc/Pens.html.

Question 4.5. How can I use Fourier fonts?

usepackage("fourier");
defaultpen(font("T1","fut\textfamilyextension","m","n"));

Question 4.6. Is there any way to change the default appearance of the decimal separator, using a comma instead of a dot?

Just set your locale appropriately:
locale("it_IT");
usepackage("icomma");
label(format(0.5));

Question 4.7. How can I get a rotated label with the filled box rotated as well so that it fits the text?

frame f;
label(f,"This is some text",white,Fill(blue));
add(rotate(65)*f);

Question 4.8. How can I rotate labels in a 3D figure?

You need to first project the triple to a pair like this:
import three;
size(100,100);

draw(rotate(90,project(Z))*"A",O--X);

Question 4.9. How can I draw some squares and circles of a fixed size and put a label in the middle of them?

Fixed-size objects should be drawn on a separate picture and then added to currentpicture. Here is one way (see also https://asymptote.sourceforge.io/gallery/subpictures.asy and https://asymptote.sourceforge.io/gallery/mosquito.asy):
real u=2cm;
 
picture square;
draw(square,scale(u)*shift(-0.5,-0.5)*unitsquare);
 
picture circle;
draw(circle,scale(0.5u)*unitcircle);
 
void add(picture pic=currentpicture, Label L, picture object, pair z) { 
add(pic,object,z);
label(pic,L,z);
} 
 
add("square",square,(0,0));
add("circle",circle,(5cm,0));

Question 4.10. The binary operator * can be used to scale the color of a pen by a real number. Does this scaling factor have to be less than 1?

The scaling factor can be greater than 1. But keep in mind that the rgb color components saturate at 1.

Try

write(cyan); write(0.8*cyan); write(1.5*cyan);
and you will quickly see what is going on.

To get a lighter cyan you can say white+cyan, which yields rgb(0.5,1,1). If you want something even lighter specify the rgb colors directly, for example, rgb(0.9,1,1).

Alternatively, work in cmyk colour space, which is nicer in that it handles saturation separately from hue:

0.1*Cyan is light and 0.9*Cyan is dark. You can also say 0.1*cmyk(red).

Question 4.11. Why is the space after the comma decimal separator in my locale so large?

LaTeX is treating the comma as punctuation and not as a decimal separator. The solution is to load the icomma package near the beginning of your file:
usepackage("icomma");

Question 4.12. How can I prevent texpreamble("\usepackage[pdftex]{hyperref}") from changing the page size?

texpreamble("\usepackage[pdftex,setpagesize=false]{hyperref}");

Next: Questions about arrows.
Back: Questions about paths.
Return to contents.

Asymptote - 2024-10-07

Extracted from Asymptote Frequently Asked Questions, Copyright © 2024 .