-
Notifications
You must be signed in to change notification settings - Fork 0
/
typst-sympy-calculator.typ
83 lines (72 loc) · 1.57 KB
/
typst-sympy-calculator.typ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#let hidden(content) = {}
// matrix
#let cmat(..args) = {
let mat = if (type(args.pos().at(0)) != "array") { (args.pos(),) } else { args.pos() }
let mat_t = ()
for j in range(mat.at(0).len()) {
mat_t.push(())
for i in range(mat.len()) {
mat_t.at(j).push(mat.at(i).at(j))
}
}
math.mat(..mat_t)
}
#let eye(n) = {
let n = if (type(n) == "content") { int(n.text) } else { int(n) }
let matrix = ()
for i in range(n) {
matrix.push(())
for j in range(n) {
if (i == j) {
matrix.at(i).push(1)
} else {
matrix.at(i).push(0)
}
}
}
math.mat(..matrix)
}
#let diag(..args) = {
let args = args.pos()
let n = args.len()
let matrix = ()
for i in range(n) {
matrix.push(())
for j in range(n) {
if (i == j) {
matrix.at(i).push(args.at(j))
} else {
matrix.at(i).push(0)
}
}
}
math.mat(..matrix)
}
// functions
#let derivative(expr, var) = $(dif)/(dif var) expr$
#let sign = math.op("sign")
#let evalat(body) = math.lr(body + "|")
// accents
#let hdot(a) = math.accent(a, math.dot)
#hidden[
```typst-calculator
@func_mat()
def convert_cmat(matrix):
return sympy.Matrix(matrix).T
@func()
def convert_derivative(expr, var):
return sympy.Derivative(expr, var)
@func()
def convert_eye(n):
return sympy.eye(n)
@func()
def convert_diag(*args):
return sympy.diag(*args)
@func()
def convert_sign(a):
return sympy.sign(a)
```
]
$
(x + 1) exp(-x)
$