This page is part of a static HTML representation of the TiddlyWiki at

Pragma: \define

 19th April 2023 at 10:31am

The \define pragma is used to define macros. It is a shortcut syntax for the SetVariableWidget.

The usual form allows macros to span multiple lines.

\define <macro-name>(<param-name>[:<param-default-value>],<param-name>[:<param-default-value>]...)
\end [<macro-name>]

Note that the \end marker can optionally specify the name of the macro to which it relates which allows macro definitions to be nested.

There is also a single line form for shorter macros:

\define <macro-name>(<param-name>[:<param-default-value>],<param-name>[:<param-default-value>]...) <single-line-definition-text>

The first line of the definition specifies the macro name and any parameters. Each parameter has a name and, optionally, a default value that is used if no value is supplied on a particular call to the macro.

The lines that follow contain the text of the macro text (i.e. the snippet represented by the macro name), until \end appears on a line by itself:

\define sayhi(name:"Bugs Bunny",address:"Rabbit Hole Hill")
Hi, I'm $name$ and I live in $address$.

Alternatively, the entire definition can be presented on a single line without an \end marker:

\define sayhi(name:"Bugs Bunny") Hi, I'm $name$.

Macro definitions can be nested by specifying the name of the macro in the \end marker. For example:

\define special-button(caption:"Click me")
\define actions()
<$action-sendmessage $message="tm-notify" $param="HelloThere"/>
\end actions
<$button actions=<<actions>>>
\end special-button


That renders as:

A more formal presentation of this syntax is also available.