-
Notifications
You must be signed in to change notification settings - Fork 3
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
Leverage mitex plugin to render latex equations #12
base: main
Are you sure you want to change the base?
Conversation
Adding @nathanrboyer to this. I know he wanted typst integration with handcalcs. This may be a potential quick fix once it is cleaned up. The true typst backend to handcalcs could still come later on, but I know that is a much bigger undertaking. |
That's really cool! I hadn't known about mitex either. It might be useful to use a context parameter to import mitex automatically such as: mitex(tc) && print(io, "#import \"@preview/mitex:0.2.4\": mi\n\"")` The project's current roadmap is:
I love the feature you've implemented here and will absolutely merge it, but need to resolve item 1 before implementing new formats. For example, it would be nice to be able to render both a raw text block I'm hoping to complete item 3 prior to JuliaCon, which would clear the way for a Typst backend in Handcalcs.jl :) |
Cool! Yeah I like that context parameter idea. I agree that being able to render raw text block and choosing mitex option would be good. I find API is always the hardest part for me. I personally like the way Latexify.jl allows for the changing of settings. You can see it here: https://korsbo.github.io/Latexify.jl/stable/#Setting-your-own-defaults. I ended up doing the same for handcalcs. I looked into preferences.jl but it seemed a little more confusing. I usually find my favorite API by just imagining what I wish it was without any syntax constraints. In this case for me it would be matching Typst 1 to 1 as best as I can. This may not be what you are looking for, but something like this would be cool for building typst documents: @typst_report begin
"""
#import \"@preview/mitex:0.2.4\": *
= Header 1
This is normal typst markdown
#align(right)[#text(fill:green)[OK]]
See the equation below:
"""
# can comment as normal
@mi(@handcalcs begin
x = 5
y = 20
z = x^2 + y^2
end
)
# mitex is a centered math environment.
@mitex(@handcalcs begin
x = 5
y = 20
z = x^2 + y^2
end
)
# this would simply pass the raw text block (unless settings were changed maybe)
@handcalcs begin
x = 5
y = 20
z = x^2 + y^2
end
# some no render function that does not print
@no_render(
a = 5
)
"""
Can I interpolate *a* here: $$(a). What syntax should it be?
"""
end This would essentially be the render function that prints each piece. It basically just opens an io and then adds |
I agree this is good design. The next release will use a The two main contenders in terms of how to select between formats is
I've tried out both, which unfortunately took a lot of time. I was initially averse to option A because I wanted to avoid creating a bunch of new types. However, B feels pretty messy and doesn't really solve any of the problems with A. Option A also seems to align with your proposal, where a In the upcoming support for |
Missed this the first time, yes exactly! |
I think I like the option A idea. I will try to look into it more these next few days/weeks depending on time. This is awesome work so far! This is the main thing I want to figure out right now. That being how everything will work together: quarto, typst, Pluto, Handcalcs, Jupyter, Drwatson, etc. At work it’s a pain to get things unblocked due to security measures so it has been hard trying to use quarto somewhat which relies on so many executables. I don’t know how I would ensure all users are able to get everything installed and working. Being able to rely on just Julia and Typst for reports would be so nice. An interactive Pluto file to typst output would pretty amazing from a user standpoint, but we just have to take it one piece at a time. |
Do you mean rendering a cell or the entire file? |
Oh my documentation says it works in Quarto, maybe I fixed it. Guess I'll have to check haha |
That's good work you're putting in, keep it up! |
I haven’t tried your package with it. That is just with Handcalcs/jupyter. It’s just the work hurdles with quarto and relying on the Latex pdf render (currently) that is too difficult currently. |
I can currently create an interactive Pluto file using handcalcs, but our calculations must be printed to pdf. There is currently no Pluto -> quarto(pdf) or Pluto -> typst(pdf) that exists |
Currently Rough Implementation
This pull request extends the
show_raw
method for LaTexStrings. It would be great if we could leverage mitex to render latex equations into typst. It is a rough implementation, but I wanted to spark a discussion.Try it out and see what you think
Import Typstry (using this branch) and Handcalcs
This command adds mitex package to the preamble
Then try the following:
julia> TypstString( @handcalcs begin x = 5 y = 20 z = x^2 + y end ) |> render;
You should get an output like the following:
![CleanShot 2025-01-16 at 15 36 09@2x](https://private-user-images.githubusercontent.com/143426779/404047040-7967c852-6405-4b36-8989-9fc9d1134b89.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxMzkzNTEsIm5iZiI6MTczOTEzOTA1MSwicGF0aCI6Ii8xNDM0MjY3NzkvNDA0MDQ3MDQwLTc5NjdjODUyLTY0MDUtNGIzNi04OTg5LTlmYzlkMTEzNGI4OS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwOVQyMjEwNTFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mMmY5MzI3OGY0M2U2NjlkNmVhZGJkNGQ0N2ZkMWExZDE5MGZjYTNhZDNkNzNiMmE1YWI1NmE0Yzg3MDUwZWZmJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.DZEEiQlf2WlCscmJYwKoWK7wJhxSY1qGkSxP8bKOyNg)
I currently opened an issue for the
[10pt]
being rendered. You can see the issue here: mitex-rs/mitex#191Otherwise mitex works pretty well. It can even render color:
julia> TypstString( @handcalcs begin x = 5 y = 20 z = x^2 + y end color = :blue ) |> render;