Jump to content

Display math equations in Alfred?


Recommended Posts

Hey guys! ;)

First: English isn't my native language, so I'm sorry for some unconventional writing. Secondly: I just started with the amazing capabilities of Alfred Workflows and im not really in that coding stuff, but I will give my best. So be kind of fair with me.^^
---
My goal so far: I want to calculate Stuff via Sympy in Python and display the result in Alfred.

My problem: JSON doesn't support the latex output of Sympy (seems so).

My Question: Is there something I dismiss or just did wrong? Or is there a completly other possibility to do it? 

I will give you a short example of what I did before (it's just like a minimal-example):

 

My Python file:

 

import json
import sys
import sympy as sym
 
args = sys.argv[1]
 
x = sym.symbols('x')
 
result = {"items": [
{
"type": "file",
"title": x,
"subtitle": "... is the solution for the given equation.",
"arg": x
}
]}
 
finalResult = json.dumps(result)
 
print(finalResult)

 

My Script:

 

python3 /Users/ma***/Desktop/temp/testfile.py "{query}"

 

The supposed error as I mentioned before:

 

TypeError: Object of type Symbol is not JSON serializable.

 

Note: I just want no additionally window that opens and that I need to close manually. Something like the AsciiMath did would be okay.

 

I hope you can understand my Problem and we can find a solution!

 

Thanks! :)

Link to comment

Hey Vitor! ;)

That has solved my current problem. Thanks for that!
 

But how its likely, by solving one Problem there comes another across:

 

I have no clue, how I can receive the input from Alfred just as it typed.

Just like: 

 

image.png.f8bd1fbd0ece4744784a030f59fec49c.png

 

(this was manually written down in the Code)

 

But if I try it with that with my code:

 

import json
import sys
import sympy as sym
 
args = sys.argv[1:]
 
x = sym.symbols('x')
y = sym.solve(args,x)
 
result = {"items": [
{
"type": "file",
"title": str(y),
"subtitle": "... is the solution for the given equation.",
"arg": str(y)
}
]}
 
finalResult = json.dumps(result)
 
print(finalResult)

 

it gives me:

 

 image.png.c70b66090454711d88e2290f8f04feff.png

 

doesn't matter what I haved typed in.

 

Debug:

 

[12:19:31.817] Sympy: Solving Equations with 1 unknown Variable[Script Filter] Queuing argument 'x'
[12:19:32.086] Sympy: Solving Equations with 1 unknown Variable[Script Filter] Script with argv '(null)' finished
[12:19:32.089] Sympy: Solving Equations with 1 unknown Variable[Script Filter] {"items": [{"type": "file", "title": "[]", "subtitle": "... is the solution for the given equation.", "arg": "[]"}]}
[12:19:33.494] Sympy: Solving Equations with 1 unknown Variable[Script Filter] Queuing argument 'x+'
[12:19:33.602] Sympy: Solving Equations with 1 unknown Variable[Script Filter] Queuing argument 'x+2'
[12:19:33.699] Sympy: Solving Equations with 1 unknown Variable[Script Filter] Script with argv '(null)' finished
[12:19:33.702] Sympy: Solving Equations with 1 unknown Variable[Script Filter] {"items": [{"type": "file", "title": "[]", "subtitle": "... is the solution for the given equation.", "arg": "[]"}]}

 

The Queuing Argument seems to be right.

 

I have the guess, that the input isn't the right data-type.

 

Hope you can help me once again.

 

Thanks!

 

Link to comment
  • 8 months later...

If you're using Sympy in Python to perform calculations and you want to display the results in Alfred, JSON might not be the best option for directly supporting the latex output of Sympy here. JSON is primarily used for data interchange and may not have built-in support for complex text formatting like latex. However, there are other possibilities you can explore. One option is to convert the latex output from Sympy into an image format (such as PNG or SVG) and then display that image in Alfred. You can use libraries like Matplotlib or Pillow in Python to generate the image representation of the latex equation.

Edited by andreles
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...