Skip to content

Commit

Permalink
fix(rehype-typst): inline math not rendering (#615)
Browse files Browse the repository at this point in the history
* fix inlineMathTemplate

* line up baseline for inline-math

* fix template

---------

Co-authored-by: Han-Miru Kim <[email protected]>
  • Loading branch information
Enter-tainer and kimhanm authored Dec 11, 2024
1 parent c4e5d9c commit 582c3ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
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

0 comments on commit 582c3ca

Please sign in to comment.