Asymptote is a powerful program that can be used to create professional-looking vector images, graphs, or sketches. This is a sort of newer version of the Metapost, which it closely resembles, only more direct to use. Using Asymptote (or Metapost), I created my sketches into a series of articles Alive Geometry. In the program you can draw 2D as well as 3D drawings, I'll just focus on 2D drawings.

Like LaTeX this is not a WYSIWIG program but a programming language. You draw pictures not with your mouse, but by telling the program what you want to get, and it creates it for you. The advantage of this is that you can draw accurate analytical curves such as the $y=\sqrt{x}$ graph, but also that you can recycle code you have already written, or use for loops to create advanced shapes and save time.

The aim of this guide is to give a very brief account of how the program is installed and how it can be used to draw basic objects and functions. If you're interested in the program, you can read more about its features in the manual or read the longer English tutorial.

## Installation

Let's start with the hardest part - installing a program and writing a Hello World program. If you want to just try the program without installing, then you can try the online environment for Asymptote. To make pictures, we will need the following three things:

• An Asymptote program that creates images from our source code.
• A TeXmaker program to write source code with.
• The GhostScript program, so we can use the pdf format.

Asymptote has no graphical interface in the base. You install it and it stays in the background on your PC. When you need it, you'll call it, and it will create a picture, following your commands. Instead, we need a Texmaker to write these commands. It's going to be our graphical interface in which we write our picture, and then we look at it. The GhostScript program, it's just a kind of dependency that helps Asymptote work with pdf files.

### Technical details

In the installation I calculate that you are using the Windows 10 operating system, and that you have about 1GB of free disk space.

If you are using Linux, you can replace the installation steps with a single line to the terminal. For Ubuntu:

For Arch Linux:

## First Image

Create a folder on your computer and a file named *hw.asy. Open this file in Texmaker. Type the following in the window:

The first line tells us that we want to use the pdf format. This format is useful for letting you view the result in Texmaker. However, you can change it to, for example, png (but this will lose its vectors) or svg or eps. You may find that some things (like hatching) break for the svg format, so I recommend using pdf or eps. After all, it can easily insert itself into a .tex document. Next, change the compiler to the Asymptote program as shown in the image next to the button with the arrow on top. Now when you click or press F1 on the arrow, the file will be compiled (translated) and you will see the result on the right side. Using the command draw(unitsquare); we drew a square with an edge of one centimetre, and this is actually shown on the right side. The background of our image is white by default, so black four lines at the edge have been drawn. The image was then cut to the smallest possible size.

## Syntax Description

The asymptote language is similar to C or C++, e.g. comments are written identically using //. If you know their syntax, just skim the following section.

### Variables

As in any language, we can set variables that have different data types, depending on what they represent (and how much space they take). Here is a brief overview:

• Integer that tags int
• Decimal real number real
• Point coordinates (real number pairs) pair
• Curve path
• Text String string
• Array, or set of variables. Writing with []

Variables are good to declare first by writing the type of variable and its name. For example, if we write

so we introduced an integer variable called sensation. A semicolon must be typed at the end of each command, otherwise Texmaker will throw up followed by an error message. Variables can be given a value for example as follows:

At the end of these lines, both and will equal 3 and j will equal 12. We've also defined multiple variables of the same type at once. You can also work with text strings:

At the end of this example, and will contain the text string 1234.

It is worth noting that some variables are so-called system variables and change some parameters of the program. For example, the variable settings.outformat, which we met earlier, changes what output format we will have.

### Features

Functions are small programs within a program that we can define and then call to do some work for us. Typically still returns the output value. For example, we can define a function as follows:

This code says that the f takes one real parameter x and also returns a real parameter. We can call it as follows:

Then the variable y will be equal to 4.2. There are still functions that do not return the parameter. We just call them, and they do something (like draw a line).

### For cycle

Another important thing will be the so-called for cycle. With it, we can do many things at once. For example:

This cycle will execute an internal code for both and equal to zero, one and two, so eventually feeling will be equal to three.

## Drawing lines

Lines are drawn using the draw(path p). But first we need to know what the curve path and the point pair looks like. We can define a point by simply giving its coordinates (first $x$ coordinate, then $y$). However, it is useful to say in advance what units we work in (e.g. in centimetres). In total, we may have, for example, such a code:

This will draw two dots at two different coordinates. We can define a curve as a path through some points, then we can draw it using the draw. It also depends on whether we want to connect the points directly or in a twist (using a B\u00e9zier curve). Direct link is done by -- and twisted link by .., as you can see in the following example;

Try what picture you get. The top is straight, while the bottom is seamlessly connected. By commanding cycle we go back to the beginning cyclically.

If you had written an extra fill(p1); in the previous one, the first curve would have been filled with black. The fill color can be changed (see manual p. 16).

### Labelling

You can still insert text into the image using the label( string name,pair posice). Of course name interprets LaTeX. So you just write, for example, just call the label( \$x^2$\(0.0)); and you get a nice $x^2$ in the beginning.

### Example

An example of all things shown is this code, which produces a numbered axis, you can extend it at any time: ## Drawing Charts

You can also load so-called modules (or libraries, packages) into the asymptote, which are extensions of program features written by someone else. One such package is called graph and allows us to draw graphs of functions.

Here we have determined the curve g using the graph function. For more on features and how to make them more subtle, see the listed tutorial on p. 28th.

## Summary

In Asymptote, you can draw advanced pictures in the way I outlined above. I hope you now have a framework understanding of how to draw such pictures. Explaining multiple functions, such as drawing geometric shapes or transforming, would already make this text too long and would be pointless in the first place: the necessary information can be found simply on the Internet or in the referenced tutorial and manual.

If you found the instructions useful, check out the other Instructions or some of my articles. I can recommend, for example. Reviving geometry, a simple introduction to differential calculus.