Open connorferster opened 3 weeks ago
Glad to hear your in interest in the project!!
Initial roadblocks with your mathjax-full journey:
os
, process
, aren't available for use!You can sort of think of PythonMonkey more like a full JavaScript runtime, it just happens to be used as a Python library with easy to use high level bindings. Like other JavaScript runtimes, (Firefox, Chrome, Node, Bun, etc) there are compatibility issues between them due to different APIs being available.
HOWEVER!!!!!
If you're willing to put a little work into polyfilling the environment, you may be able to get things running smoothly which were originally meant to run in a different environment (like NodeJS or the browser) --- we did that to port https://socket.io/ to Python, and our Python SDK for distributed computing is also just a port of our JS SDK using PythonMonkey via polyfilling.
I played around with your example code but eventually came across errors due to mathjax-full
using Node standard libraries like path
. You may have more luck if you use the browser bundle https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js but when I tried it just now I got errors from the HTML dom not being present ): - so it'd have to take a little bit more work, or maybe some webpack incantations.
Wow! Thank you for such a detailed (and fast) response. I see the problem more clearly now. Thank you, again, for this response.
I played around with your example code but eventually came across errors due to mathjax-full using Node standard libraries like path.
How did you get around the export error to hit this error?
How did you get around the export error to hit this error?
I modified the code in the node module lol
I changed
export {init};
to
exports.init = init;
in file node_modules/mathjax-full/components/src/node-main/node-main.js
Not sure if that's the best path to start going down, but it's just something I played around with
Excellent, thank you!
Issue type
Bug
How did you install PythonMonkey?
Installed from pip
OS platform and distribution
Linux Ubuntu 22.04
Python version (
python --version
)3.11
PythonMonkey version (
pip show pythonmonkey
)1.0.0
Bug Description
Hi PythonMonkey maintainers!
I love what you have done with this library and have been following it for the last year (congrats on v1.0!). I am quite comfortable in Python but I am a Javascript noob (please bear with me).
My use case is to try and run mathjax from Python. Here is what I am trying to do (see First attempt, below).
This fails when it tries to access the
export {init}
from the "node-main.js" submodule. (See stack trace below).So, I tried creating an external submodule that executes
.init
within the Javascript (see Second attempt, below).This runs the init (success!) but gets stuck on the export within my "tex2svg.js" sub module.
Am I doing this wrong or is this actually a bug? Any help or insight is deeply appreciated.
Standalone code to reproduce the issue
First attempt
Second attempt
Relevant log output or backtrace
Second attempt (Using
pym.require("../tex2svg.js")
):Additional info if applicable
Here is the contents of my javascript submodule ("tex2svg.js"):
What branch of PythonMonkey were you developing on? (If applicable)
No response