Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MG-dkfz opened this issue Oct 8, 2023 · 2 comments

Comments

@MG-dkfz
Copy link

MG-dkfz commented Oct 8, 2023

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
Copy link
Member

stevengj commented Oct 12, 2023

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
Copy link
Member

This was reportedly fixed upstream in Jupyter notebook version 7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants