4.0 KiB
4.0 KiB
name, tags, files, share.uri, share.hash, share.mode
| name | tags | files | share.uri | share.hash | share.mode | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Library/mrmugame/Silverbullet-Math | meta/library |
|
https://github.com/MrMugame/silverbullet-math/blob/main/Math.md | 13247895 | pull |
Silverbullet Math
This library implements two new widgets
latex.block(...)andlatex.inline(...),
which can be used to render block and inline level math respectively. Both use ${latex.inline\href{https://katex.org/}{\KaTeX}} under the hood
Examples
Let ${latex.inlineS} be a set and ${latex.inline\circ : S \times S \to S,; (a, b) \mapsto a \cdot b} be a binary operation, then the pair ${latex.inline(S, \circ)} is called a group iff
- ${latex.inline\forall a, b \in S, ; a \circ b \in S} (completeness),
- ${latex.inline} (associativity),
- ${latex.inline\exists e \in S} such that ${latex.inline} (identity) and
- ${latex.inline\forall a \in S,; \exists b \in S} such that ${latex.inline} (inverse).
The Fourier transform of a complex-valued (Lebesgue) integrable function ${latex.inlinef(x)} on the real line, is the complex valued function ${latex.inline\hat {f}(\xi )}, defined by the integral ${latex.block}
Quality of life
There are two slash commands to make writing math a little easier,
/mathand/equation.
Info
The current ${latex.inline\KaTeX} version is ${latex.katex.version}.
Implementation
local location = "Library/mrmugame/Silverbullet-Math"
-- TODO: Remove the check for system.getURLPrefix as soon as the API has settled
latex = {
header = string.format("<link rel=\"stylesheet\" href=\".fs/%s/katex.min.css\">", location),
katex = js.import(string.format("%s.fs/%s/katex.mjs", system.getURLPrefix and system.getURLPrefix() or "/", location))
}
function latex.inline(expression)
local html = latex.katex.renderToString(expression, {
trust = true,
throwOnError = false,
displayMode = false
})
return widget.new {
display = "inline",
html = "<span>" .. latex.header .. html .. "</span>"
}
end
function latex.block(expression)
local html = latex.katex.renderToString(expression, {
trust = true,
throwOnError = false,
displayMode = true
})
return widget.new {
display = "block",
html = "<span>" .. latex.header .. html .. "</span>"
}
end
slashcommand.define {
name = "math",
run = function()
editor.insertAtCursor("${latex.inline[[]]}", false, true)
editor.moveCursor(editor.getCursor() - 3)
end
}
slashcommand.define {
name = "equation",
run = function()
editor.insertAtCursor("${latex.block[[]]}", false, true)
editor.moveCursor(editor.getCursor() - 3)
end
}
.sb-lua-directive-inline:has(.katex-html) {
border: none !important;
}