Control

How to define control conditions

Mau provides ways to render document nodes conditionally. The syntax of control conditions is @if CONDITION, where CONDITION is always in the form VARIABLE==VALUE or VARIABLE!=VALUE.

Mau source code
:answer:42

@if answer==42

The condition above will influence this paragraph

How to use control conditions

Control conditions behave like labels and arguments, and are attached to the next document node. They decide if the node is saved in the AST or not. If the condition is true, the node is saved as usual, while if the condition is false the node is still created but not saved.

Mau source code
:answer:42

@if answer==42
This paragraph will be rendered.

@if answer!=42
This paragraph will not be rendered.

This paragraph will be rendered.

Condition syntax

The amount of spaces before the condition and around == or != is irrelevant.

Mau source code
:answer:42

@if answer==42
This paragraph will be rendered.

@if answer == 42
This paragraph will be rendered.

@if   answer   ==   42
This paragraph will be rendered.

This paragraph will be rendered.

This paragraph will be rendered.

This paragraph will be rendered.

Control, labels and attachments

As mentioned before, control conditions do not prevent the node from being created. They can only prevent it from being added to the AST.

This means that whether the attached condition is true or false, nodes must always be valid and labels and arguments will be attached to them.

Mau source code
:answer:42

. Some title
@if answer!=42
This paragraph will not be rendered.

This paragraph will NOT receive the title "Some title".

This paragraph will NOT receive the title "Some title".

Control text nodes

Mau provides a way to conditionally render pieces of text (e.g. in paragraphs) through the two control macros if and ifeval.

The macro if is very similar to the control node seen above. The full syntax of the macro is [if:CONDITION](TRUE_CASE, FALSE_CASE), and it will return the value of TRUE_CASE if the CONDITION is true, else the value of FALSE_CASE.

Mau source code
:answer:42

This paragraph will contain [if:answer==42]("the answer", "random words").

This paragraph will contain the answer.

Macro conditions

As for the control node @if, the macros support both conditions: == and !=.

Mau source code
:+var:

The option is [if:var!=true]("disabled", "enabled").

The option is enabled.

Conditional evaluation

The macro ifeval has the same syntax [ifeval:CONDITION](TRUE_CASE, FALSE_CASE) but doesn't output the value of its true and false cases. Rather, it uses the result as the name of a variable, and return its value.

Mau source code
:language:en
:title_en: The Neverending Story
:title_de: Die Unendliche Geschichte

The title is: [ifeval:language==en](title_en, title_de)

The title is: The Neverending Story

Default values

For both if and ifeval the true case is mandatory, while the false case defaults to an empty value. In both cases, this means that no text will be inserted.

Mau source code
:answer:42
:remark:The universe is big!

This is a sentence. [if:answer==100]("This is another sentence.")

Earth is small. [if:answer==100](remark)

This is a sentence.

Earth is small.

Lazy evaluation

The macro ifeval looks up variables only when they are needed. This means that if the test is successful the negative case might safely mention a variable that does not exist.

Mau source code
:answer:42
:remark:The universe is big!

Earth is small. [ifeval:answer==42](remark, doesnotexist)

Earth is small. The universe is big!

Mau syntax in variables

Both the macro if and ifeval inject the resulting text and then Mau renders it. This means that if the true/false cases of if or the values of the variables for ifeval contain Mau syntax, this will be properly rendered.

Mau source code
:answer:42
:remark:The _universe_ is *big*!

Such [if:answer==42]("a *beautiful* day!")

Earth is small. [ifeval:answer==42](remark)

Such a beautiful day!

Earth is small. The universe is big!