Skip to content

Commit

Permalink
Spacing for differentials (TeXBook Chapter 18 p.168); touch up docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Leedehai committed Dec 22, 2023
1 parent f8a8b92 commit 7261f78
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion demo.typ
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified physica-manual.pdf
Binary file not shown.
22 changes: 15 additions & 7 deletions physica-manual.typ
Original file line number Diff line number Diff line change
Expand Up @@ -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`],
Expand Down Expand Up @@ -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(`...`)`])],
[],
Expand Down Expand Up @@ -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$.
Expand All @@ -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)`) \
Expand All @@ -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])`) \
Expand Down Expand Up @@ -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-tranpose>
=== Matrix transpose with superscript T <matrix-transpose>

#v(1em)

Expand Down
11 changes: 9 additions & 2 deletions physica.typ
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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

Expand Down
7 changes: 4 additions & 3 deletions typst.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 7261f78

Please sign in to comment.