Skip to content

Commit 1d4a160

Browse files
authored
Merge pull request #227 from Vampir0/main
Add mathcalc package
2 parents 527fbac + 790a3b6 commit 1d4a160

3 files changed

Lines changed: 67 additions & 0 deletions

File tree

packages/mathcalc/0.1.0/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Math Calculator for Espanso
2+
3+
Evaluate math expressions inline using Python's math engine.
4+
5+
**Requires Python installed on the system.**
6+
7+
## Triggers
8+
9+
| Trigger | Output | Example |
10+
|---------|--------|---------|
11+
| `:calc` | Result only | `1013.5` |
12+
| `:xcalc` | Expression = Result | `(10^3) + sqrt(144) = 1012` |
13+
14+
## Supported operations
15+
16+
- Basic: `+`, `-`, `*`, `/`
17+
- Power: `^` or `**`
18+
- `sqrt(x)`, `pow(x, y)`
19+
- `sin(x)`, `cos(x)`, `tan(x)`, `asin`, `acos`, `atan`
20+
- `log(x)`, `log2(x)`, `log10(x)`
21+
- `ceil(x)`, `floor(x)`, `factorial(x)`
22+
- Constants: `pi`, `e`, `tau`
23+
- Parentheses and nested expressions
24+
25+
## Examples
26+
27+
- `(19+1)^2``400`
28+
- `sqrt(144)``12`
29+
- `sin(pi/2)``1`
30+
- `log10(1000)``3`
31+
- `factorial(6)``720`
32+
- `(sqrt(2)+1)^2``5.828427124`
33+
34+
## Reference
35+
36+
Full list of available functions: https://docs.python.org/3/library/math.html
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: "mathcalc"
2+
title: "Math Calculator"
3+
description: Inline math calculator with full Python math support. Evaluate expressions with +, -, *, /, ^, sqrt, sin, cos, tan, log, factorial and more.
4+
version: 0.1.0
5+
author: Matt
6+
tags: ["math", "calculator", "python", "utility"]
7+
homepage: "https://github.com/Vampir0"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
global_vars:
2+
- name: "input"
3+
type: "form"
4+
params:
5+
layout: |
6+
Enter expression (e.g. (19+1)^2): [[val]]
7+
- name: result
8+
type: script
9+
params:
10+
args:
11+
- python
12+
- -c
13+
- |
14+
from math import *
15+
x = '{{input.val}}'.replace('^', '**')
16+
r = eval(x)
17+
print(int(r) if r == int(r) else round(r, 10))
18+
19+
matches:
20+
- trigger: ":calc"
21+
replace: "{{result}}"
22+
23+
- trigger: ":xcalc"
24+
replace: "{{input.val}} = {{result}}"

0 commit comments

Comments
 (0)