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

Refactor code to allow TikZ to html conversions on demand #30

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

rei2hu
Copy link

@rei2hu rei2hu commented Jul 6, 2024

This is a refactoring that will allow users to perform conversions on demand, keeps the existing functionality, and fixes some bugs.

I had a use case where I wanted to do the main processing in a Worker, so I made these changes (and some more that aren't included) to support that. I've left most of the existing code intact. Also helps with #8, #20, and #24.

TikZJax.js contains all of the conversion logic and exposes a load(wasmPath, coredumpPath) method that can be called to instantiate the wasm module on demand.

index.js contains all of the logic that relies on being in the dom.

I've updated the README with a basic example of how to load things manually.

I also had to pull in a different version of dvi2html to get things to build, but that should not be an issue because the interface looks to be the same.

The repository seems incomplete so let me know if I've messed up some hidden workflow.

if (!window.TikZJaxNoAutostart) {
window.onload = TikZJax(document);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is considered a bug or not, but TikZJax was not being executed with the onload function, but was being executed when the line was hit (because the result of the call is what's being assigned to window.onload)

}

const coredump = new Uint8Array(inf.result, 0, pages*65536);
return async (input) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

load returns a function that sets up wasm with the loaded payload/core dumps, so theoretically you could load different wasm/coredumps.

const tex1 = await load(wasm1, coredump1);
const tex2 = await load(wasm2, coredump2);

tex1(tikz1);
tex2(tikz2);

The main point of this is to prevent loading multiple times though. I don't see any benefit to loading multiple times.

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.

1 participant