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

Add build time generated math using Katex embedded as WASI #12679

Merged
merged 1 commit into from
Aug 9, 2024

Conversation

bep
Copy link
Member

@bep bep commented Jul 26, 2024

While very useful on its own (and combined with the passthrough render hooks), this also serves as a proof of concept of using WASI (WebAssembly System Interface) modules in Hugo.

This will be marked experimental in the documentation. Not because it will be removed or changed in a dramatic way, but we need to think a little more how to best set up/configure similar services, define where these WASM files gets stored, maybe we can allow user provided WASM files plugins via Hugo Modules mounts etc.

See these issues for more context:

@bep
Copy link
Member Author

bep commented Jul 30, 2024

We would need a fix for tetratelabs/wazero#2294 for this to go beyond a proof of concept, I think, but I'm working on it.

@bep
Copy link
Member Author

bep commented Aug 5, 2024

OK, my upstream Wazero patch was just merged (!). I'm going to do finish the "render hook" part of this in #12717 first, and then return to this PR.

@bep bep force-pushed the wasitest branch 6 times, most recently from 7eef0f3 to a986f73 Compare August 8, 2024 09:04
@bep
Copy link
Member Author

bep commented Aug 8, 2024

transform.ToMath(opts any)

Where opts is converted to KatexInput:

type KatexInput struct {
	Expression string       `json:"expression"`
	Options    KatexOptions `json:"options"`
}

type KatexOptions struct {
	Output      string `json:"output"` // html, mathml (default), htmlAndMathml
	DisplayMode bool   `json:"displayMode"`
}

There may be some more (https://katex.org/docs/options.html) useful end user option, but it's not obvious to me.

Does the func signature above make sense, @jmooring ?

@bep bep force-pushed the wasitest branch 3 times, most recently from c84cad2 to 7701939 Compare August 8, 2024 13:16
@jmooring
Copy link
Member

jmooring commented Aug 8, 2024

Does the func signature above make sense?

I'm sure you have a good reason for the signature above, but I would have expected this instead:

{{ $expression := "c = \\pm\\sqrt{a^2 + b^2}" }}
{{ $opts := dict "output" "mathml" "displaymode" true }}
{{ $result := transform.ToMathML $expression $opts }}

where $opts has reasonable defaults (e.g., output = mathml, displaymode = true).

@bep
Copy link
Member Author

bep commented Aug 8, 2024

I'm sure you have a good reason for the signature above, but I would have expected this instead:

Only me being lazy, I guess. So, from an end users perspective I guess it makes sense to have them split, so options can be defined somewhere (e.g. in hugo.toml). I'll fix that.

@bep
Copy link
Member Author

bep commented Aug 8, 2024

{{ $result := transform.ToMathML $expression $opts }}

Also note that I have named it transform.ToMath (there are some different ossible output formats, not just mathml).

@bep
Copy link
Member Author

bep commented Aug 8, 2024

OK, I have pushed a verion of transform.ToMath with 2 args, the last (options) optional.

@bep bep force-pushed the wasitest branch 5 times, most recently from 9c612a2 to 79cc5ff Compare August 8, 2024 16:00
@bep bep force-pushed the wasitest branch 4 times, most recently from b226863 to 940a838 Compare August 9, 2024 13:15
@bep bep changed the title Embed Katex as Wasm Add build time generated math using Katex embedded as WASI Aug 9, 2024
@bep bep marked this pull request as ready for review August 9, 2024 13:16
@bep bep force-pushed the wasitest branch 5 times, most recently from 20783a3 to 1fb91e0 Compare August 9, 2024 14:26
While very useful on its own (and combined with the passthrough render hooks), this also serves as a proof of concept of using WASI (WebAssembly System Interface) modules in Hugo.

This will be marked _experimental_ in the documentation. Not because it will be removed or changed in a dramatic way, but we need to think a little more how to best set up/configure similar services, define where these WASM files gets stored, maybe we can allow user provided WASM files plugins via Hugo Modules mounts etc.

See these issues for more context:

* gohugoio#12736
* gohugoio#12737

See gohugoio#11927
@bep bep merged commit 33c0938 into gohugoio:master Aug 9, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants