Variables

How to declare a variable

Mau supports variables that can be created and assigned a value in three ways: inline, in the configuration file or on the command line. In this chapter we will see how to define and use them inline. The chapter about configuration and the chapter about the command line interface will provide information about the other ways to declare them.

Variables can be declared with the syntax :NAME:VALUE. Variable names can contain upper- and lowercase letters, numbers, and the symbols ._+- (dot, underscore, plus, and minus).

The value of a variable is always interpreted as a string, even if it's entirely made of digits.

Mau source code
:var:42
:var_1:42

How to use a variable

Variables can be used in paragraphs and in other locations wrapping their {NAME} between curly braces

Mau source code
:var:42

Value: {var}

Value: 42

Namespaced variables

Variable names can also contain dots. Internally, this creates a namespace, which is useful in some advanced configurations.

Mau source code
:namespace.var:42

Value: {namespace.var}

Value: 42

Booleans

There are no boolean types in Mau. A variable can be given the values true or false, but those are pure strings.

However, Mau provides a shortcut to generate those values. Variables with a name that starts with + are given the value true. If the name starts with - the value is false.

Mau source code
:+a_true_value:
:-a_false_value:

These variables are {a_true_value} and {a_false_value}.

These variables are true and false.

Booleans and explicit value

If specified, the value of boolean variables is ignored.

Mau source code
:+a_true_value:42

The value is {a_true_value}.

The value is true.

Verbatim and varibles

The verbatim style (backticks) suppresses variable substitution. This is done as curly braces are widely used in programming languages, and since verbatim is mainly used to highlight code inside text, it seems only natural to disable the feature completely.

Mau source code
:answer:42

The answer is {answer} but not in verbatim: `{answer}`.

The answer is 42 but not in verbatim: {answer}.

Escape variables substitution

A single curly brace { or } can be included in the text without any specific escapes. However, Mau will interpret any text included between the opening and closing bracket as the name of a variable. There are two ways to escape variable substitution: double curly braces and backslash escapes.

Double curly braces

The syntax {{name}} inserts the text {name}. This can be useful whenever the output of Mau needs to be parsed by another system that uses variables. For example, Pelican uses the syntax {filename}name_of_the_file to automatically generate a link to another file. The correct way to create such a link in Mau is therefore with the syntax [link]("{{filename}}name_of_the_file").

Backslash escapes

You can escape braces with a backslash \{ or \}. As Mau tries to match an opening bracket with a closing one, you just need to escape one of them: \{name} or {this\}.