Skip to content

Commit

Permalink
feat: latex-calculator script command
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Gleich <[email protected]>
  • Loading branch information
gleich authored and dehesa committed Feb 4, 2022
1 parent 33cee2c commit 578b713
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions commands/math/latex-calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3

# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title LaTeX Calculator
# @raycast.mode silent
# @raycast.packageName Math
#
# Optional parameters:
# @raycast.icon 🧮
# @raycast.argument1 { "type": "text", "placeholder": "\\frac{4}{2}}", "optional": true}
#
# Documentation:
# @raycast.description Evaluate LaTeX expressions and get the product copied to your clipboard
# @raycast.author Matt Gleich
# @raycast.authorURL https://mattglei.ch

import pyperclip
from sympy.parsing.latex import parse_latex
import sys

result = float(parse_latex(sys.argv[1]).evalf())

if result.is_integer():
result = round(result)

pyperclip.copy(result)
print(f"Copied {result} to clipboard")

0 comments on commit 578b713

Please sign in to comment.