Skip to content

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

Open
rei2hu wants to merge 5 commits intokisonecat:masterfrom
rei2hu:chore/refactor
Open

Refactor code to allow TikZ to html conversions on demand#30
rei2hu wants to merge 5 commits intokisonecat:masterfrom
rei2hu:chore/refactor

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.


window.TikZJax = TikZJax;
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.

@jorgengaldal
Copy link

Can I use this version before it is merged? Is there a bundled js-file I can download?

@rei2hu
Copy link
Author

rei2hu commented Apr 8, 2025

Can I use this version before it is merged? Is there a bundled js-file I can download?

Not a bundled version, but I did put together a repo that can be added to a package.json to do server side generation of svgs using these changes e.g. "tikzjax-server": "git+https://github.com/rei2hu/tikzjax-server.git"

If you run into an issue using it feel free to make an issue there and I can look at it though it works for me(tm)

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