如何为所有用户定义的julia函数构建索引页面?

时间:2018-03-23 18:20:27

标签: markdown julia documentation doxygen

说我有A.jlB.jlC.jlD.jl。在每个.jl中,有100个函数。当我尝试调用特定函数时,我需要搜索.jl以确定函数是如何定义的?是否有一种简单的方法可以将所有函数定义生成到HTML索引页面中。如果我可以单击该链接并查看该函数的实际源代码,它会更好。像Doxygen那样为C / C ++生成文档,但Doxygen不支持Julia。感谢。

2 个答案:

答案 0 :(得分:6)

在我看来,对文档功能的内置支持实际上非常好。

  1. 基本上您使用“docstrings”:https://docs.julialang.org/en/stable/manual/documentation/#Documentation-1

    """
        s = mysum(a,b)
    
    Compute the sum of `a` and `b`.
    """
    function mysum(a,b)
        return a+b
    end
    
  2. 将功能放在模块中可能很有用(A,B,C和D可以是单独的模块)。您加载了using Aimport A的模块(文件A.jl应该在您的LOAD_PATH中)。如果使用,import该函数的前缀是以点分隔的模块名称。如果函数未在模块中分组,则需要包含包含函数的文件,例如include("A.jl")(使用完整或相对路径)。

  3. 文档可以在加载模块后由?显示,例如?myfunction_in_module_A?A.myfunction_in_module_A

  4. 如果您不记得功能名称

    • 您可以使用apropos("my keyword")进行全文搜索。
    • 列出所有功能都是names(module_A)
    • 的模块
    • 使用methodswith
    • 根据相关类型进行搜索
  5. Documenter.jl允许通过将所有docsstrings组合到单个HTML文档中来制作漂亮的文档。

答案 1 :(得分:1)

  

当我尝试调用特定函数时,我需要搜索.jl   弄清楚函数是如何定义的?有没有一种简单的方法可以   将所有函数定义生成到HTML索引页面中。如果我能   单击该链接并查看该函数的实际源代码   会更好。

不直接回答关于索引页面的问题,但如果您的目标是轻松找到源代码,则goto选项是使用@which@edit宏。来自帮助:

help?> @which
  @which

  Applied to a function or macro call, it evaluates the arguments to the
  specified call, and returns the Method object for the method that would be
  called for those arguments. Applied to a variable, it returns the module in
  which the variable was bound. It calls out to the which function.


help?> @edit
  @edit

  Evaluates the arguments to the function or macro call, determines their
  types, and calls the edit function on the resulting expression.

作为示例,让我们看看定义数组求sum方法的位置

julia> @which sum([1, 2, 3])
sum(a::AbstractArray) in Base at reducedim.jl:627

或者我们可以使用@edit,然后在正确的行

打开相应的源文件
julia> @edit sum([1, 2, 3])

如果要更改将用于打开文件的编辑器,请设置JUILA_EDITOR环境变量,例如,使用Sublime,我会这样做

julia> ENV["JULIA_EDITOR"] = "subl"
"subl"