diff --git a/README.md b/README.md index e8cddd0..a241721 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,8 @@ explore the design together. Some features might warrant a package on its own. [physica-manual.pdf](https://github.com/Leedehai/typst-physics/blob/master/physica-manual.pdf). This does not scale well. I plan to add programmatic testing by comparing rendered pictures with golden images. +* Please nudge Typst maintainers to resolve https://github.com/typst/typst/issues/240 by scaling up given glyphs in the middle of [`lr()`](https://typst.app/docs/reference/math/lr#functions-lr) :grinning: + ## License * Code: the [MIT License](LICENSE.txt). diff --git a/physica-manual.pdf b/physica-manual.pdf index 4b93182..e28fce4 100644 Binary files a/physica-manual.pdf and b/physica-manual.pdf differ diff --git a/physica-manual.typ b/physica-manual.typ index e7bc4c7..1eba0b0 100644 --- a/physica-manual.typ +++ b/physica-manual.typ @@ -1,5 +1,6 @@ // Copyright 2023 Leedehai // This document is shared under the Creative Commons BY-ND 4.0 license. +#import "physica.typ": * #let version = "0.8.1" @@ -52,8 +53,6 @@ This manual itself was generated using the Typst CLI and the `physica` package, With `typst`'s #linkurl("package management", "https://github.com/typst/packages"): -#import "physica.typ": * - ```typst #import "@preview/physica:0.8.1": * diff --git a/physica.typ b/physica.typ index 2f10a01..cdb8b0a 100644 --- a/physica.typ +++ b/physica.typ @@ -344,6 +344,15 @@ #let bra(f) = $lr(angle.l #f|)$ #let ket(f) = $lr(|#f angle.r)$ +// Quadratic interpolation that takes in a height in pt units. +// Intended input-output pairs: {10.59,1},{23.01,0.8},{26.93,0.7}. +// This is imperfect, hacky and has corner cases unresolved, but until +// https://github.com/typst/typst/issues/240 is resolved there is no better way. +// Motivated by https://github.com/Leedehai/typst-physics/issues/16 +#let __height_mul_factor(h) = { + -0.0005757 * h * h + 0.0032409 * h + 1.03024 +} + // Credit: thanks to peng1999@ and szdytom@'s suggestions of measure() and // phantoms. The hack works until https://github.com/typst/typst/issues/240 is // addressed by Typst. @@ -355,7 +364,9 @@ let ket = args.at(1, default: bra) let height = measure($ bra ket $, styles).height; - let phantom = box(height: height * 0.8, width: 0pt, inset: 0pt, stroke: none); + let phantom = box( + height: height * __height_mul_factor(height.pt()), + width: 0pt, inset: 0pt, stroke: none); $ lr(angle.l bra lr(|phantom#h(0pt)) ket angle.r) $ }) @@ -369,7 +380,9 @@ let ket = args.at(1, default: bra) let height = measure($ bra ket $, styles).height; - let phantom = box(height: height * 0.8, width: 0pt, inset: 0pt, stroke: none); + let phantom = box( + height: height * __height_mul_factor(height.pt()), + width: 0pt, inset: 0pt, stroke: none); $ lr(bar.v bra#h(0pt)phantom angle.r)lr(angle.l phantom#h(0pt)ket bar.v) $ }) @@ -382,7 +395,9 @@ // we use the same hack as braket(). #let matrixelement(n, M, m) = style(styles => { let height = measure($ #n #M #m $, styles).height; - let phantom = box(height: height * 0.8, width: 0pt, inset: 0pt, stroke: none); + let phantom = box( + height: height * __height_mul_factor(height.pt()), + width: 0pt, inset: 0pt, stroke: none); $ lr(angle.l #n lr(|#M#h(0pt)phantom|) #m angle.r) $ })