Desmost compiles LaTeX into Desmos.
In other words, it’s like HTML+CSS but for Desmos. Write your content in LaTeX (alongside your Markdown!) with Desmost syntax where you need it, and Desmost will turn it into a Desmos calculator embed for you.
Important
Desmost only works in the browser. This is because it relies on the Desmos API, which (currently) can only be included via <script>.
npm install desmostSee Docs / Writing to learn how to use Desmost syntax on top of LaTeX.
import { compile } from "desmost";
let calc = Desmos.GraphingCalculator(...);
compile(calc, "f(x) = x^2");Pass in options to customise compilation:
compile(calc, "/text{ sup world! }", {
errors: "crash",
ignore_blank_lines: true,
});Left up to you, in your framework of choice!
But if you enjoy nice things, Desmost provides a Svelte component for mass-compiling Desmost, intended to be used in conjunction with MDsveX:
<script>
import Content from "./intro.md";
import { Desmost } from "desmost/svelte";
</script>
<Desmost>
<Content />
</Desmost>This will replace all ```desmos blocks from your Markdown source with Desmos calculator embeds.
Tip
This is a brief look at what Desmost can do, and why you might want to use it. For full guidance, please head to Docs!
Desmost aims to be as lightweight as possible. If all you need is a blocks of LaTeX with no extra customisation, then that’s all you need to write.
a = 2
b = 3
c = 5
y = ax^2 + bx + cIf you want to add Desmos notes, just leave a % LaTeX comment:
% Welcome to Desmost!
a = 2
b = 3
c = 5
y = ax^2 + bx + cBut let’s say you want to do something fancier, like animating the slider for one of those variables.
All you need to do is add /anim in front of that line, plus a :: delimiter:
% Welcome to Desmost!
/anim :: a = 2
b = 3
c = 5
y = ax^2 + bx + cThese are called incantations, and it’s the only syntax there is in Desmost.1
When Desmost compiles this into Desmos, it’ll see /anim and know to set playing: true for that particular Desmos expression.
Suppose you also want to customise the slider bounds. Just add another incantation, this time with an argument:
% Welcome to Desmost!
/anim /slider{ min: 0, max: 10 } :: a = 2
b = 3
c = 5
y = ax^2 + bx + cTip
Look familiar? Desmost’s incantation syntax mirrors LaTeX’s \backslash{} commands ;)
This line is getting a little long, though. We can break it up over multiple lines:
% Welcome to Desmost!
/anim
/slider{ min: 0, max: 10 }
:: a = 2
b = 3
c = 5
y = ax^2 + bx + cWhat if it’s not your incantations, but your LaTeX that’s becoming too long?
I = \int \frac{1 + x + x^2}{1 + x} \ dxWe’ve got an incantation for that – /latex:
/latex{
I = \int \frac
{1 + x + x^2}
{1 + x}
\ dx
}And that’s all there is to Desmost!
All other functionality you might need is accessed through more incantations. For a complete list of all the available incantations, visit Incantations Reference.
Enjoy!
Desmost doesn’t have to be used for Markdown, but that’s what it was designed for.2 The key purpose of Desmost is to let you program Desmos embeds with raw text alongside your prose:
# Mysteries of Sound
Today we’re investigating the beauty of soundwaves and Fourier transforms. This is a sine wave:
```desmos
y = \sin{x}
```
And here’s a saw wave:
```desmos
/viewport{ left: -2*Math.PI, right: 2*Math.PI }
/slider{ min: 1, max: 40, step: 1 } :: N = 1
/latex{
f(x) = \frac{2}{\pi} \sum_{n=0}^{N} \frac{
}
/anim-mono /slider{ min: 0, max: "2\\pi" }
```Exactly like how a ```math block renders into LaTeX, or a ```mermaid block renders a diagram.
We want simple stuff like this to work effortlessly:
This keeps it easily comprehendable when mixed with Markdown. And it’s exactly the same as what you’d type into Desmos – it’s like you meant to do that, but accidentally ended up typing it into your IDE!
At the same time, we want to provide full control over as many aspects of the calculator as possible. Incantations make this easy – to access more functionality, all it takes is adding a new incantation.
All object arguments to incantations such as /viewport{} and /slider{} are identical to the Desmos API. This means fewer unnecessary abstractions for you to remember.
Desmost only handles what it needs to care about to work. You don’t need a LaTeX parser, because Desmos will already do that later down the line – parsing it ourselves would just be wasted effort!
Every bug, typo and inefficiency was lovingly crafted by hand <3