Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rehype-typst): inline math not rendering #615

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions projects/rehype-typst/equation.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

#let s = state("t", (:))

#let pin(t) = locate(loc => {
style(styles => s.update(it => it.insert(t, measure(line(length: loc.position().y + 0.25em), styles).width) + it))
})
#let pin(t) = context {
let width = measure(line(length: here().position().y)).width
s.update(it => it.insert(t, width) + it)
}

#show math.equation: it => {
box(it, inset: (top: 0.5em, bottom: 0.5em))
}

$pin("l1")1+e/sqrt(sqrt(a/c)/(e + c +a/b))$
$pin("l1")1+(e vec(a,b,c)) / sqrt(sqrt(a/c)/(e + c +a/b)/e)$ 123

#context [
#metadata(s.final().at("l1")) <label>
]

#locate(loc => [
#metadata(s.final(loc).at("l1")) <label>
])
// #context s.get()

// #s.display()
// #locate(loc => {
// let s = s.final(loc)
// place(left+top, dx: 0pt, dy: s.l1, line(length: 100pt, stroke: red + 0.1pt))
// })
#context {
let s = s.final()
place(left + top, dx: 0pt, dy: s.l1, line(length: 100pt, stroke: red + 0.1pt))
}
13 changes: 7 additions & 6 deletions projects/rehype-typst/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,20 @@ async function renderToSVGString_($typst, code, displayMode) {

#let s = state("t", (:))

#let pin(t) = locate(loc => {
style(styles => s.update(it => it.insert(t, measure(line(length: loc.position().y + 0.25em), styles).width) + it))
})
#let pin(t) = context {
let width = measure(line(length: here().position().y)).width
s.update(it => it.insert(t, width) + it)
}

#show math.equation: it => {
box(it, inset: (top: 0.5em, bottom: 0.5em))
}

$pin("l1")${code}$

#locate(loc => [
#metadata(s.final(loc).at("l1")) <label>
])
#context [
#metadata(s.final().at("l1")) <label>
]
`;
const displayMathTemplate = `
#set page(height: auto, width: auto, margin: 0pt)
Expand Down
Loading