【问题标题】:My Colab stop rendering Mathjax sympy output?我的 Colab 停止渲染 Mathjax sympy 输出?
【发布时间】:2020-07-25 21:17:05
【问题描述】:

我在 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) 

但是很遗憾,从昨天开始,我无法获得渲染输出??

请告诉我任何建议??

【问题讨论】:

  • 你有输出吗?让我们知道发生了什么。

标签: python sympy google-colaboratory mathjax


【解决方案1】:

我不确定您发布的代码的来源,但您可以按照此处的配方在 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)

【讨论】:

  • 非常感谢您的好意和帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-11
  • 1970-01-01
  • 2019-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多