1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-30 13:29:56 +00:00

Docs: tweaks to 'Macro Definitions in WikiText'

This commit is contained in:
Jermolene 2018-08-20 17:55:32 +01:00
parent 9a2e2cd385
commit ee28f66b0a

View File

@ -1,13 +1,13 @@
caption: Macro Definitions caption: Macro Definitions
created: 20150220181617000 created: 20150220181617000
modified: 20171215152754837 modified: 20180820165115455
tags: WikiText tags: WikiText
title: Macro Definitions in WikiText title: Macro Definitions in WikiText
type: text/vnd.tiddlywiki type: text/vnd.tiddlywiki
A [[macro|Macros]] is defined using a `\define` [[pragma|Pragma]]. Like any pragma, this can only appear at the start of a tiddler. A [[macro|Macros]] is defined using a `\define` [[pragma|Pragma]]. Like any pragma, this can only appear at the start of a tiddler.
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 macro's text (i.e. the snippet represented by the macro name), until `\end` appears on a line by itself: 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:
<$codeblock code={{$:/editions/tw5.com/macro-examples/say-hi}}/> <$codeblock code={{$:/editions/tw5.com/macro-examples/say-hi}}/>
@ -20,20 +20,21 @@ Alternatively, the entire definition can be presented on a single line without a
A more formal [[presentation|Macro Definition Syntax]] of this syntax is also available. A more formal [[presentation|Macro Definition Syntax]] of this syntax is also available.
!! Accessing variables and parameters !! Accessing variables and parameters
Inside the macro there are a few methods for accessing variables and parameters defined outside of the macro or in the macro parameter list.
Inside the macro there are several methods for accessing variables defined outside of the macro or parameters from the macro parameter list.
|syntax|description|h |syntax|description|h
|`$...$`|parameter defined in the macro parameters list| |`$...$`|Text substitution of a parameter defined in the macro parameters list |
|`<<__...__>>`|parameter defined in the macro parameters list but the syntax evaluates the parameter as it is invoked| |`<<__...__>>`|Parameter-as-variable access to a parameter defined in the macro parameters list |
|`$(...)$`|variable placeholder to variable defined outside of the macro| |`$(...)$`|Text substitution of a variable defined outside of the macro |
|`<<...>>`|variable invocation of variable (or other macro) defined outside of the macro| |`<<...>>`|Access to a variable (or other macro) defined outside of the macro |
<br> <br>
!!! Placeholders `$(...)$` !!! Placeholders `$(...)$`
The macro can contain placeholders for parameters. These consist of a parameter name between dollar signs, like `$this$`. The macro can contain placeholders for parameters. These consist of a parameter name between dollar signs, like `$this$`.
It can also contain placeholders for [[variables|Variables]]. These consist of a variable name (or macro name) between dollar signs and round brackets, like `$(this)$`. The macro can also contain placeholders for [[variables|Variables]]. These consist of a variable name (or macro name) between dollar signs and round brackets, like `$(this)$`.
The actual value of the parameter or variable is substituted for the placeholder whenever the macro is called: The actual value of the parameter or variable is substituted for the placeholder whenever the macro is called: