How to enable math in sphinx?

别等时光非礼了梦想. 提交于 2019-12-12 10:43:21

问题


I am using sphinx with the pngmath extension to document my code that has a lot of mathematical expressions. Doing that in a *.rst file is working just fine.

a \times b becomes:



However, if I try the same inside a *.py file for example in a module documentation like so:

"""
a \times b
"""

I end up with



Furthermore no amsmath functionality seems to work, either.
What do I need to do, to also have math formulas in my *.py documentations?


回答1:


Try putting a lower case 'r' before your docstring - like this:

def multiply(a,b):
    r"""
    returns a \times b
    """
    return a*b

I've never seen a raw literal string for a docstring before, but this will keep your \t from being interpreted as a <TAB> character.



来源:https://stackoverflow.com/questions/8385538/how-to-enable-math-in-sphinx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!