--- description: Typst's tutorial. --- # Writing in Typst Let's get started! Suppose you got assigned to write a technical report for university. It will contain prose, maths, headings, and figures. To get started, you create a new project on the Typst app. You'll be taken to the editor where you see two panels: A source panel where you compose your document and a preview panel where you see the rendered document.  You already have a good angle for your report in mind. So let's start by writing the introduction. Enter some text in the editor panel. You'll notice that the text immediately appears on the previewed page. ```example In this report, we will explore the various factors that influence fluid dynamics in glaciers and how they contribute to the formation and behavior of these natural structures. ``` _Throughout this tutorial, we'll show code examples like this one. Just like in the app, the first panel contains markup and the second panel shows a preview. We shrunk the page to fit the examples so you can see what's going on._ The next step is to add a heading and emphasize some text. Typst uses simple markup for the most common formatting tasks. To add a heading, enter the `=` character and to emphasize some text with italics, enclose it in `[_underscores_]`. ```example = Introduction In this report, we will explore the various factors that influence _fluid dynamics_ in glaciers and how they contribute to the formation and behavior of these natural structures. ``` That was easy! To add a new paragraph, just add a blank line in between two lines of text. If that paragraph needs a subheading, produce it by typing `==` instead of `=`. The number of `=` characters determines the nesting level of the heading. Now we want to list a few of the circumstances that influence glacier dynamics. To do that, we use a numbered list. For each item of the list, we type a `+` character at the beginning of the line. Typst will automatically number the items. ```example + The climate + The topography + The geology ``` If we wanted to add a bulleted list, we would use the `-` character instead of the `+` character. We can also nest lists: For example, we can add a sub-list to the first item of the list above by indenting it. ```example + The climate - Temperature - Precipitation + The topography + The geology ``` ## Adding images You think that your report would benefit from a figure. Let's add one. Typst supports images in the formats PNG, JPEG, GIF, and SVG. To add an image file to your project, first open the _file panel_ by clicking the box icon in the left sidebar. Here, you can see a list of all files in your project. Currently, there is only one: The main Typst file you are writing in. To upload another file, click the button with the arrow in the top-right corner. This opens the upload dialog, in which you can pick files to upload from your computer. Select an image file for your report.  We have seen before that specific symbols (called _markup_) have specific meaning in Typst. We can use `=`, `-`, `+`, and `_` to create headings, lists and emphasized text, respectively. However, having a special symbol for everything we want to insert into our document would soon become cryptic and unwieldy. For this reason, Typst reserves markup symbols only for the most common things. Everything else is inserted with _functions._ For our image to show up on the page, we use Typst's [`image`]($func/image) function. ```example #image("glacier.jpg") ``` In general, a function produces some output for a set of _arguments_. When you _call_ a function within markup, you provide the arguments and Typst inserts the result (the function's _return value_) into the document. In our case, the `image` function takes one argument: The path to the image file. To call a function, we first need to type the `#` character, immediately followed by the name of the function. Then, we enclose the arguments in parentheses. Typst recognizes many different data types within argument lists. Our file path is a short [string of text]($type/string), so we need to enclose it in double quotes. The inserted image uses the whole width of the page. To change that, pass the `width` argument to the `image` function. This is a _named_ argument and therefore specified as a `name: value` pair. If there are multiple arguments, they are separated by commas, so we first need to put a comma behind the path. ```example #image("glacier.jpg", width: 70%) ``` The `width` argument is a [relative length]($type/relative-length). In our case, we specified a percentage, determining that the image shall take up `{70%}` of the page's width. We also could have specified an absolute value like `{1cm}` or `{0.7in}`. Just like text, the image is aligned at the left side of the page by default. That looks a bit awkward. Let's center it and add a caption. We achieve this by using the [`align`]($func/align) function. This function takes an `alignment` as its first argument and then the content that we want to align as the second argument: ```example #align(center)[ #image("glacier.jpg", width: 70%) _Glaciers form an important part of the earth's climate system._ ] ``` Did you spot the closing bracket `]` at the end of the example? Both the argument and the caption are enclosed in the same square brackets. Therefore, the `align` function centers both of them. But wait, shouldn't the arguments of a function be specified within parentheses? Why is there a second set of square brackets with the aligned content after the parentheses? The answer is that, as passing content to a function is such a common thing to do in Typst, there is special syntax for it: Instead of putting the content inside of the argument list, you can write it in square brackets directly after the normal arguments, saving on punctuation. We call markup in square brackets a _content block._