Leedehai / typst-physics

physica: vectors, fields, differentials, derivatives, Dirac brakets, tensors, and more. See examples in the manual PDF.
https://github.com/Leedehai/typst-physics
MIT License
312 stars 8 forks source link

mel needs beautify #16

Closed zrt2002 closed 9 months ago

zrt2002 commented 9 months ago

This code snippet $ mel(phi_n^0, sqrt((2 hbar) / (m omega))(a^dagger + a), phi_n^0) $ gives image in which the vertical bar is too bold and slightly higher than my braket. Besides, the space between alphabet and bar is too tight.

Leedehai commented 9 months ago

Thanks. Admittedly this has been a longstanding pain issue and I do not have an answer.

Boldness and tightness: sorry, this is rooted in Typst's layout strategy and could not be solved cleanly at the package level. Especially, I think the boldness is caused by some issue deep inside the compiler's stretch_glyph() function: stretching by height shouldn't affect the width. I just created https://github.com/typst/typst/issues/2737.

Height of vertical bar: the package uses a hack to calculate the height, and it is not reliable as you saw from the example. Maybe I could use quadratic interpolation to calculate an adjustment factor based on the element height [1], but that's unreliable, too. There's an issue created at Typst (https://github.com/typst/typst/issues/240), and I very much look forward to a native solution to get rid of the hack.

I urge you to raise the Typst contributor's awareness so they could prioritize :)

[1] In the meantime, I'll find some time and do it in this package.

Leedehai commented 9 months ago

Update: I have a draft to make the Typst compiler handle this natively: https://github.com/Leedehai/typst/pull/1/files

Leedehai commented 9 months ago

Upgraded physica to v0.9.0. It requires Typst compiler 0.10.0 (released a few hours ago; update with typst update), which has my PRs https://github.com/typst/typst/pull/2760 and https://github.com/typst/typst/pull/2764 to fix this issue.

Screenshot 2023-12-04 at 18 46 56

After https://github.com/typst/packages/pull/277 is merged as well, physica v0.9.0 will be auto-downloadable by the compiler and the typst.app web app.