JuliaLang / IJulia.jl

Julia kernel for Jupyter
MIT License
2.78k stars 409 forks source link

Latex maths not rendered in docstring if function signature is indented by four spaces #1096

Closed MG-dkfz closed 10 months ago

MG-dkfz commented 11 months ago

Consider this example for adding equations written in LaTeX to docstrings, which was taken from Documenter.jl

"""
Here's some inline maths: ``\\sqrt[n]{1 + x + x^2 + \\ldots}``.

Here's an equation:

``\\frac{n!}{k!(n - k)!} = \\binom{n}{k}``

This is the binomial coefficient.
"""
func(x) = x

In this form, calling ?func in a Jupyter Notebook nicely renders the equations, as expected. However, including the signature of the function in the docstring, and indenting it by four spaces, as recommended in the Julia Documentation, no longer renders the equations. Consider this minimal extension of above example:

"""
    func(x)

Here's some inline maths: ``\\sqrt[n]{1 + x + x^2 + \\ldots}``.

Here's an equation:

``\\frac{n!}{k!(n - k)!} = \\binom{n}{k}``

This is the binomial coefficient.
"""
func(x) = x

Calling ?func now, just displays plain text.

I'm not sure of this is specific to IJulia or a more general issue – my apologies if this is the wrong place for this.

I'm using Julia 1.9.3 and IJulia v1.24.2.

stevengj commented 11 months ago

This seems to be a bug in Jupyter, because I can reproduce it in IPython as well (the Jupyter Python kernel):

from IPython.display import display, Markdown
display(Markdown('''

func(x)


Here's some inline maths: $\sqrt[n]{1 + x + x^2 + \ldots}$.

Here's an equation:

$\frac{n!}{k!(n - k)!} = \binom{n}{k}$

This is the binomial coefficient.
'''))

fails to show the equations, but succeeds if I remove the fenced func(x) block at the beginning.

I've filed a Jupyter notebook issue (linked below).

stevengj commented 10 months ago

This was reportedly fixed upstream in Jupyter notebook version 7.