Mr Pennyworth Posted November 6, 2020 Posted November 6, 2020 (edited) My fashcard software supports neither LaTeX nor MathML. Given that image is the only way to go, I created this workflow where you, Open Alfred Type ` (backtick) Start typing a math expression in AsciiMath syntax. As soon as you start typing, another window opens and it displays the typesetted math in real time as you type. Pressing enter closes both alfred and the math window, and puts a PNG image into clipboard. Instead of pressing enter, if you pressed command + enter, it copies LaTeX instead of the image to clipboard. Q: Why AsciiMath? A: Because it is extremely concise and intuitive. Check out this handy list of asciimath-vs-latex comparison examples. Q: What if I don't know how to write a particular thing in AsciiMath? A: If you are stuck in middle of typing, just stop, hit shift, and it'll pop up a reference. When done consulting the reference, hit escape again, and start typing from where you left off! (see gif below) Meta: A thing that I find exciting is this gives an example of a "rich preview as you type" workflow. Broad Technical details: custom protocol URLs: gives a cheap one-way-server functionality, ie, a way for alfred scripts to communicate with the running app, instead of launching an app every script invocation, or, running a server manually in the app (or some other complicated IPC scheme) monitor window events so that even if the user presses escape and quits the workflow without actioning, the math window can be hidden Download: AsciiMath.alfredworkflow Edited November 26, 2020 by Mr Pennyworth
Mr Pennyworth Posted November 6, 2020 Author Posted November 6, 2020 (edited) On 11/7/2020 at 1:43 AM, lynxlinius said: 10.14? Whoops! Thanks for pointing it out! Updated the workflow. Should work for 10.13 and up now, although I have no means of testing... Edited November 26, 2020 by Mr Pennyworth
RCL Posted November 15, 2020 Posted November 15, 2020 Thank you for this great workflow. I have been trying it but found that powers are not shown properly. For example, X^2 only shows x without the power. Is there a way to fix it? Thank you.
Mr Pennyworth Posted November 15, 2020 Author Posted November 15, 2020 @RCL I just tried x^2 and it did show correctly... can you run this command in terminal and confirm it just shows "x+y"? open -g "asciimath://render?x^2+y^2" Or, does it show x^2+y? Or, does it show x^2+y^2 correctly? Also make sure that "alfred filters results" is not checked in the workflow. (see screenshot)
RCL Posted November 16, 2020 Posted November 16, 2020 @ Mr Pennyworth The "alfred filters results" box is unchecked. When I try the command in the terminal, I got the message below. I am running Big Sur 11.0.1. Could it be the cause of the problem? Thank you. RCL@MBP ~ % open -g "asciimath://render?x^2+y^2" The file /Users/rcl/asciimath:/render?x^2+y^2 does not exist.
Mr Pennyworth Posted November 16, 2020 Author Posted November 16, 2020 @RCL hmm... yeah, it could be BigSur. I haven't tested on it. In the meanwhile, can you open the workflow folder in terminal (like in the screenshot) and then run the following command twice? open -a 'AsciiMath Renderer.app' 'asciimath://render?x^2+y^2' (on the first run, likely it won't show anything at all, hence twice) Basically, I want to figure out whether it has problem especially with powers or with anything that's longer that one letter... For that, it'll be awesome if you could try out something simple in alfred like "x+y=z" and see if renders or whether even in that case it is just "x"...
RCL Posted November 16, 2020 Posted November 16, 2020 I ran the way suggested and got the message below. Attached are screenshots that show equations properly. Thank you. RCL@MBP user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E % open -a 'AsciiMath Renderer.app' 'asciimath://render?x^2+y^2' The file /Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/asciimath:/render?x^2+y^2 does not exist. RCL@MBP user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E % open -a 'AsciiMath Renderer.app' 'asciimath://render?x^2+y^2' The file /Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/asciimath:/render?x^2+y^2 does not exist.
Mr Pennyworth Posted November 16, 2020 Author Posted November 16, 2020 @RCL hmm... that's very strange! both the parts about the terminal commands not working, and about the workflow still showing "x+y=z" I don't have access to a BigSur machine, but here's a last thing to try: 1. In the workflow, right-click on the script filter, and post a screenshot here so that I can double-check the exact code you're running 2. Keeping the debugger open, try "x^2+y^2" inside alfred and let me know what it renders and also the full text of the debugging output.
RCL Posted November 16, 2020 Posted November 16, 2020 Attached are screenshots. The debug message is as follows. Thank you. [11:11:10.427] AsciiMath[Script Filter] Queuing argument 'x^2+y^2' [11:11:10.459] AsciiMath[Script Filter] Script with argv 'x^2+y^2' finished [11:11:10.463] STDERR: AsciiMath[Script Filter] The file /Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/asciimath:/render?x^2+y^2 does not exist. [11:11:10.464] AsciiMath[Script Filter] {"items": [ { "title": "Copy Math", "subtitle": "as Image (⌘: as LaTeX)", "arg": "copyImage", "quicklookurl": "/Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/AsciiMath.html", "mods": { "cmd": { "subtitle": "as LaTeX", "arg": "copyLatex" } } } ]} [11:11:13.641] AsciiMath[Script Filter] Queuing argument 'X' [11:11:13.728] AsciiMath[Script Filter] Script with argv 'X' finished [11:11:13.728] AsciiMath[Script Filter] {"items": [ { "title": "Copy Math", "subtitle": "as Image (⌘: as LaTeX)", "arg": "copyImage", "quicklookurl": "/Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/AsciiMath.html", "mods": { "cmd": { "subtitle": "as LaTeX", "arg": "copyLatex" } } } ]} [11:11:15.739] AsciiMath[Script Filter] Queuing argument 'x' [11:11:15.891] AsciiMath[Script Filter] Script with argv 'x' finished [11:11:15.895] AsciiMath[Script Filter] {"items": [ { "title": "Copy Math", "subtitle": "as Image (⌘: as LaTeX)", "arg": "copyImage", "quicklookurl": "/Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/AsciiMath.html", "mods": { "cmd": { "subtitle": "as LaTeX", "arg": "copyLatex" } } } ]} [11:11:16.401] AsciiMath[Script Filter] Queuing argument 'x^' [11:11:16.492] AsciiMath[Script Filter] Script with argv 'x^' finished [11:11:16.496] STDERR: AsciiMath[Script Filter] The file /Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/asciimath:/render?x^ does not exist. [11:11:16.497] AsciiMath[Script Filter] {"items": [ { "title": "Copy Math", "subtitle": "as Image (⌘: as LaTeX)", "arg": "copyImage", "quicklookurl": "/Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/AsciiMath.html", "mods": { "cmd": { "subtitle": "as LaTeX", "arg": "copyLatex" } } } ]} [11:11:16.625] AsciiMath[Script Filter] Queuing argument 'x^2' [11:11:16.653] AsciiMath[Script Filter] Script with argv 'x^2' finished [11:11:16.663] STDERR: AsciiMath[Script Filter] The file /Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/asciimath:/render?x^2 does not exist. [11:11:16.664] AsciiMath[Script Filter] {"items": [ { "title": "Copy Math", "subtitle": "as Image (⌘: as LaTeX)", "arg": "copyImage", "quicklookurl": "/Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/AsciiMath.html", "mods": { "cmd": { "subtitle": "as LaTeX", "arg": "copyLatex" } } } ]} [11:11:18.073] AsciiMath[Script Filter] Queuing argument 'x^2+' [11:11:18.103] AsciiMath[Script Filter] Script with argv 'x^2+' finished [11:11:18.113] STDERR: AsciiMath[Script Filter] The file /Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/asciimath:/render?x^2+ does not exist. [11:11:18.115] AsciiMath[Script Filter] {"items": [ { "title": "Copy Math", "subtitle": "as Image (⌘: as LaTeX)", "arg": "copyImage", "quicklookurl": "/Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/AsciiMath.html", "mods": { "cmd": { "subtitle": "as LaTeX", "arg": "copyLatex" } } } ]} [11:11:18.819] AsciiMath[Script Filter] Queuing argument 'x^2+y' [11:11:18.909] AsciiMath[Script Filter] Script with argv 'x^2+y' finished [11:11:18.918] STDERR: AsciiMath[Script Filter] The file /Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/asciimath:/render?x^2+y does not exist. [11:11:18.919] AsciiMath[Script Filter] {"items": [ { "title": "Copy Math", "subtitle": "as Image (⌘: as LaTeX)", "arg": "copyImage", "quicklookurl": "/Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/AsciiMath.html", "mods": { "cmd": { "subtitle": "as LaTeX", "arg": "copyLatex" } } } ]} [11:11:19.425] AsciiMath[Script Filter] Queuing argument 'x^2+y^' [11:11:19.515] AsciiMath[Script Filter] Script with argv 'x^2+y^' finished [11:11:19.524] STDERR: AsciiMath[Script Filter] The file /Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/asciimath:/render?x^2+y^ does not exist. [11:11:19.525] AsciiMath[Script Filter] {"items": [ { "title": "Copy Math", "subtitle": "as Image (⌘: as LaTeX)", "arg": "copyImage", "quicklookurl": "/Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/AsciiMath.html", "mods": { "cmd": { "subtitle": "as LaTeX", "arg": "copyLatex" } } } ]} [11:11:19.705] AsciiMath[Script Filter] Queuing argument 'x^2+y^2' [11:11:19.796] AsciiMath[Script Filter] Script with argv 'x^2+y^2' finished [11:11:19.807] STDERR: AsciiMath[Script Filter] The file /Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/asciimath:/render?x^2+y^2 does not exist. [11:11:19.808] AsciiMath[Script Filter] {"items": [ { "title": "Copy Math", "subtitle": "as Image (⌘: as LaTeX)", "arg": "copyImage", "quicklookurl": "/Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.F62AE381-F57E-4939-AA70-79FA9026916E/AsciiMath.html", "mods": { "cmd": { "subtitle": "as LaTeX", "arg": "copyLatex" } } } ]}
Mr Pennyworth Posted November 16, 2020 Author Posted November 16, 2020 Thanks @RCL for the log! Because I have no way of testing as I'm not on BigSur, this is just a guess, but I think I have a fix open -g "asciimath://render?x%5E2%2Bz%5E2" Try the above command in terminal and see if it works. If it does, I'll accordingly update the workflow.
Mr Pennyworth Posted November 16, 2020 Author Posted November 16, 2020 (edited) @RCL, Assuming that indeed was the problem, I've updated the workflow. Re-download using the same link and see if it is fixed? Edited November 26, 2020 by Mr Pennyworth
RCL Posted November 16, 2020 Posted November 16, 2020 It works now! Thank you so much for your workflow and time!
saivan Posted October 21, 2021 Posted October 21, 2021 I literally just made an account to say THANK YOU SO MUCH for this. It's so good! When I save the image, the resolution isn't so good and the background isn't transparent. Any idea about how I can fix that?
JJGordo Posted November 4, 2021 Posted November 4, 2021 Hi @Mr Pennyworth. Absolutely love this workflow; thank you! Unfortunately, I'm having an issue. The workflow functioned as intended for a day, however now the render/typesetting window no longer pops up. Also, without it, I can't copy the PNG or the LaTeX. Any help would be much appreciated!
JJGordo Posted November 5, 2021 Posted November 5, 2021 As a follow-up, it turns out AsciiMath Renderer has been crashing on me every time it tries to run. I have verified this in the macOS console logs. No idea what the issue is...
deanishe Posted November 5, 2021 Posted November 5, 2021 7 hours ago, JJGordo said: As a follow-up, it turns out AsciiMath Renderer has been crashing on me every time it tries to run. I have verified this in the macOS console logs. No idea what the issue is... And what did the logs say? Are you getting an error message in Alfred’s workflow debugger? We certainly have no idea what's going on on your Mac, and we can't help you if you don't give us more information than "X is crashing".
JJGordo Posted November 5, 2021 Posted November 5, 2021 (edited) Hi @deanishe. I'm not as adept as others here, sorry. Attached is a screenshot of the Alfred debugger (where I don't see it catching anything?) as well as the console log: Text version of console log: ------------------------------------- Translated Report (Full Report Below) ------------------------------------- Process: AsciiMath Renderer [21875] Path: /Users/USER/Library/Application Support/Alfred/*/AsciiMath Renderer.app/Contents/MacOS/AsciiMath Renderer Identifier: mr.pennyworth.AsciiMathRenderer Version: 0.0.8 (1) Code Type: X86-64 (Native) Parent Process: launchd [1] User ID: 501 Date/Time: 2021-11-05 11:15:52.8523 -0400 OS Version: macOS 12.0.1 (21A559) Report Version: 12 Bridge OS Version: 6.0 (19P548) Anonymous UUID: 4D86192D-FA14-0F5A-A234-6211E3EA13D5 Sleep/Wake UUID: C2F701DB-62DF-4E4F-8D4E-D009D6F3632C Time Awake Since Boot: 73000 seconds Time Since Wake: 1424 seconds System Integrity Protection: enabled Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_BAD_INSTRUCTION (SIGILL) Exception Codes: 0x0000000000000001, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Termination Reason: Namespace SIGNAL, Code 4 Illegal instruction: 4 Terminating Process: exc handler [21875] Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 AsciiMath Renderer 0x109dc6d39 globalinit_33_9029708ADB81389A80B02D410BB30023_func11 + 329 1 libdispatch.dylib 0x7ff80f4a1cc9 _dispatch_client_callout + 8 2 libdispatch.dylib 0x7ff80f4a2ec1 _dispatch_once_callout + 20 3 AsciiMath Renderer 0x109dc9744 globalinit_33_B5244C1962C1E149A3A2E7710EC309D5_func14 + 276 4 libdispatch.dylib 0x7ff80f4a1cc9 _dispatch_client_callout + 8 5 libdispatch.dylib 0x7ff80f4a2ec1 _dispatch_once_callout + 20 6 AsciiMath Renderer 0x109dcbf08 specialized static PressSecretary.enable() + 232 7 AsciiMath Renderer 0x109dca849 static Alfred.onHide(callback:) + 41 8 AsciiMath Renderer 0x109dc1b16 AppDelegate.applicationDidFinishLaunching(_:) + 1270 9 AsciiMath Renderer 0x109dc1dab @objc AppDelegate.applicationDidFinishLaunching(_:) + 107 10 CoreFoundation 0x7ff80f714e73 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12 11 CoreFoundation 0x7ff80f7b2349 ___CFXRegistrationPost_block_invoke + 49 12 CoreFoundation 0x7ff80f7b22c6 _CFXRegistrationPost + 496 13 CoreFoundation 0x7ff80f6e6786 _CFXNotificationPost + 733 14 Foundation 0x7ff81052e996 -[NSNotificationCenter postNotificationName:object:userInfo:] + 82 15 AppKit 0x7ff81215118b -[NSApplication _postDidFinishNotification] + 305 16 AppKit 0x7ff812150edd -[NSApplication _sendFinishLaunchingNotification] + 208 17 AppKit 0x7ff81214eab0 -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 541 18 AppKit 0x7ff81214e707 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 665 19 Foundation 0x7ff81055a284 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 308 20 Foundation 0x7ff81055a0f6 _NSAppleEventManagerGenericHandler + 80 21 AE 0x7ff815d9bd28 0x7ff815d90000 + 48424 22 AE 0x7ff815d9b592 0x7ff815d90000 + 46482 23 AE 0x7ff815d949c7 aeProcessAppleEvent + 419 24 HIToolbox 0x7ff81834cb42 AEProcessAppleEvent + 54 25 AppKit 0x7ff812148d8a _DPSNextEvent + 2064 26 AppKit 0x7ff812146f5c -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1411 27 AppKit 0x7ff812139359 -[NSApplication run] + 586 28 AsciiMath Renderer 0x109dc2a86 closure #1 in + 294 29 AsciiMath Renderer 0x109dc2abe specialized thunk for @callee_guaranteed () -> (@error @owned Error) + 14 30 libswiftObjectiveC.dylib 0x7ff8243e9e6c autoreleasepool<A>(invoking:) + 44 31 AsciiMath Renderer 0x109dc1033 main + 35 32 dyld 0x10d8994fe start + 462 Edited November 5, 2021 by JJGordo
xgo Posted November 10, 2021 Posted November 10, 2021 This looked like an interesting workflow and I tried installing and got a very similar error - no quickview lookup when typing a formula, nothing concrete coming out of Alfred debugger, but an actual crash log for AsciiMathRenderer every time its called. Very similar error log, pasting screencap of top section for context
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now