Macro reference

Marginalia understands the macros of SillyTavern, so prompts and world info written for SillyTavern work without changes. Macros work in every template: master template, user prompt, summary prompt and lorebook entries.

Syntax

Form Example
without arguments {{user}}
arguments separated by :: {{setvar::mood::nervous}}
first argument after a space {{getvar mood}}, {{setvar greeting::Hello}}
legacy single : {{getvar:mood}}, {{random:north,south}}
nested macros {{getvar::{{user}}_mood}}
scoped (content as the last argument) {{setvar backstory}}Long text...{{/setvar}}
  • Macro names are case-insensitive: {{User}} and {{USER}} work.
  • Spaces around names and arguments are ignored: {{ getvar :: mood }}.
  • Extra :: go into the last argument: {{setvar::x::a::b}} sets x to a::b.
  • Scoped content is evaluated first, then dedented and trimmed. With # after the braces, {{#setvar name}}...{{/setvar}}, the whitespace is kept exactly.

Names and participants

Marginalia has no personas or character cards; the names come from the turn instructions of the part being written.

Macro Result
{{user}} The POV character.
{{char}} The POV character. Alias {{charIfNotGroup}}.
{{group}} The present characters, or the POV character when none are given. Alias {{groupNotMuted}}.
{{notChar}} The present characters except the POV character (comma or line separated, joined with , ).
{{description}} The book's description.
{{scenario}} The scene setting.
{{input}} The instructions for the part.

The SillyTavern markers <USER>, <BOT>, <CHAR>, <GROUP> and <CHARIFNOTGROUP> (any case) work as well.

With POV character Alice and present characters Alice, Bob, Carol: {{user}} → Alice, {{group}} → Alice, Bob, Carol, {{notChar}} → Bob, Carol.

Story history

Macro Result
{{lastMessage}} The text of the last part of the active branch. Alias {{lastCharMessage}}.
{{lastMessageId}} The position of the last part, counted from 0.
{{lastUserMessage}} The instructions of the last part.
{{summary}} The newest summary of the active branch.
{{closest-message}}, {{closest-message::n}} The part closest to the one being written: the last one, or the n-th counted back from it (::2 is the one before the last). Empty when there is no such part. Alias {{closestMessage}}.
{{closest-summary}}, {{closest-summary::n}} The same for the summaries of the branch: the newest one, or the n-th counted back. Alias {{closestSummary}}.
{{current-message}} The text of the part that Regenerate or a swipe replaces; empty for a new part. Alias {{currentMessage}}.

For the first part of a book they are empty. For Regenerate, "last part" is the one before the regenerated part.

The number of closest-message and closest-summary can be a macro, so it can come from a variable: {{setvar::back::3}}{{closest-message::{{getvar::back}}}} is the third part from the end. A number that is not a positive whole number gives nothing. closest-summary counts the summaries of the parts of the branch, a meta summary and the summaries it stands in for included; {{summary}} is the same as {{closest-summary}}.

Date and time

Macro Example result
{{time}} 2:30 PM
{{time::UTC+2}} 4:30 PM - the time at a UTC offset (UTC-5:30 works too)
{{date}} March 15, 2026
{{weekday}} Sunday
{{isodate}} 2026-03-15
{{isotime}} 14:30
{{datetimeformat::YYYY-MM-DD HH:mm}} 2026-03-15 14:30 - moment.js format tokens, text in [brackets] is printed as it is: {{datetimeformat::dddd [the] D. MMMM}} → Sunday the 15. March
{{idleDuration}} 2 hours - time since the last part was written, just now for the first part. Alias {{idle_duration}}.
{{timeDiff::2026-01-01 12:00::2026-01-01 10:00}} in 2 hours - the difference between two times; now, dates (2026-01-08) and ISO times work. Unknown values give nothing.

Times are in the time zone of the computer or server Marginalia runs on, and always in English. For the Docker version, set the time zone with the TZ environment variable, e.g. TZ=Europe/Prague.

Variables

Variables store values between parts: counters, a character's mood, things the story has established. There are two kinds:

  • local variables belong to the story branch: each part remembers their values, and a new part starts with the values of the part before it;

  • global variables belong to the book, shared by all branches.

See What is kept between parts.

Local Global  
{{getvar::name}} {{getglobalvar::name}} The value; empty when not set.
{{setvar::name::value}} {{setglobalvar::name::value}} Sets the value. Prints nothing.
{{addvar::name::value}} {{addglobalvar::name::value}} Adds a number, or appends text when either isn't a number. Prints nothing.
{{incvar::name}} {{incglobalvar::name}} Adds 1 and prints the new value. A value that isn't a number starts from 0.
{{decvar::name}} {{decglobalvar::name}} Subtracts 1 and prints the new value.
{{hasvar::name}} {{hasglobalvar::name}} true or false.
{{deletevar::name}} {{deleteglobalvar::name}} Removes the variable. Alias flushvar / flushglobalvar.

Numbers are printed without trailing zeros: 1.50 plus 1.5 is 3.

{{setvar::hp::10}}{{addvar::hp::5}}HP: {{getvar::hp}}      → HP: 15
{{setvar::items::a rope}}{{addvar::items::, a lamp}}{{getvar::items}}   → a rope, a lamp

Shorthands

{{.name}} is a local variable, {{$name}} a global one. On its own, a shorthand prints the value. With an operator:

Shorthand Effect Prints
{{.hp = 20}} sets the value nothing
{{.hp += 5}}, {{.hp -= 5}} adds / subtracts (+= appends text to text) nothing
{{.turn++}}, {{.turn--}} adds / subtracts 1 the new value
{{.hp == 17}}, {{.hp != 17}} compares true / false
{{.hp > 10}}, >=, <, <= compares numbers (false for text) true / false

Fallbacks and defaults:

  • {{.name || Guest}} prints Guest when the variable is empty or falsy (0, false, no, off);
  • {{.name ?? Guest}} prints Guest only when the variable isn't set at all;
  • {{.title ||= Wanderer}} sets the variable to Wanderer if it is empty or falsy, then prints it;
  • {{.title ??= Wanderer}} sets it only when it isn't set at all, then prints it.

Values can contain macros: {{.log += -> {{user}}}}.

A part counter, for example, at the top of the user prompt (+= prints nothing, and {{trim}} removes the empty line it leaves):

{{.part += 1}}{{trim}}
This is part {{.part}} of the story.

Conditionals

{{if presentCharacters}}
  Present: {{presentCharacters}}
{{else}}
  {{user}} is alone.
{{/if}}

The condition can be:

Condition True when
a macro name - {{if user}} the macro gives a value
a variable - {{if .mood}}, {{if $chapter}} the variable has a value
a template variable - {{if sceneSetting}} the variable has a value
a comparison - {{if .hp > 20}} the comparison is true
any text - {{if yes}} always, except for the falsy values
negation - {{if !user}}, {{if !.mood}} the opposite

Falsy are an empty value and 0, false, no, off (any case). Everything else is true.

  • The short form {{if user::text}} prints text when the condition is true.

  • Only the branch that is taken is evaluated: a {{setvar}} in the other branch doesn't happen.

  • {{if}} blocks are dedented and trimmed like scoped macros, so they can be indented for readability. {{#if}} (the Handlebars if) keeps the whitespace.

  • A {{if}} without {{/if}} is printed as text.

Expressions

{{eval::expression}} gives true or false. Use it where a comparison is needed that {{if}} cannot do: on the values of the template (not only variables), joined with and, or and not:

{{eval::povCharacter == "Fiora" and presentCharacters has "Mara"}}
{{if {{eval::.hp < 10 or not .armed}} }}Fiora is in danger.{{/if}}
In an expression Meaning
"text", 'text' A text. A text is always in quotes: a word without quotes is a name.
12, -3.5, true, false A number or a truth value.
povCharacter, presentCharacters, sceneSetting... A value of the template, as in {{povCharacter}}. A macro without arguments works too (user, summary, lastMessage).
.mood, $chapter A local or a global variable; empty when it is not set.
( ) Grouping.

Comparisons:

Operator True when
==, != Equal, not equal. Numbers are compared by value (5 == 5.0), anything else exactly, so "Fiora" == "fiora" is false.
~= Equal, ignoring case.
<, <=, >, >= The numbers are in that order. False when a side is not a number.
contains The text on the left has the text on the right inside, ignoring case: presentCharacters contains "ma" is also true for Mara.
has The list on the left, separated by commas, semicolons or lines, has the item on the right, ignoring case and the spaces around the items: presentCharacters has "Mara" is not true for Marati.

Joining: and (&&), or (||), not (!); not binds tightest, then and, then or. A value on its own is true unless it is empty, 0, false, no or off. Macros are allowed inside a text ("{{user}}") and are rendered first.

An expression that is not valid prints Error: a syntax error, an unquoted word that is not a name (povCharacter == Fiora), an unknown name. All the names are checked, also in the part of an and / or that would not be reached, so a typo cannot hide. In a lorebook condition an Error makes the entry unused and the preview says so.

Randomness

Macro Result
{{random::red::green::blue}} One of the options, different every time. Also {{random:red,green,blue}} and {{random}}red, green{{/random}}.
{{pick::sword::axe::bow}} One of the options, but always the same one for the same book and the same place in the template. Use it for things that must stay consistent, like a randomly chosen name.
{{roll::2d6+3}} A dice roll: 1d20, 3d4-10, d100; also {{roll d100}}, {{roll:6}} (one six-sided die). Invalid rolls give nothing.

Generation info

Macro Result
{{model}} The name of the inference provider of the book.
{{maxContextTokens}} The context limit in tokens (protocol or provider, see Limits). Alias {{maxContext}}.
{{maxResponseTokens}} The response limit in tokens. Alias {{maxResponse}}.
{{maxPrompt}} Context minus response: the room for the prompt.
{{lastGenerationType}} normal for a new part, regenerate, swipe, or quiet in summaries.

Commands

Macro Result
{{command::name}}, {{command::name::argument::argument}} What a command answers, as text. Only a command that is made for macros can be used (it only reads; an extension says so, for example {{command::character-tracker-map}} of the Character Tracker); any other name prints Error. A command that fails prints nothing.

The command runs when the generation reaches the macro (not at all when it is in a branch of an {{if}} that is not taken) for the book that is generated, and only in the prompts of a generation (the user prompt, the lorebook entries and the master template), elsewhere the macro prints nothing. The answer is kept with the part the new part continues from: the next generation from the same part, and the other templates of the same generation, use it instead of running the command again. Regenerate and swipe ask the command again, and so does every new part, since it continues from a new last part.

Utility

Macro Result
{{newline}}, {{newline::2}} One or more line breaks.
{{space}}, {{space::4}} One or more spaces.
{{trim}} Removes the line breaks around it. Useful after lines that only set variables.
{{noop}} Nothing.
{{join::separator::a::b::c}} The texts after the first one joined with the first one between them, any number of them (macros included): {{join::-::{{user}}::{{scenario}}}}. Empty texts are left out, so an optional macro leaves no stray separator. The spaces around a written argument are dropped, so for a separator with spaces use a macro: {{join::{{space}}::a::b}}, {{join::{{newline}}::a::b}}.
{{reverse::text}} The text reversed.
{{// comment}} A comment, removed. {{//}} ... {{///}} comments out everything between them, macros included.
\{\{user\}\} Prints {{user}} literally.

SillyTavern-only macros

Macros that only make sense in SillyTavern chats - personas and character card fields ({{persona}}, {{personality}}, {{charPrompt}}, {{mesExamples}}...), instruct mode sequences ({{instructUserPrefix}}...), author's notes, swipe IDs, {{outlet}} and the like - are recognized and print nothing, so imported world info doesn't leak them into the prompt. {{isMobile}} and {{hasExtension}} print false.

A macro Marginalia doesn't know:

  • with arguments ({{fooBar::x}}) is printed as it is, like SillyTavern does;
  • without arguments ({{fooBar}}) is printed as Error, the same as an unknown template variable.