How to get help on a Julia command on a Jupyter notebook?

I already tried :

?replace

ParseError:
# Error @ /home/onto/dev/projects/intro_julia.ipynb:1:1
?replace
╙ ── not a unary operator

Stacktrace:
 [1] top-level scope
   @ ~/dev/projects/intro_julia.ipynb:1

but it does work in the terminal…

There is probably a better way, but you can do Base.Docs.doc("replace").

1 Like

You mean @docs replace ?

I did, and the output is very scary (because of some weird bug that’s not yet solved I guess, according to some comment I read on GH):

ParseError: KaTeX parse error: No such environment: verbatim at position 7: \begin{̲v̲e̲r̲b̲a̲t̲i̲m̲}̲ String <: Abst…

EDIT: I found this as a workaround: Displaying docstrings in Notebook in VSCode (errors) - #4 by Paul_Soderlind

1 Like

Works for me in jupyter notebook:

What notebook front-end are you using?

VSCode’s

? parses for me if I choose “Jupyter Kernel” (not “Julia release channel”) as the kernel source:

A separate issue is that the front-end is trying to render the LaTeX version and failing.

The way the Jupyter protocol works is that the backend kernel (here, IJulia.jl) sends output as a dictionary in multiple formats, and the front-end chooses which one it wants to display. Here, IJulia sends text/plain, text/markdown, and text/latex formats for the documentation. The jupyter notebook is rendering the text/markdown format, but apparently VSCode is trying to render the text/latex format and failing. As noted above, you can force VSCode to use text/markdown via

display("text/markdown", Base.Docs.doc("replace"))

but this is a bit awkward. Another workaround is to tell Julia that Markdown.MD should never be displayed as text/latex:

import Markdown
Base.showable(::MIME"text/markdown", ::Markdown.MD) = false

at which point ?replace works:

A longer-term “solution” would to patch IJulia.jl so that it never sends text/latex for Markdown.MD objects, but this is a bit annoying since the front-end is supposed to decide this.

The right thing would be for VSCode to fix this. They shouldn’t display as text/latex if text/markdown is available, since their text/latex display is apparently not fully functional. (However, their markdown rendering does not support LaTeX equations. So they really need to fix both.)

4 Likes

Could this be fixed at the level of the vscode Julia extension? Or is it something that needs to be handled upstream, in vscode? In either case, is there a Github issue tracking this?

It would have to be handled upstream, in vscode. They have so far closed all of the related issues (linked in Cannot render Julia's help document in VScode Jupyter Notebook · Issue #13493 · microsoft/vscode-jupyter · GitHub), unfortunately.

It would be nice to at least file an issue for them to prefer text/markdown to text/latex when both are present in the display dictionary, since their support for the former is more full-featured. (Their text/latex support is basically limited to equations.) There doesn’t seem to be an issue that makes this clear.

But they don’t plan to support LaTeX equations in Markdown.

2 Likes