# Workshop

Generating Output

## Introduction

In real life, most of the time, output commands are applied to write out the content of variables. But variables are still one session away, so we'll start practicing with literal numbers and strings. After that, it is easy to extend your dewy new output skills to variables, as you'll see in the next session.

## Preparation

Start Praat and open a new Praat script.

## Exercise

First, acquaint yourself with the output commands. There is no help from command history, you have to write the code yourself. These are the relevant commands:

```
writeInfo:
writeInfoLine:
appendInfo:
appendInfoLine:
```

Play around with the commands, add some arguments (strings with double quotes, numbers without, separated by comma), and see what happens.

Now, try to accomplish the following output:

Line1 Word1 Word2

Line2 Word3 Word4 Word5 Word6

using this sequence of commands:

```
writeInfo:
appendInfo:
appendInfoLine:
appendInfo:
appendInfo:
```

Easy? So, try to meet this special requirement: The last statement has 3 arguments, one of which is numerical.

Next, experiment with tabbed output. Take any output command, add some arguments and throw in a few *tab$*-items. Change font size (Font-menu in Praat Info) and see what happens to the column alignment.

When you're ready, set font size to 14 and produce the following output. Don't use spaces!

a b c 1 2 3 10 20 30 100 200 300 1000 2000 3000

If you play around and try this with larger numbers, you'll see that it's not really feasible to assemble neat tables with the help of `tab$`

. Rather, `tab$`

is intended to generate lists of tab separated values, which could be used e.g. as input for spreadsheets.

Now, we are going to exploit that output commands write out the result if they are fed with a formula:

```
writeInfo: 2 + 4
```

writes *6* to Praat Info. Most of the time, as you will see, results of formulas in scripts are assigned to variables, but passing them directly to Praat Info is a simple and effective way to acquaint yourself with operators, operator precedence and other aspects of formulas.

The basic arithmetic operators for formulas are **+** (addition)**-** (subtraction)***** (multiplication)**/** (division)

```
writeInfoLine: "basic arithmetics:"
appendInfoLine: 9+3
appendInfoLine: 9-3
appendInfoLine: 9*3
appendInfoLine: 9/3
```

When you run this script you get:

basic arithmetics:

12

6

27

3

If no parentheses are used, multiplication and division are calculated before addition and subtraction and formulas are calculated from left to right. Look at the following script—don't run it ;-) What results do you expect?

```
writeInfoLine: "operator precedence and parentheses:"
appendInfoLine: 2+1*9
appendInfoLine: (2+1)*9
appendInfoLine: 2-1+4
appendInfoLine: 2-(1+4)
```

To learn more about operators and formulas, read the Praat tutorial on operators and put together formulas as complex as you like to become familiar with script controlled arithmetics.

To conclude this workshop, let's test *newline$*. Try to accomplish the following output with one line of code:

Multiplication

2 * 8 = 16

Division

16 / 2 = 8

Make sure that the results (*16* and *8*) are calculated by Praat!