-
Notifications
You must be signed in to change notification settings - Fork 22
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
Mapping Between Typst Source and Output #524
Comments
The feature is already at the rust side (for typst-preview) but not exposed in the JS library. |
For my own purposes, I've implemented a getMapping function which produces a javascript object allowing mapping between source and output positions. You can see it here. Basically, I go through all of the glyphs on all of the elements of all the frames on all the pages of the document, and produce a collection of parallel arrays given page number, x, y, source file, offset. Then I can read through the array in javascript to map source to output and back again. I'd like to contribute what I've done back, but I figured there would probably be some questions about design that would need to be hashed out before I try to put it in an actuall pull request. So I thought I'd get your thoughts here. |
It will be very expensive to export entire span mapping from rust side to js side, especially when document keeps changing. It seems you're building some editor and this will become a bottleneck on big documents. Two aspect:
|
So far, I appear to be getting away with exporting the whole mapping. My theory was that since I'm exporting a whole pdf anyways, it wouldn't be a big deal to export a mapping of it alongside that. But I did figure I'd likely need to optimize eventually. Exporting the mapping does have the advantage of being very fast to lookup new locations. The actual mapping logic behind the code you pointed to appears to live here: ( typst.ts/compiler/src/service/compile.rs Line 501 in 5f91f5a
Can you explain how IncrServer is intended to work? I looked at it previously, but I wasn't sure how to do anything useful with that api. |
Sounds great.
Alright, it is in experiment state currently and doesn't get mentioned in the documentation, as I'm not sure how to expose it correctly. The usage of The goal of typstPlugin.withIncrementalServer(
(srv: IncrementalServer) => {
return new Promise((dispose) => {
const updateDoc = () => {
const v = await typstPlugin.compile({
mainFilePath,
incrementalServer: srv,
});
typstDoc.addChangement(["diff-v1", v]);
};
callback({ updateDoc, dispose })
});
}
); You can see the experiment code here: https://github.com/mitex-rs/mitex/blob/c5e9f9bf2c5ef9a0f7be1c981f11026a0d732137/packages/mitex-web/src/tools/underleaf.ts#L103-L111 |
Is there a feature/code that enables mapping between the typst source and positions in the output? It'd be nice to be able to map from a position in the source to the page and position on that page, and back again.
I'm using typst.ts on the browser client.
The text was updated successfully, but these errors were encountered: