python - 我的 Colab 停止渲染 Mathjax sympy 输出?
问题描述
我在 Colab 中使用过 sympy。在我将在 StackOverflow 中找到的代码放入后,它给了我一个很好的打印结果......
from sympy import init_printing
def custom_latex_printer(exp,**options):
from google.colab.output._publish import javascript
url = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=default"
javascript(url=url)
return sympy.printing.latex(exp,**options)
init_printing(use_latex="mathjax",latex_printer=custom_latex_printer)
但是,不幸的是,从昨天开始,我无法获得渲染输出??
请让我知道任何建议?
解决方案
我不确定您发布的代码的来源,但您可以按照此处的配方在 Colab 中使用 sympy:https ://colab.research.google.com/notebooks/snippets/advanced_outputs.ipynb#scrollTo=9G8w79zS5vG4
运行此单元格:
from IPython.display import Math, HTML
def load_mathjax_in_cell_output():
display(HTML("<script src='https://www.gstatic.com/external_hosted/"
"mathjax/latest/MathJax.js?config=default'></script>"))
get_ipython().events.register('pre_run_cell', load_mathjax_in_cell_output)
在此 sympy 应在后续单元格中正确呈现之后:
import sympy
sympy.init_printing()
x = sympy.symbols('x')
sympy.Integral(sympy.sqrt(1 / x), x)
推荐阅读
- android - 在模块中找到的 Android 重复类 com.google.android.gms.location.places.zza
- python - 由于身份验证失败,客户端未经授权
- javascript - 还有另一种方法来查找并返回数组的对象吗?
- python - Docker:无法测试 postgresql 连接
- flutter - 我的颤振应用程序的标签栏视图不起作用
- sql - 如何避免左连接中的重复记录
- java - java类和arraylist
- flutter - 在 Flutter 中处理屏幕尺寸的最佳方法是什么?
- python - Python - 访问包含文本字符串的文件中的元素
- python - numpy 前向填充条件