diff --git a/README.md b/README.md index 071f75d..3303f98 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ See the [manual](https://github.com/Leedehai/typst-physics/blob/master/physica-m A larger [demo.typ](https://github.com/Leedehai/typst-physics/blob/master/demo.typ): -![demo-larger](https://github.com/Leedehai/typst-physics/assets/18319900/af4fcf6c-5da3-48d1-a7a7-59053f808db5) +![demo-larger](https://github.com/Leedehai/typst-physics/assets/18319900/b7dadf90-b401-4bbb-aff7-7c8840954209) ## Using physica in your Typst document diff --git a/demo.typ b/demo.typ index f5b38f0..bbf1856 100644 --- a/demo.typ +++ b/demo.typ @@ -11,7 +11,7 @@ A^T, curl vb(E) = - pdv(vb(B), t), quad tensor(Lambda,+mu,-nu) = dmat(1,RR), quad -dd(x,y), +f(x,y) dd(x,y), quad dd(vb(x),y,[3]), quad diff --git a/physica-manual.pdf b/physica-manual.pdf index a85543e..feaa1af 100644 Binary files a/physica-manual.pdf and b/physica-manual.pdf differ diff --git a/physica-manual.typ b/physica-manual.typ index ee2270a..a9b9f46 100644 --- a/physica-manual.typ +++ b/physica-manual.typ @@ -165,7 +165,7 @@ All symbols need to be used in *math mode* `$...$`. [`TT`], [], [`v^TT, A^TT` #sym.arrow $v^TT, A^TT$], - [transpose, also see\ @matrix-tranpose], + [transpose, also see\ @matrix-transpose], [`vectorbold(`_content_`)`], [`vb`], @@ -234,7 +234,7 @@ All symbols need to be used in *math mode* `$...$`. [`TT`], [], [`v^TT, A^TT` #sym.arrow $v^TT, A^TT$], - [transpose, also see\ @matrix-tranpose], + [transpose, also see\ @matrix-transpose], [#builtin([`mat(`...`)`])], [], @@ -592,6 +592,14 @@ Functions: `differential(`\*_args_, \*\*_kwargs_`)`, abbreviated as `dd(`...`)`. - `d`: the differential symbol [default: `upright(d)`]. - `p`: the product symbol connecting the components [default: `none`]. +TeXBook advises _[f]ormulas involving calculus look best when an extra thin space +appears before dx or dy or d whatever_ (Chapter 18 p.168), and this package +heeds this advice. If you don't want the spaces between the d-units, you may set +in a `compact:#true` argument: $dd(r,theta) "vs." dd(r,theta,compact:#true)$ (compact). +// https://github.com/typst/typst/issues/147 advocates for set rules for +// non built-in functions. When that's implemented, user can do a +// #set dd(compact: true) to set this param for all dd() invocations. + *Order assignment algorithm:* - If there is no order number or order array, all variables has order 1. - If there is an order number (not an array), then this order number is assigned to _every_ variable, e.g. `dd(x,y,2)` assigns $x <- 2, y <- 2$. @@ -607,8 +615,8 @@ Functions: `differential(`\*_args_, \*\*_kwargs_`)`, abbreviated as `dd(`...`)`. column-gutter: 2em, [ - *(1)* #hl(`dd(f), dd(x,y)`) \ - $ dd(f), dd(x,y) $ + *(1)* #hl(`dd(f), f(r,theta) dd(r,theta)`) \ + $ dd(f), f(r,theta) dd(r,theta) $ ], [ *(2)* #hl(`dd(x,3), dd(f,[k]), dd(f,[k],d:delta)`) \ @@ -619,8 +627,8 @@ Functions: `differential(`\*_args_, \*\*_kwargs_`)`, abbreviated as `dd(`...`)`. $ dd(f,2), dd(vb(x),t,[3,]) $ ], [ - *(4)* #hl(`dd(x,y,[2,3]), dd(x,y,z,[2,3])`) \ - $ dd(x,y,[2,3]), dd(x,y,z,[2,3]) $ + *(4)* #hl(`dd(x,y), dd(x,y,[2,3]), dd(x,y,z,[2,3])`) \ + $ dd(x,y), dd(x,y,[2,3]), dd(x,y,z,[2,3]) $ ], [ *(5)* #hl(`dd(x, y, z, [[1,1],rho+1,n_1])`) \ @@ -785,7 +793,7 @@ In the default font, the Typst built-in symbol `planck.reduce` $planck.reduce$ l [$ i hbar pdv(,t) psi = -frac(hbar^2, 2m) laplacian psi $], ) -=== Matrix transpose with superscript T +=== Matrix transpose with superscript T #v(1em) diff --git a/physica.typ b/physica.typ index 7f3ff2a..f0e3895 100644 --- a/physica.typ +++ b/physica.typ @@ -465,7 +465,11 @@ } let dsym = kwargs.at("d", default: $upright(d)$) - let prod = kwargs.at("p", default: none) + let compact = kwargs.at("compact", default: false) + // Why a very thin space is the default joiner: see TeXBook Chapter 18 p.168. + // math.thin is 1/6 em, and I decide this very thin space shall be slightly + // more than half of that. + let prod = kwargs.at("p", default: if compact { none } else { h(0.09em) }) let difference = var_num - orders.len() while difference > 0 { @@ -482,7 +486,10 @@ arr.push($dsym#var$) } } - $#arr.join(prod)$ + // Wrap in op(...) to give it smart spacing, just like Typst's built-in "dif" + // symbol. For example, there should be a space in the middle of "f(x) dx". + // See TeXBook Chapter 18 p.168. + $op(#arr.join(prod))$ } #let dd = differential diff --git a/typst.toml b/typst.toml index 79ba0dc..c666474 100644 --- a/typst.toml +++ b/typst.toml @@ -8,9 +8,10 @@ keywords = [ "physics", "mathematics", "brace", "set", "product", "evaluate", "restrict", "integral", "gradient", "divergence", "curl", "vector", "field", "laplacian", "matrix", "determinant", "diagonal", "identity", "Jacobian", "Hessian", - "Dirac", "braket", "differential", "derivative", "partial", "dv", "odv", - "pdv", "Planck", "hbar", "tensor", "isotope", "signal", "electromagnetism", - "mechanics", "quantum", "relativity", "imaginary", "notation", + "transpose", "Dirac", "braket", "differential", "derivative", "partial", + "dv", "odv", "pdv", "Planck", "hbar", "tensor", "isotope", "signal", + "electromagnetism", "mechanics", "quantum", "relativity", "imaginary", + "notation", ] compiler = "0.10.0" exclude = ["*.pdf", "*.py"]