VPython MathJax-Error

56 views
Skip to first unread message

TKS

unread,
Feb 4, 2018, 3:07:35 PM2/4/18
to VPython-users
I tried to include LaTeX in a vpython program

http://www.glowscript.org/docs/VPythonDocs/MathJax.html

Code:

from vpython import *
box()
scene.title = "\\(\\dfrac {5} {7} \\)"
MathJax.Hub.Queue(["Typeset",MathJax.Hub])

Result:
Traceback (most recent call last):
  File "D:/TKSHDa/Python/NewmannMadelung/vpython_mathjaxbox.py", line 12, in <module>
    MathJax.Hub.Queue(["Typeset",MathJax.Hub])
NameError: name 'MathJax' is not defined

Environment:
Windows 10 64Bit, Python 3.6.3, vpython ['7.3.2', 'jupyter'] ['2.6', 'glowscript'], called from IDLE in Firefox 58.01

Bruce Sherwood

unread,
Feb 4, 2018, 4:44:27 PM2/4/18
to VPython-users
Oops. The documentation needs to say that this only works (at least at present) in GlowScript VPython, not VPython 7. 

Note that in a Jupyter notebook there are mechanisms for displaying LaTeX.

Thanks for the report.

Bruce

TKS

unread,
Feb 5, 2018, 12:56:36 AM2/5/18
to VPython-users
Thanks for the clarification.

Importing MathJax manually works as a workaround :-)

scene.title = "<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML'></script>"
scene.title += "\\(\\dfrac {5} {7} \\)"

Bruce Sherwood

unread,
Feb 5, 2018, 9:40:35 AM2/5/18
to VPython-users
That's kind of amazing. I wouldn't have thought of that. You've convinced me that I should get MathJax into VPython 7. Thanks!

Bruce

TKS

unread,
Feb 6, 2018, 1:15:43 AM2/6/18
to VPython-users
When I am thinking about it I come to the question wether or not it would be helpful to have more access to html-control.

So far I found scene.title and scene.caption as anchor points on the page.

What ist about organizing Informations above and below interactive elements?

From my question you might see that so far I haven't got the whole picture, i.e. the relation between glowsript and vpython - How would I publish examples myself on a webserver?

Having MathJax would be very helpful and in addition allowing more anchor points as well.

Thanks again for your work!!!

Bruce Sherwood

unread,
Feb 6, 2018, 10:37:51 AM2/6/18
to VPython-users
Here is a technical overview of the relationship between VPython 7 and GlowScript VPython:


An earlier presentation on Jupyter VPython and GlowScript VPython is here:


Both of these links are available at vpython.org.

Concerning publishing your program: If you do not need to import Python modules other than vpython, the simplest publication scheme is to place your program at glowscript.org, run it, and publish the URL you will see while running. You can also on the glowscript.org edit page export the compiled (JavaScript) version of your program and insert it in your own web page. You can also reference a GlowScript program like this on your own web page:

<div>This is a test.</div>
<div>It is only a test.</div>

If you save this minimal code in a file with the extension .html, then double-click the file to invoke a browser, it will run.

Publishing a Python 7 program involves other considerations. One option is to use a Jupyter notebook and use the Jupyter mechanisms for publishing a program. I've not tried it myself, but presumably you could modify the VPython 7 machinery to run your Python program on your own server (as opposed to the standard use of a local server) and communicate with the GlowScript library running in a remote client.

As for your other questions, I recommend running this example program:


Then click "View this program" to see how the widgets are laid out, simply by appending to the caption of the 3D canvas.

Bruce
Reply all
Reply to author
Forward
0 new messages