mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-08 10:59:57 +00:00
36 lines
1.3 KiB
Plaintext
36 lines
1.3 KiB
Plaintext
created: 20220917112233317
|
|
modified: 20221019081352266
|
|
tags: Pragmas
|
|
title: Pragma: \define
|
|
type: text/vnd.tiddlywiki
|
|
|
|
The ''\define'' [[pragma|Pragmas]] is used to [[define macros|Macro Definitions]]. 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>]...)
|
|
<multiple-line-definition-text>
|
|
\end
|
|
```
|
|
|
|
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:
|
|
|
|
For example:
|
|
|
|
<$codeblock code={{$:/editions/tw5.com/macro-examples/say-hi}}/>
|
|
|
|
Alternatively, the entire definition can be presented on a single line without an `\end` marker:
|
|
|
|
```
|
|
\define sayhi(name:"Bugs Bunny") Hi, I'm $name$.
|
|
```
|
|
|
|
A more formal [[presentation|Macro Definition Syntax]] of this syntax is also available.
|