astro-typst playground

Version: 0.12.0-beta.4 with Astro v5.7.10

0: Articles in the collection

1: svg output

1.1: Import as a component

---
import Simp from "./simp.typ";
---
<Simp />

1.1: In route

/simp

1.2: raw content

#set page(width: auto, height: auto, margin: 0.5em)

#let repeat = (n, f) => {
  for i in range(n) {
    f()
  }
}

#let render = () => [
  + Hello, typst!
]

#repeat(10, render)

#include "_included.typ"

2: HTML export

  1. Hello, typst!
  2. Hello, typst!
  3. Hello, typst!
  4. Hello, typst!
  5. Hello, typst!
  6. Hello, typst!
  7. Hello, typst!
  8. Hello, typst!
  9. Hello, typst!
  10. Hello, typst!

2.1: string code & #html.frame

this is html content

3. Hast & JSX

Astro

JSX from Typst!

Counter: 10

Source code
_jsx.typ
#let jsx = s => html.elem("script", attrs: ("data-jsx": s))
// you can customize the syntax as you like, just make sure it's in the above format
// for example, as code block
#let jsx2 = cb => html.elem("script", attrs: ("data-jsx": cb.text))
#import "_lib.typ": typst
=== JSX from Typst!
#jsx("import Counter from '../components/Counter.astro'")
#jsx2[```jsx
<Counter initialCount={10} message='typst' />
```]
../components/Counter.astro
---
export type Props = {
initialCount: number;
message: string;
};
const { initialCount, message } = Astro.props;
let count = initialCount;
---
<div>
<p>Counter: <span id="count">{count}</span></p>
<button id="increment">Increment</button>
<button id="msg">Alert</button>
</div>
<script is:inline define:vars={{ message }}>
const button = document.querySelector("button#increment");
const p = document.querySelector("#count");
button?.addEventListener("click", () => {
p.textContent = (parseInt(p.textContent) + 1).toString();
});
const msgBtn = document.querySelector("button#msg");
msgBtn?.addEventListener("click", () => {
alert(`Message from ${message}!`);
});
</script>

React

Source code
example.astro
---
import ConfettiBtn from "../components/ConfettiBtn.tsx";
---
<ConfettiBtn client:only />
components/ConfettiBtn.tsx
import React, { useState } from "react";
import Confetti from "react-confetti-explosion";
export default () => {
const [isConfettiRunning, setIsConfettiRunning] = useState(false);
return (
<div>
<button
disabled={isConfettiRunning}
onClick={() => {
setIsConfettiRunning(!isConfettiRunning)
}}
>
Click to trigger Confetti!
</button>
{isConfettiRunning && (
<Confetti onComplete={() => setIsConfettiRunning(false)} />
)}
</div>
);
};

4: TypstDocInput

astro-typst playgroundLinkLook at Figure 1!Include other filesThis is an included file.𝐻=𝑛𝑢𝑦=𝑛𝑢𝑦This is an included file.Include changed to:𝑓(𝑡)=1{𝐹(𝜇)}=1{𝐻(𝜇)̃𝐹(𝜇)}=(𝑡)𝑓(𝑡)=(𝑧)̃𝑓(𝑡𝑧)d𝑧=sin(𝜋𝑧Δ𝑇)(𝜋𝑧Δ𝑇)𝑛=𝑓(𝑡𝑧)𝛿(𝑡𝑛Δ𝑇𝑧)d𝑧=𝑛=sin(𝜋𝑧Δ𝑇)(𝜋𝑧Δ𝑇)𝑓(𝑡𝑧)𝛿(𝑡𝑛Δ𝑇𝑧)d𝑧=𝑛=𝑓(𝑛Δ𝑇)sin(𝜋·𝑡𝑛Δ𝑇Δ𝑇)𝜋·𝑡𝑛Δ𝑇Δ𝑇=𝑛=𝑓(𝑛Δ𝑇)sinc(𝑡𝑛Δ𝑇Δ𝑇).𝑓(𝑡,𝑧)(𝑡,𝑧)=𝑓(𝛼,𝛽)(𝑡𝛼,𝑧𝛽)d𝛼d𝛽.Hello fromastroThis is data passed from sys.input: something from Astro!Figure 1: Rainbow squares

5: mainFilePath

astro-typst playgroundLinkLook at Figure 1!Include other filesThis is an included file.𝐻=𝑛𝑢𝑦=𝑛𝑢𝑦This is an included file.Include changed to:𝑓(𝑡)=1{𝐹(𝜇)}=1{𝐻(𝜇)̃𝐹(𝜇)}=(𝑡)𝑓(𝑡)=(𝑧)̃𝑓(𝑡𝑧)d𝑧=sin(𝜋𝑧Δ𝑇)(𝜋𝑧Δ𝑇)𝑛=𝑓(𝑡𝑧)𝛿(𝑡𝑛Δ𝑇𝑧)d𝑧=𝑛=sin(𝜋𝑧Δ𝑇)(𝜋𝑧Δ𝑇)𝑓(𝑡𝑧)𝛿(𝑡𝑛Δ𝑇𝑧)d𝑧=𝑛=𝑓(𝑛Δ𝑇)sin(𝜋·𝑡𝑛Δ𝑇Δ𝑇)𝜋·𝑡𝑛Δ𝑇Δ𝑇=𝑛=𝑓(𝑛Δ𝑇)sinc(𝑡𝑛Δ𝑇Δ𝑇).𝑓(𝑡,𝑧)(𝑡,𝑧)=𝑓(𝛼,𝛽)(𝑡𝛼,𝑧𝛽)d𝛼d𝛽.Hello fromastroThis is data passed from sys.input: something from typst.Figure 1: Rainbow squares

6: DynTypst

Work in progress