Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git
# Variables

Variables are placeholders for values that can be defined once and reused
throughout the document. When the document is built, each variable is replaced
with its corresponding value.

## File format

YAML (meaning, *YAML Ain't Markup Language*) is a plain-text format used for
storing structured data. It's commonly used in configuration files due to its
readability and simplicity. YAML files allow encoding key-value pairs within
a nested hierarchy.

Any number of variables can be defined, in any order:

``` yaml
key_1: Value 1
key_2: Value 2
```

A variable's value can reference other variables by enclosing the referenced
key in double curly braces (`{{ }}`)---also known as "moustache"
notation---wrapped in quotation marks:

``` yaml
key: Value
key_1: "{{key}} 1"
key_2: "{{key}} 2"
```

Variables can be nested to group related information:

``` yaml
document:
  title: Document Title
  author: Author Name
  isbn: 978-3-16-148410-0
```

Reference nested keys using a period, such as:

``` yaml
novel:
  author: Author Name
copyright:
  owner: "{{novel.author}}"
```

## Usage

The preview tab updates as you type. Imagine a variable file contains:

``` yaml
novel:
  title: "Diary of {{novel.author}}"
  author: "Anne Frank"
```

Then typing:

```
The novel *{{novel.title}}* is a widely read book.
```

Displays in the preview pane as:

> The novel *Diary of Anne Frank* is a widely read book.

## Autocomplete

Typing variable names is laborious. To autocomplete variable names:

1. Type in a partial variable value, such as `Dia`.
1. Press [Ctrl+Space]{.kbd} (hold down the [Control]{.kbd} key and tap [Space]{.kbd}).

The editor inserts:

```
{{novel.title}}
```

And the preview tab shows:

> Diary of Anne Frank