Skip to content

Commit

Permalink
Update to v0.8.0
Browse files Browse the repository at this point in the history
Handled breaking changes introduced by Typst 0.8.0
  • Loading branch information
Leedehai committed Sep 13, 2023
1 parent 68881ff commit 5d0dc5d
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
tags:
- "v*.*.*"

permissions:
permissions:
contents: write

jobs:
Expand Down
47 changes: 26 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# The physica module (for physics)

[![CI](https://github.com/Leedehai/typst-physics/actions/workflows/ci.yml/badge.svg)](https://github.com/Leedehai/typst-physics/actions/workflows/ci.yml)
[![Latest release date](https://img.shields.io/github/release-date/Leedehai/typst-physics)][latest-release]
[![Latest release](https://img.shields.io/github/v/release/Leedehai/typst-physics.svg?color=gold)][latest-release]

Current semantic version: `0.7`. [Manual](physica-manual.pdf).
The [manual](physica-manual.pdf).
Download releases [here](https://github.com/Leedehai/typst-physics/releases/).

Available at [https://typst.app/docs/packages/](https://typst.app/docs/packages/).
Available at the official collection of [Typst packages](https://typst.app/docs/packages/).

This [Typst](https://typst.app) package provides handy typesetting utilities for
physics, including:
Expand Down Expand Up @@ -37,29 +38,34 @@ See the [manual](physica-manual.pdf) for more details.

See https://github.com/typst/packages.

<p align="center">
<img src="https://github.com/Leedehai/typst-physics/assets/18319900/f2a3a2bd-3ef7-4383-ab92-9a71affb4e12" width="173" alt="effect">
</p>

```
#import "@preview/physica:0.7.5": *
// Style 1
#import "@preview/physica:0.8.0": *
$op("curl")(op("grad") f) = curl (grad f)$
$ curl (grad f), tensor(T, -mu, +nu), pdv(f,x,y,[1,2]) $
```

### Without `typst` package management
```
// Style 2
#import "@preview/physica:0.8.0": curl, grad, tensor, pdv
* To use the `physica` package, simply insert `#import "physica.typ": *` at the
beginning of your document.
* To reduce the possibility of name collisions, you may want to import the
package under name scope `physica`:
```
#import "physica.typ"
$ curl (grad f), tensor(T, -mu, +nu), pdv(f,x,y,[1,2]) $
```

$op("curl")(op("grad") f) = physica.curl (physica.grad f)$
```
* You may also import names specifically:
```
#import "physica.typ": curl, grad
```
// Style 3
#import "@preview/physica:0.8.0"
$ physica.curl (physica.grad f), physica.tensor(T, -mu, +nu), physica.pdv(f,x,y,[1,2]) $
```

### Without `typst` package management

$op("curl")(op("grad") f) = curl (grad f)$
```
Similar to examples above, but import with the undecorated file path like `"physica.typ"`.

## Manual

Expand All @@ -70,7 +76,7 @@ CLI Version:

```sh
$ typst --version
typst 0.6.0 (2dfd44fe)
typst 0.8.0 (360cc9b9)
```

To regenerate the manual, use command
Expand All @@ -97,4 +103,3 @@ testing by comparing rendered pictures with golden images.
* Docs: the [Creative Commons BY-ND 4.0 license](https://creativecommons.org/licenses/by-nd/4.0/).

[latest-release]: https://github.com/Leedehai/typst-physics/releases/latest "The latest release"
[latest-manual]: https://github.com/Leedehai/typst-physics/releases/latest/download/physica-manual.pdf "Download the latest manual"
Binary file modified physica-manual.pdf
Binary file not shown.
16 changes: 9 additions & 7 deletions physica-manual.typ
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023 Leedehai
// This document is shared under the Creative Commons BY-ND 4.0 license.

#let version = "0.7.5"
#let version = "0.8.0"

#set page(
numbering: "1/1",
Expand All @@ -22,8 +22,8 @@
]

#align(center)[
Version #version, July 30, 2023 \
Doc updated: July 30, 2023
Version #version, September 12, 2023 \
Doc updated: September 12, 2023
]

#set par(justify: true)
Expand Down Expand Up @@ -52,18 +52,20 @@ 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": *

```
#import "@preview/physica:0.7.5": *
#import "@preview/physica:0.8.0": *
$op("curl")(op("grad") f) = curl (grad f)$
$ curl (grad f), tensor(T, -mu, +nu), pdv(f,x,y,[1,2]) $
```

$ curl (grad f), tensor(T, -mu, +nu), pdv(f,x,y,[1,2]) $

= The symbols

#v(1em)

#import "physica.typ": *

// Put the superscript *before* the symbol, in case there are symbols after it.
#let builtin(symbol) = [#super(text(fill: blue, "typst "))#symbol]

Expand Down
58 changes: 29 additions & 29 deletions physica.typ
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

// Given a Content generated from lr(), return the array of sub Content objects.
// Example: "[1,a_1,(1,1),n+1]" => "1", "a_1", "(1,1)", "n+1"
#let __extract_array_contents(content) = {
assert(type(content) == "content", message: "expecting a content type input")
if content.func() != math.lr { return none }
#let __extract_array_contents(input) = {
assert(type(input) == content, message: "expecting a content type input")
if input.func() != math.lr { return none }
// A Content object made by lr() definitely has a "body" field, and a
// "children" field underneath it. It holds an array of Content objects,
// starting with a Content holding "(" and ending with a Content holding ")".
let children = content.at("body").at("children")
let children = input.at("body").at("children")

let result_elements = () // array of Content objects

Expand Down Expand Up @@ -45,7 +45,7 @@

// A bare-minimum-effort symbolic addition.
#let __bare_minimum_effort_symbolic_add(elements) = {
assert(type(elements) == "array", message: "expecting an array of content")
assert(type(elements) == array, message: "expecting an array of content")
let operands = () // array
for e in elements {
if not e.has("children") {
Expand Down Expand Up @@ -161,7 +161,7 @@
} else {
math.italic(e)
}
if type(a) == "content" and a.func() == math.attach {
if type(a) == content and a.func() == math.attach {
math.attach(
math.accent(maybe_bold(a.base), accent),
t: if a.has("t") { maybe_bold(a.t) } else { none },
Expand Down Expand Up @@ -246,7 +246,7 @@

#let identitymatrix(order, delim:"(", fill:none) = {
let order_num = 1
if type(order) == "content" and __content_holds_number(order) {
if type(order) == content and __content_holds_number(order) {
order_num = int(order.text)
} else {
panic("the order shall be an integer, e.g. 2")
Expand All @@ -259,7 +259,7 @@

#let zeromatrix(order, delim:"(") = {
let order_num = 1
if type(order) == "content" and __content_holds_number(order) {
if type(order) == content and __content_holds_number(order) {
order_num = int(order.text)
} else {
panic("the order shall be an integer, e.g. 2")
Expand All @@ -271,8 +271,8 @@
#let zmat = zeromatrix

#let jacobianmatrix(fs, xs, delim:"(") = {
assert(type(fs) == "array", message: "expecting an array of function names")
assert(type(xs) == "array", message: "expecting an array of variable names")
assert(type(fs) == array, message: "expecting an array of function names")
assert(type(xs) == array, message: "expecting an array of variable names")
let arrays = () // array of arrays
for f in fs {
arrays.push(xs.map((x) => math.frac($diff#f$, $diff#x$)))
Expand All @@ -282,10 +282,10 @@
#let jmat = jacobianmatrix

#let hessianmatrix(fs, xs, delim:"(") = {
assert(type(fs) == "array", message: "expecting a one-element array")
assert(type(fs) == array, message: "expecting a one-element array")
assert(fs.len() == 1, message: "expecting only one function name")
let f = fs.at(0)
assert(type(xs) == "array", message: "expecting an array of variable names")
assert(type(xs) == array, message: "expecting an array of variable names")
let row_arrays = () // array of arrays
let order = xs.len()
for r in range(order) {
Expand All @@ -306,19 +306,19 @@

#let xmatrix(m, n, func, delim:"(") = {
let rows = none
if type(m) == "content" and __content_holds_number(m) {
if type(m) == content and __content_holds_number(m) {
rows = int(m.text)
} else {
panic("the first argument shall be an integer, e.g. 2")
}
let cols = none
if type(n) == "content" and __content_holds_number(m) {
if type(n) == content and __content_holds_number(m) {
cols = int(n.text)
} else {
panic("the second argument shall be an integer, e.g. 2")
}
assert(
type(func) == "function",
type(func) == function,
message: "func shall be a function (did you forget to add a preceding '#' before the function name)?"
)
let row_arrays = () // array of arrays
Expand Down Expand Up @@ -349,7 +349,7 @@
let ket = args.at(1, default: bra)

let height = measure($ bra ket $, styles).height;
let phantom = box(height: height, width: 0pt, inset: 0pt, stroke: none);
let phantom = box(height: height * 0.8, width: 0pt, inset: 0pt, stroke: none);
$ lr(angle.l bra lr(|phantom#h(0pt)) ket angle.r) $
})

Expand All @@ -363,8 +363,8 @@
let ket = args.at(1, default: bra)

let height = measure($ bra ket $, styles).height;
let phantom = box(height: height, width: 0pt, inset: 0pt, stroke: none);
$ lr(|bra#h(0pt)phantom angle.r)lr(angle.l phantom#h(0pt)ket|) $
let phantom = box(height: height * 0.8, width: 0pt, inset: 0pt, stroke: none);
$ lr(bar.v bra#h(0pt)phantom angle.r)lr(angle.l phantom#h(0pt)ket bar.v) $
})

#let innerproduct = braket
Expand All @@ -376,8 +376,8 @@
// 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, width: 0pt, inset: 0pt, stroke: none);
$ lr(angle.l #n |#M#h(0pt)phantom| #m angle.r) $
let phantom = box(height: height * 0.8, width: 0pt, inset: 0pt, stroke: none);
$ lr(angle.l #n lr(|#M#h(0pt)phantom|) #m angle.r) $
})

#let mel = matrixelement
Expand Down Expand Up @@ -439,7 +439,7 @@
let var_num = args.len()
let default_order = [1] // a Content holding "1"
let last = args.at(args.len() - 1)
if type(last) == "content" {
if type(last) == content {
if last.func() == math.lr and last.at("body").at("children").at(0) == [\[] {
var_num -= 1
orders = __extract_array_contents(last) // array
Expand All @@ -448,7 +448,7 @@
default_order = last // treat as a single element
orders.push(default_order)
}
} else if type(last) == "integer" {
} else if type(last) == int {
var_num -= 1
default_order = [#last] // make it a Content
orders.push(default_order)
Expand Down Expand Up @@ -485,7 +485,7 @@

#let __combine_var_order(var, order) = {
let naive_result = math.attach(var, t: order)
if type(var) != "content" or var.func() != math.attach {
if type(var) != content or var.func() != math.attach {
return naive_result
}

Expand Down Expand Up @@ -545,7 +545,7 @@

// The last argument might be the order numbers, let's check.
let last = args.at(args.len() - 1)
if type(last) == "content" {
if type(last) == content {
if last.func() == math.lr and last.at("body").at("children").at(0) == [\[] {
var_num -= 1
orders = __extract_array_contents(last) // array
Expand All @@ -554,7 +554,7 @@
default_order = last
orders.push(default_order)
}
} else if type(last) == "integer" {
} else if type(last) == int {
var_num -= 1
default_order = [#last] // make it a Content
orders.push(default_order)
Expand Down Expand Up @@ -642,7 +642,7 @@
} else {
([+], sym.square)
}
assert(type(tuple) == "array", message: "shall be array")
assert(type(tuple) == array, message: "shall be array")

let pos = tuple.at(0)
let symbol = if tuple.len() >= 2 {
Expand Down Expand Up @@ -737,12 +737,12 @@
}
}

#let signals(str, step: 1em, color: black) = {
assert(type(str) == "string", message: "input needs to be a string")
#let signals(input, step: 1em, color: black) = {
assert(type(input) == str, message: "input needs to be a string")

let elements = () // array
let previous = " "
for e in str {
for e in input {
if e == " " { continue; }
if e == "." {
elements.push(__signal_element(previous, step, color))
Expand Down
5 changes: 3 additions & 2 deletions typst.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "physica"
version = "0.7.5"
version = "0.8.0"
entrypoint = "physica.typ"
license = "MIT"
description = "Physics: derivative, differential, field, matrix, braket, tensor, etc."
description = "Physics: derivative, differential, field, matrix, braket, tensor, hbar, etc."
authors = ["Leedehai"]
repository = "https://github.com/Leedehai/typst-physics"
keywords = [
Expand All @@ -12,4 +12,5 @@ keywords = [
"differential", "derivative", "partial", "dv", "odv", "pdv", "Planck", "hbar",
"tensor", "isotope", "signal", "electromagnetism", "mechanics", "quantum",
]
compiler = "0.8.0"
exclude = ["*.pdf", "*.py"]

0 comments on commit 5d0dc5d

Please sign in to comment.