Skip to content

Commit

Permalink
Until Typst implements the feature, an incomplete & hacky interim sol…
Browse files Browse the repository at this point in the history
…ution for braket etc.

Not satisfactory, until Typst resolves typst/typst#240

This interim solution can handle
$ mel(u,M,v) mel(u,vec(U,V),v), mel(vec(U,V),M,v) $
but not something like
$ mel(u,vec(U,V,W),v) mel(vec(U,V,W),M,v) $

Motivated by #16
  • Loading branch information
Leedehai committed Nov 22, 2023
1 parent f2b6cc5 commit 8f64609
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Binary file modified physica-manual.pdf
Binary file not shown.
3 changes: 1 addition & 2 deletions physica-manual.typ
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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": *
Expand Down
21 changes: 18 additions & 3 deletions physica.typ
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) $
})

Expand All @@ -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) $
})

Expand All @@ -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) $
})

Expand Down

0 comments on commit 8f64609

Please sign in to comment.