# Spintax by example The fastest way to understand spintax is to watch finished text become a template. So we took a real paragraph — the _About Spintax_ block from our own homepage — and reverse-authored it, one technique at a time, exactly the way the [reverse-authoring guide](https://spintax.net/docs/authoring-mindset.md) describes. Every construct below is coloured the way our editor extensions colour it; every step links to its full guide. ## The finished text Reverse authoring starts from copy you are already happy with, then adds markup last. Here is one sentence of the source — the same words you can read in the [About Spintax](https://spintax.net/what-is-spintax.md) block: > Spintax is our own template language for producing many genuinely unique variations of a text from a single source you control. Nothing below invents new wording. We only mark up _choices_ the author already had in mind. ## 1\. A vocabulary of choices Before touching a sentence, declare the reusable words once. `#set` re-rolls on every use; `#def` rolls a value once and keeps it (so a number and its noun stay in step). Edit a line here and every sentence that uses it changes. ``` #set %Unique% = {genuinely unique|truly distinct|non-repeating} #set %Engine% = {engine|spintax engine|renderer} #def %pages% = {1|3|48} ``` [Full guide: Variables →](https://spintax.net/docs/variables.md) ## 2\. Swap words and whole clauses The core operator is `{a|b|c}`. Fork the _smallest_ span that differs — a single word — or a whole opening clause, always leaving the shared tail outside the fork so grammar can never desync. ``` Spintax {(spin syntax)|— "spin syntax" —} is %OwnLang% for {producing|generating} many %Unique% variations of a text. ``` Only the parenthetical differs, so only it is forked — the shared `Spintax…is` stays outside the braces. Forking the whole `{Spintax…is|Spintax…is}` would repeat the fixed parts and invite them to drift. [Full guide: Grammar-safe synonymization →](https://spintax.net/docs/grammar-safe-spintax.md) ## 3\. Pick and reorder with permutations A permutation `[<…> a|b|c]` selects a random subset and shuffles the order — far more variety than stacking synonyms. The feature list below picks three-to-six items each render. The engine list keeps all four and only reorders them — **a permutation with no `minsize`/`maxsize` includes every item by default**, so you set sizes only when the list should vary in length. ``` It adds [ permutations|scoped variables|value-driven conditionals|plural agreement|reusable includes|post-processing]. … for [ JavaScript|PHP|Python|Object Pascal|.NET] ``` [Full guide: Permutations →](https://spintax.net/docs/permutations.md) ## 4\. Branch on a value A conditional `{?VAR?then|else}` chooses by a variable's value, not at random. Toggle one `#def` and a whole clause changes together. ``` #def %ai% = {yes|} … {?ai?Have an AI draft the template once|Write one template by hand}; the %Engine% then renders unlimited variants. ``` [Full guide: Conditional spintax →](https://spintax.net/docs/conditional-spintax.md) ## 5\. Agree with the count `{plural %n%: one|many}` picks the right noun form for a number. Because `%pages%` was a `#def`, the number and its noun always match — and a plural nests happily inside a permutation. ``` across [ %pages% {plural %pages%: page|pages}|dozens of sites|many locales] ``` Renders `1 page`, `3 pages`, `48 pages` — never "1 pages". [Full guide: Plurals →](https://spintax.net/docs/plural-spintax.md) ## 6\. Decline with cases (Russian) English gets away with one noun form; inflected languages need a different ending in each grammatical case. The move is to pick the entity **once** and make every case agree with that single pick — hold it in one `#def` and append the case ending to the stem: ``` #def %e% = {магазин|сайт|проект} … о %e%е … для %e%а … к %e%у ``` Because `#def` rolls once, the whole sentence stays on one entity — _о магазине… для магазина… к магазину_. Swap it to `#set`, which re-rolls at every reference, and the entity teleports mid-sentence — _о проекте… для магазина… к сайту_: grammatical, nonsense. That contrast is the whole reason to reach for `#def`. (The stem-plus-ending shortcut works because these three nouns decline alike; a truly irregular noun takes one `#def` per full form.) [Full guide: Grammar-safe (Russian cases) →](https://spintax.net/docs/grammar-safe-spintax.md#russian-cases) ## The whole template ``` #set %OwnLang% = {our own template language|a markup language we built|our own template syntax} #set %Unique% = {genuinely unique|truly distinct|non-repeating} #set %Source% = {a single source you control|one master you own|a single source of truth} #set %Engine% = {engine|spintax engine|renderer} #set %N% = {hundreds|thousands|millions} #def %ai% = {yes|} #def %pages% = {1|3|48}

Spintax {(spin syntax)|— "spin syntax" —} is %OwnLang% for {producing|generating} many %Unique% variations of a text from %Source%. You write one template that encodes every choice — [ alternatives|orderings|conditions|variables] — and the %Engine% expands it into %N% of %Unique% variants. {Every variation is one you defined|You define every variation}, so the output stays {on-brand and correct|accurate and on-brand} rather than a probabilistic guess.

The {modern|AI-era} workflow {pairs|combines} a {language model|large language model} with that template logic. {?ai?Have an AI draft the richly varied template once|Write one richly varied template by hand}; the %Engine% then renders {unlimited|endless} variants {locally|on your own hardware}, deterministically, and at near-zero cost.

With spintax you {roll out|publish} %Unique% content across [ %pages% {plural %pages%: page|pages}|dozens of sites|many locales] — unique by construction, not spun gibberish.

Modern spintax is far more than flat alternation. It adds [ permutations that pick and order a subset|scoped variables|value-driven conditionals|locale-aware plural agreement|reusable includes|a post-processing pass for spacing and capitalisation].

And it {runs wherever you do|works anywhere you deploy}: {independent|standalone} open-source implementations — for [ JavaScript|PHP|Python|Object Pascal|.NET] — all held to one shared corpus so a template renders identically on every one.

``` How it is coloured (the same scopes our editor extensions use): - `#set` directive (#set / #def) - `{a|b}` alternation {a|b} - `[<…>]` permutation \[<…> a|b\] - `%VAR%` variable %VAR% - `{?…}` conditional {?…} - `{plural}` plural {plural …} [Open in the playground](https://spintax.net/play/?t=I3NldCAlT3duTGFuZyUgPSB7b3VyIG93biB0ZW1wbGF0ZSBsYW5ndWFnZXxhIG1hcmt1cCBsYW5ndWFnZSB3ZSBidWlsdHxvdXIgb3duIHRlbXBsYXRlIHN5bnRheH0KI3NldCAlVW5pcXVlJSA9IHtnZW51aW5lbHkgdW5pcXVlfHRydWx5IGRpc3RpbmN0fG5vbi1yZXBlYXRpbmd9CiNzZXQgJVNvdXJjZSUgPSB7YSBzaW5nbGUgc291cmNlIHlvdSBjb250cm9sfG9uZSBtYXN0ZXIgeW91IG93bnxhIHNpbmdsZSBzb3VyY2Ugb2YgdHJ1dGh9CiNzZXQgJUVuZ2luZSUgPSB7ZW5naW5lfHNwaW50YXggZW5naW5lfHJlbmRlcmVyfQojc2V0ICVOJSA9IHtodW5kcmVkc3x0aG91c2FuZHN8bWlsbGlvbnN9CiNkZWYgJWFpJSA9IHt5ZXN8fQojZGVmICVwYWdlcyUgPSB7MXwzfDQ4fQoKPHA-U3BpbnRheCB7KHNwaW4gc3ludGF4KXzigJQgInNwaW4gc3ludGF4IiDigJR9IGlzICVPd25MYW5nJSBmb3Ige3Byb2R1Y2luZ3xnZW5lcmF0aW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opens the playground with this template loaded — hit Generate for endless live variants, or edit it. ## Get this highlighting in your editor The colours above are the grammar we ship as editor extensions — install it and your own templates light up the same way: [VS Code (301st.spintax)](https://marketplace.visualstudio.com/items?itemName=301st.spintax) or Sublime Text (Package Control: **Spintax**). ## Where to go next - [Open the playground](https://spintax.net/play/) and paste your own finished text to reverse-author. - [The authoring series](https://spintax.net/docs/authoring-mindset.md) — every technique above, in depth. - [Syntax reference](https://spintax.net/docs/syntax.md) and [nested spintax](https://spintax.net/docs/nested-spintax.md). - [Run it anywhere](https://spintax.net/spintax-engines.md) — the open-source engines, JavaScript to .NET. --- [Open in the playground](https://spintax.net/play/) [Back to all guides](https://spintax.net/docs.md) --- Source: https://spintax.net/examples/