-
Notifications
You must be signed in to change notification settings - Fork 88
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
Export to Typst/Fletcher diagram #262
base: master
Are you sure you want to change the base?
Conversation
…eaks moving cells.
@varkor Couple questions if you have time for them. At this point I've implemented Typst rendering, but the (AFAIK only) library is very bare bones so I've had to work around some minor issues. Notably, concurrent renders seem to break the library but I've implemented a queue for the rendering, which is quick enough to work as a permanent solution. Onto real issues:
Do you have an idea about the possible cause of these breakages ? Cheers |
Line 550 in 4fee690
This call is returning EDIT: Fixed, see commit below. |
Thanks for the pull request! I must admit that it hadn't occurred to me that Typst has different syntax for mathematics than LaTeX, which makes support for Typst subtler. I suppose it will be necessary to have a toggle in the UI for LaTeX/Typst mode – I'll have to think about how to do that without complicating the UI too much.
Unfortunately, the timing is a little inconvenient, as I'm about to go on a research trip for a few weeks, and don't yet know whether I'll have time to look at this in detail before I get back. However, if I don't manage to look at it during my trip, it will be a priority for me once I return. I'll try to answer any questions you have in the meantime, though. |
Thanks for your time ! Regarding the second point, this was actually all addressed in the latest commit which makes me confident this is close to releasable. Don't worry about the timing though, I can just host the fork somewhere in the meantime. What's left (for me) to do:
|
That's it, I'm calling it releasable ! Let me know what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some detailed but incomplete suggestion for code
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: jingkaimori <jingkaimori@gmail.com>
This comment was marked as resolved.
This comment was marked as resolved.
Commit 82aaf18 introduced a bug causing typst fails to load when toggling between katex and typst mode multiple times. Here is the patch to fix it: diff --git a/src/ui.mjs b/src/ui.mjs
index 646d2b8..e1e52d1 100644
--- a/src/ui.mjs
+++ b/src/ui.mjs
@@ -7892,6 +7892,9 @@ const TypstQueue = new class extends PromiseQueue {
// Load the Typst library as an ES6 module when invoked. Unlike KaTeX, this is on the heavier side of things. We don't
// wait for it.
const load_typst = () => {
+ if (Typst !== null) {
+ return;
+ }
Typst = import("https://cdn.jsdelivr.net/npm/@myriaddreamin/typst.ts/dist/esm/contrib/all-in-one-lite.bundle.js").then((module) => {
const $typst = module.$typst;
const preloadRemoteFonts = module.preloadRemoteFonts;
@@ -7912,8 +7915,6 @@ const load_typst = () => {
}).catch(() => {
// Handle Typst.ts not loading (somewhat) gracefully.
UI.display_error("Typst failed to load.");
- // Remove the loading screen.
- ui.element.query_selector(".loading-screen").class_list.add("hidden");
});
};
@@ -8015,7 +8016,13 @@ document.addEventListener("DOMContentLoaded", () => {
});
// Load immediately if Typst if the renderer set in user settings
- if (ui.settings.get("quiver.renderer") === "typst") load_typst();
+ if (ui.settings.get("quiver.renderer") === "typst"){
+ load_typst();
+ Typst.catch(() => {
+ // Remove the loading screen.
+ ui.element.query_selector(".loading-screen").class_list.add("hidden");
+ });
+ };
// Load the style sheet needed for KaTeX.
document.head.appendChild(new DOM.Element("link", { |
Lines 6901 to 6904 in 82aaf18
|
This list is only ever filled up when importing LaTeX macros and when those macros contain shorthands for color definitions (if I read the code correctly). I guess it would make sense to hide this list when in Typst mode, as there is currently no way to import Typst macros (although this wouldn't be too hard to implement since we use the actual typst compiler with a predefined preamble). A note for implementation if going in that direction: in a macro list, we can retrieve variable names via standard matching (e.g. I say in the current state of things, this list can remain hidden in Typst mode. I'm also wondering if it's not worth hiding the Typst export button when in LaTeX mode. This would allow in the future to add buttons for fletcher import and typst macro import without having too much clutter in the bottom bar. Exporting a fletcher diagram from a LaTeX one will also almost always yield incorrect maths syntax (although that can be dealt with using the typst package |
IMO importing external typst content could be implemented in another pr.
I agree with this. And mode toggling button could be moved to bottom bar, so that things related to label rendering appears together. Default mode applied to input is differ between KaTeX and typst. In KaTeX, input is considered as if in math mode, but in typst, input is treated as normal text. In this pr, a wrapper is applied automatically when typst is selected as renderer. Therefore changing label to text mode needs unnecessary wrapper. Line 325 in 82aaf18
Line 5610 in 82aaf18
But according to #45 (comment) such wrapper should be applied by user. |
I've implemented initial support to export to Typst diagrams. Incompatibilities are reported through the incompatibilities metadata object (that is: shortened arrows, empty arrow body, and k-cells for k > 1)
This still needs some UI adjustments to show the incompatibilities and instructions just like with latex.
I marked this as Draft because I feel like this feature cannot be fully used as-is since I haven't implemented in-browser rendering of the formulas. Looking into how to do that with
typst.ts
.Feel free to leave comments and to try this out. Diagrams should be readily useable with
at a document's start.