【问题标题】:Documenting math formulas as comments in python code using Doxygen使用 Doxygen 将数学公式记录为 Python 代码中的注释
【发布时间】:2020-07-27 18:50:41
【问题描述】:

我的问题是this one 的扩展,我想要的是 Doxygen 输出我的 python 源代码的同一注释行中的数学公式和文本。举个例子:

# Create homogeneous probability matrix from the colors matrix
def create_probability_map(colors_map):
    """!\f$(x_1,y_1)\f$"""
    pass

当我运行上述代码时,Doxygen 会按预期输出correct math formula。 但是,如果我在数学公式之前添加一些文本:

# Create homogeneous probability matrix from the colors matrix
def create_probability_map(colors_map):
    """Formula is: !\f$(x_1,y_1)\f$"""
    pass

输出不如预期。 有人知道如何解决这个问题吗?

在尝试其他几种组合时,我发现如果文本在数学公式之后,则 Doxygen outputs 正确注释,如下所示:

# Create homogeneous probability matrix from the colors matrix
def create_probability_map(colors_map):
    """!\f$(x_1,y_1)\f$ is the formula"""
    pass

P.S:我还发现奇怪的是,据说 Doxygen 无法在 Python 上处理数学公式,正如 documentation 中所述(特别是在 here 中)。文档过期了吗?

【问题讨论】:

    标签: python formula doxygen


    【解决方案1】:

    我用 doxygen 1.8.18 尝试了以下代码:

    ## \file
    
    # Create homogeneous probability matrix from the colors matrix
    def create_probability_map1(colors_map):
        """!\f$(x_1,y_1)\f$"""
        pass
    
    # Create homogeneous probability matrix from the colors matrix
    def create_probability_map2(colors_map):
        """Formula is: !\f$(x_2,y_2)\f$"""
        pass
    
    # Create homogeneous probability matrix from the colors matrix
    def create_probability_map3(colors_map):
        """!\f$(x_3,y_3)\f$ is the formula"""
        pass
    
    # Create homogeneous probability matrix from the colors matrix
    def create_probability_map4(colors_map):
        """!Formula is: \f$(x_4,y_4)\f$ is the formula"""
        pass
    

    使用默认的 doxygen 配置设置,这会导致:

    这在我看来一切正常,带有"""! 的文档字符串被视为 doxygen cmets,而仅带有 """ 的文档字符串被视为逐字/代码(如问题中提到的链接所示)。

    【讨论】:

    • 完美,所以诀窍实际上是用 """! 开始评论,而不是只在 """ 上。非常感谢,这真的很有帮助! :)
    猜你喜欢
    • 1970-01-01
    • 2013-03-22
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    • 2010-09-08
    • 2018-01-18
    • 1970-01-01
    • 2010-11-06
    相关资源
    最近更新 更多