---
matra:
entry: main.matra
values:
- content.js.part
---
# Compose a page with Matra packages
```main.matra
html(lang="en") {
head {
title { content.pageTitle(content.title) }
}
body {
header {
p { "MATRA / PACKAGE EXAMPLES" }
h1 { content.title }
p { content.description }
}
main {
...for (item in content.packages) {
section(id=item.id) {
h2 { item.name }
p { item.description }
pre { code { item.example } }
}
}
}
footer {
p { "These package workflows are experimental; check each package's release notes." }
}
}
}
```
```content.js.part
({
title: "Compose a page with Matra packages",
description: "Use the CLI to start a project, Core to evaluate Matra documents, and site-generation to build a site.",
pageTitle: title => `${title} | Matra`,
packages: [
{
id: "cli",
name: "@matra/cli",
description: "Create and preview a starter project with the experimental CLI.",
example: "npm install --global @matra/[email protected]\nmatra init hello\ncd hello && matra dev"
},
{
id: "core",
name: "@matra/core",
description: "Build and run a literate Matra document in Node.js.",
example: 'const value = await runLiterate(await buildLiterate(source))'
},
{
id: "site-generation",
name: "@matra/site-generation",
description: "Generate pages from Matra templates, page data, and a shared layout.",
example: 'await generateSite({ root, output: "dist", pages })'
}
]
})
```EXAMPLES
Write a document. Get HTML.
See the Matra entry, JavaScript values, and HTML renderer in one short example. The website build executes this source and shows the actual renderer output beside it.
The sample runs during the site build. Execute JavaScript values only in an environment you trust.
Runnable example
Generate an HTML document from JavaScript values and a function
The setup page explains how to reproduce this example with Node.js.
The left panel shows the complete Markdown source. matra.entry selects main.matra, and matra.values exposes the JavaScript expression as content. @matra/core evaluates the document, while @matra/site-generation builds a site from pages, shared layouts, and data. The CLI creates and builds starter projects. The code below shows each package in use.
<html lang="en">
<head>
<title>Compose a page with Matra packages | Matra</title>
</head>
<body>
<header>
<p>MATRA / PACKAGE EXAMPLES</p>
<h1>Compose a page with Matra packages</h1>
<p>Use the CLI to start a project, Core to evaluate Matra documents, and site-generation to build a site.</p>
</header>
<main>
<section id="cli">
<h2>@matra/cli</h2>
<p>Create and preview a starter project with the experimental CLI.</p>
<pre><code>npm install --global @matra/[email protected]
matra init hello
cd hello && matra dev</code></pre>
</section>
<section id="core">
<h2>@matra/core</h2>
<p>Build and run a literate Matra document in Node.js.</p>
<pre><code>const value = await runLiterate(await buildLiterate(source))</code></pre>
</section>
<section id="site-generation">
<h2>@matra/site-generation</h2>
<p>Generate pages from Matra templates, page data, and a shared layout.</p>
<pre><code>await generateSite({ root, output: "dist", pages })</code></pre>
</section>
</main>
<footer>
<p>These package workflows are experimental; check each package's release notes.</p>
</footer>
</body>
</html>INTERACTIVE DEMOS
Change a value. See the picture and equation.
Sliders and inputs re-run fixed Matra documents, updating both the preview and source.
The Core/HTML v0.3.0 document APIs generate browser-native SVG and MathML. These are not the dedicated @matra/graphics or @matra/math APIs, nor symbolic computation. Arbitrary code execution and external module imports are not provided.
SVG: arrange circles
Change the circle count and radius to explore a pattern made with repetition and rotation.
Showing the initial result. Enable JavaScript to use the controls.
View the executed Matra source
let count = 8;
let size = 16;
let indices = [0,1,2,3,4,5,6,7];
svg(viewBox="0 0 320 320" role="img" aria-label="SVG: arrange circles") {
title { "SVG: arrange circles" }
circle(cx=160 cy=160 r=80 fill="none" stroke="#d8e2ef") {}
...for (i in indices) {
g(transform="rotate(" + (i * 360 / count) + " 160 160)") {
circle(cx=160 cy=80 r=size fill="#006fe5" fill-opacity=0.65) {}
}
}
}MathML: a × x²
Change coefficient a and input x to see equation typesetting and a numeric result. Calculation uses Core's basic arithmetic.
Showing the initial result. Enable JavaScript to use the controls.
View the executed Matra source
let a = 2;
let x = 3;
let result = a * x * x;
math(display="block") {
mrow {
mn { a }
mo { "×" }
msup {
mrow {
mo { "(" }
mn { x }
mo { ")" }
}
mn { 2 }
}
mo { "=" }
mn { result }
}
}Explore next
Know the boundary before extending it.
01
HTML page
Describe document structure in Matra, data and functions in JavaScript, and generate HTML.
Setup instructions →02
SVG and math
Try focused SVG/MathML demos generated with Core/HTML. This is a separate path from the dedicated Graphics/Math APIs.
Try the demos →Release plan →03
Editing in a browser
Edit and run Matra documents in the HTML-only Playground, with Worker termination and a 10-second timeout.
Try the Playground →Reproducibility
Pin the published package versions.
npm install --save-exact @matra/[email protected] @matra/[email protected]