# Displaying docstrings in Notebook in VSCode (errors)

**URL:** https://discourse.julialang.org/t/displaying-docstrings-in-notebook-in-vscode-errors/107627
**Category:** General Usage
**Tags:** notebooks, vsc
**Created:** [December 14, 2023, 7:34pm UTC](https://discourse.julialang.org/t/displaying-docstrings-in-notebook-in-vscode-errors/107627 "2023-12-14T19:34:43Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [December 14, 2023, 7:34pm UTC](https://discourse.julialang.org/t/displaying-docstrings-in-notebook-in-vscode-errors/107627/1 "2023-12-14T19:34:43Z")

</div>

I found this [SO post](https://stackoverflow.com/questions/68081136/print-a-docstring-of-a-program-to-stdout-in-julia) that makes think it should work on VSC but when I try it (in notebook cell)

```julia
@doc sin

ParseError: KaTeX parse error: No such environment: verbatim at position 7: \begin{̲v̲e̲r̲b̲a̲t̲i̲m̲}̲ sin(x) \end{ve…

Compute sine of \texttt{x}, where \texttt{x} is in radians.

See also \href{@ref}{\texttt{sind}}, \href{@ref}{\texttt{sinpi}}, \href{@ref}{\texttt{sincos}}, \href{@ref}{\texttt{cis}}, \href{@ref}{\texttt{asin}}.
...

```

How can we display docstrings then?

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [December 14, 2023, 8:15pm UTC](https://discourse.julialang.org/t/displaying-docstrings-in-notebook-in-vscode-errors/107627/2 "2023-12-14T20:15:54Z")

</div>

Sh…

> <https://github.com/microsoft/vscode/issues/143801>
>
> Does this issue occur when all extensions are disabled?: Yes/No
> 
> 
> 
> \- Version…: 1.65.0-insider (user setup)
> \- Commit: 32456dc9e7d3194a94dd3ee0322ccf47e461d09c
> \- Date: 2022-02-23T05:16:22.798Z
> \- OS: WSL
> 
> 
> Steps to Reproduce:
> 
> 1. Open the ipynb file provided in this issue (JSON provided)
> 2. Notice how errors are displayed in the output \`ParseError: KaTeX parse error: No such environment: verbatim at position 7: \\begin{̲v̲e̲r̲b̲a̲t̲i̲m̲}̲ rand(\[rng=GLOB…\`
> 
> Now, switch the mime type to \`text/markdown\` and this will work.
> 
> \<details\>
> \<summary\>Here's the ipynb contents generated using Jupyter\</summary\>
> 
> \`\`\`json
> {
> "cells": \[
> {
> "cell\_type": "code",
> "execution\_count": 1,
> "metadata": {},
> "outputs": \[
> {
> "data": {
> "text/plain": \[
> "1234"
> \]
> },
> "execution\_count": 1,
> "metadata": {},
> "output\_type": "execute\_result"
> }
> \],
> "source": \[
> "1234"
> \]
> },
> {
> "cell\_type": "code",
> "execution\_count": 2,
> "metadata": {},
> "outputs": \[
> {
> "name": "stdout",
> "output\_type": "stream",
> "text": \[
> "search: \\u001b\[0m\\u001b\[1mr\\u001b\[22m\\u001b\[0m\\u001b\[1ma\\u001b\[22m\\u001b\[0m\\u001b\[1mn\\u001b\[22m\\u001b\[0m\\u001b\[1md\\u001b\[22m \\u001b\[0m\\u001b\[1mr\\u001b\[22m\\u001b\[0m\\u001b\[1ma\\u001b\[22m\\u001b\[0m\\u001b\[1mn\\u001b\[22m\\u001b\[0m\\u001b\[1md\\u001b\[22mn t\\u001b\[0m\\u001b\[1mr\\u001b\[22m\\u001b\[0m\\u001b\[1ma\\u001b\[22m\\u001b\[0m\\u001b\[1mn\\u001b\[22msco\\u001b\[0m\\u001b\[1md\\u001b\[22me mac\\u001b\[0m\\u001b\[1mr\\u001b\[22moexp\\u001b\[0m\\u001b\[1ma\\u001b\[22m\\u001b\[0m\\u001b\[1mn\\u001b\[22m\\u001b\[0m\\u001b\[1md\\u001b\[22m @mac\\u001b\[0m\\u001b\[1mr\\u001b\[22moexp\\u001b\[0m\\u001b\[1ma\\u001b\[22m\\u001b\[0m\\u001b\[1mn\\u001b\[22m\\u001b\[0m\\u001b\[1md\\u001b\[22m @mac\\u001b\[0m\\u001b\[1mr\\u001b\[22moexp\\u001b\[0m\\u001b\[1ma\\u001b\[22m\\u001b\[0m\\u001b\[1mn\\u001b\[22m\\u001b\[0m\\u001b\[1md\\u001b\[22m1\\n",
> "\\n"
> \]
> },
> {
> "data": {
> "text/latex": \[
> "\\\\begin{verbatim}\\n",
> "rand(\[rng=GLOBAL\_RNG\], \[S\], \[dims...\])\\n",
> "\\\\end{verbatim}\\n",
> "Pick a random element or array of random elements from the set of values specified by \\\\texttt{S}; \\\\texttt{S} can be\\n",
> "\\n",
> "\\\\begin{itemize}\\n",
> "\\\\item an indexable collection (for example \\\\texttt{1:9} or \\\\texttt{('x', \\"y\\", :z)}),\\n",
> "\\n",
> "\\n",
> "\\\\item an \\\\texttt{AbstractDict} or \\\\texttt{AbstractSet} object,\\n",
> "\\n",
> "\\n",
> "\\\\item a string (considered as a collection of characters), or\\n",
> "\\n",
> "\\n",
> "\\\\item a type: the set of values to pick from is then equivalent to \\\\texttt{typemin(S):typemax(S)} for integers (this is not applicable to \\\\href{@ref}{\\\\texttt{BigInt}}), to $\[0, 1)$ for floating point numbers and to $\[0, 1)+i\[0, 1)$ for complex floating point numbers;\\n",
> "\\n",
> "\\\\end{itemize}\\n",
> "\\\\texttt{S} defaults to \\\\href{@ref}{\\\\texttt{Float64}}. When only one argument is passed besides the optional \\\\texttt{rng} and is a \\\\texttt{Tuple}, it is interpreted as a collection of values (\\\\texttt{S}) and not as \\\\texttt{dims}.\\n",
> "\\n",
> "\\\\begin{quote}\\n",
> "\\\\textbf{compat}\\n",
> "\\n",
> "Julia 1.1\\n",
> "\\n",
> "Support for \\\\texttt{S} as a tuple requires at least Julia 1.1.\\n",
> "\\n",
> "\\\\end{quote}\\n",
> "\\\\section{Examples}\\n",
> "\\\\begin{verbatim}\\n",
> "julia\> rand(Int, 2)\\n",
> "2-element Array{Int64,1}:\\n",
> " 1339893410598768192\\n",
> " 1575814717733606317\\n",
> "\\n",
> "julia\> using Random\\n",
> "\\n",
> "julia\> rand(MersenneTwister(0), Dict(1=\>2, 3=\>4))\\n",
> "1=\>2\\n",
> "\\n",
> "julia\> rand((2, 3))\\n",
> "3\\n",
> "\\n",
> "julia\> rand(Float64, (2, 3))\\n",
> "2×3 Array{Float64,2}:\\n",
> " 0.999717 0.0143835 0.540787\\n",
> " 0.696556 0.783855 0.938235\\n",
> "\\\\end{verbatim}\\n",
> "\\\\begin{quote}\\n",
> "\\\\textbf{note}\\n",
> "\\n",
> "Note\\n",
> "\\n",
> "The complexity of \\\\texttt{rand(rng, s::Union\\\\{AbstractDict,AbstractSet\\\\})} is linear in the length of \\\\texttt{s}, unless an optimized method with constant complexity is available, which is the case for \\\\texttt{Dict}, \\\\texttt{Set} and \\\\texttt{BitSet}. For more than a few calls, use \\\\texttt{rand(rng, collect(s))} instead, or either \\\\texttt{rand(rng, Dict(s))} or \\\\texttt{rand(rng, Set(s))} as appropriate.\\n",
> "\\n",
> "\\\\end{quote}\\n"
> \],
> "text/markdown": \[
> "\`\`\`\\n",
> "rand(\[rng=GLOBAL\_RNG\], \[S\], \[dims...\])\\n",
> "\`\`\`\\n",
> "\\n",
> "Pick a random element or array of random elements from the set of values specified by \`S\`; \`S\` can be\\n",
> "\\n",
> " \* an indexable collection (for example \`1:9\` or \`('x', \\"y\\", :z)\`),\\n",
> " \* an \`AbstractDict\` or \`AbstractSet\` object,\\n",
> " \* a string (considered as a collection of characters), or\\n",
> " \* a type: the set of values to pick from is then equivalent to \`typemin(S):typemax(S)\` for integers (this is not applicable to \[\`BigInt\`\](@ref)), to $\[0, 1)$ for floating point numbers and to $\[0, 1)+i\[0, 1)$ for complex floating point numbers;\\n",
> "\\n",
> "\`S\` defaults to \[\`Float64\`\](@ref). When only one argument is passed besides the optional \`rng\` and is a \`Tuple\`, it is interpreted as a collection of values (\`S\`) and not as \`dims\`.\\n",
> "\\n",
> "!!! compat \\"Julia 1.1\\"\\n",
> " Support for \`S\` as a tuple requires at least Julia 1.1.\\n",
> "\\n",
> "\\n",
> "# Examples\\n",
> "\\n",
> "\`\`\`julia-repl\\n",
> "julia\> rand(Int, 2)\\n",
> "2-element Array{Int64,1}:\\n",
> " 1339893410598768192\\n",
> " 1575814717733606317\\n",
> "\\n",
> "julia\> using Random\\n",
> "\\n",
> "julia\> rand(MersenneTwister(0), Dict(1=\>2, 3=\>4))\\n",
> "1=\>2\\n",
> "\\n",
> "julia\> rand((2, 3))\\n",
> "3\\n",
> "\\n",
> "julia\> rand(Float64, (2, 3))\\n",
> "2×3 Array{Float64,2}:\\n",
> " 0.999717 0.0143835 0.540787\\n",
> " 0.696556 0.783855 0.938235\\n",
> "\`\`\`\\n",
> "\\n",
> "!!! note\\n",
> " The complexity of \`rand(rng, s::Union{AbstractDict,AbstractSet})\` is linear in the length of \`s\`, unless an optimized method with constant complexity is available, which is the case for \`Dict\`, \`Set\` and \`BitSet\`. For more than a few calls, use \`rand(rng, collect(s))\` instead, or either \`rand(rng, Dict(s))\` or \`rand(rng, Set(s))\` as appropriate.\\n",
> "\\n"
> \],
> "text/plain": \[
> "\\u001b\[36m rand(\[rng=GLOBAL\_RNG\], \[S\], \[dims...\])\\u001b\[39m\\n",
> "\\n",
> " Pick a random element or array of random elements from the set of values\\n",
> " specified by \\u001b\[36mS\\u001b\[39m; \\u001b\[36mS\\u001b\[39m can be\\n",
> "\\n",
> " • an indexable collection (for example \\u001b\[36m1:9\\u001b\[39m or \\u001b\[36m('x', \\"y\\", :z)\\u001b\[39m),\\n",
> "\\n",
> " • an \\u001b\[36mAbstractDict\\u001b\[39m or \\u001b\[36mAbstractSet\\u001b\[39m object,\\n",
> "\\n",
> " • a string (considered as a collection of characters), or\\n",
> "\\n",
> " • a type: the set of values to pick from is then equivalent to\\n",
> " \\u001b\[36mtypemin(S):typemax(S)\\u001b\[39m for integers (this is not applicable to\\n",
> " \\u001b\[36mBigInt\\u001b\[39m), to \\u001b\[35m\[0, 1)\\u001b\[39m for floating point numbers and to \\u001b\[35m\[0, 1)+i\[0,\\n",
> " 1)\\u001b\[39m for complex floating point numbers;\\n",
> "\\n",
> " \\u001b\[36mS\\u001b\[39m defaults to \\u001b\[36mFloat64\\u001b\[39m. When only one argument is passed besides the optional\\n",
> " \\u001b\[36mrng\\u001b\[39m and is a \\u001b\[36mTuple\\u001b\[39m, it is interpreted as a collection of values (\\u001b\[36mS\\u001b\[39m) and not\\n",
> " as \\u001b\[36mdims\\u001b\[39m.\\n",
> "\\n",
> "\\u001b\[39m\\u001b\[1m │ \\u001b\[22m\\u001b\[39m\\u001b\[1mJulia 1.1\\u001b\[22m\\n",
> "\\u001b\[39m\\u001b\[1m │\\u001b\[22m\\n",
> "\\u001b\[39m\\u001b\[1m │\\u001b\[22m Support for \\u001b\[36mS\\u001b\[39m as a tuple requires at least Julia 1.1.\\n",
> "\\n",
> "\\u001b\[1m Examples\\u001b\[22m\\n",
> "\\u001b\[1m ≡≡≡≡≡≡≡≡≡≡\\u001b\[22m\\n",
> "\\n",
> "\\u001b\[36m julia\> rand(Int, 2)\\u001b\[39m\\n",
> "\\u001b\[36m 2-element Array{Int64,1}:\\u001b\[39m\\n",
> "\\u001b\[36m 1339893410598768192\\u001b\[39m\\n",
> "\\u001b\[36m 1575814717733606317\\u001b\[39m\\n",
> "\\u001b\[36m \\u001b\[39m\\n",
> "\\u001b\[36m julia\> using Random\\u001b\[39m\\n",
> "\\u001b\[36m \\u001b\[39m\\n",
> "\\u001b\[36m julia\> rand(MersenneTwister(0), Dict(1=\>2, 3=\>4))\\u001b\[39m\\n",
> "\\u001b\[36m 1=\>2\\u001b\[39m\\n",
> "\\u001b\[36m \\u001b\[39m\\n",
> "\\u001b\[36m julia\> rand((2, 3))\\u001b\[39m\\n",
> "\\u001b\[36m 3\\u001b\[39m\\n",
> "\\u001b\[36m \\u001b\[39m\\n",
> "\\u001b\[36m julia\> rand(Float64, (2, 3))\\u001b\[39m\\n",
> "\\u001b\[36m 2×3 Array{Float64,2}:\\u001b\[39m\\n",
> "\\u001b\[36m 0.999717 0.0143835 0.540787\\u001b\[39m\\n",
> "\\u001b\[36m 0.696556 0.783855 0.938235\\u001b\[39m\\n",
> "\\n",
> "\\u001b\[36m\\u001b\[1m │ \\u001b\[22m\\u001b\[39m\\u001b\[36m\\u001b\[1mNote\\u001b\[22m\\u001b\[39m\\n",
> "\\u001b\[36m\\u001b\[1m │\\u001b\[22m\\u001b\[39m\\n",
> "\\u001b\[36m\\u001b\[1m │\\u001b\[22m\\u001b\[39m The complexity of \\u001b\[36mrand(rng, s::Union{AbstractDict,AbstractSet})\\u001b\[39m is\\n",
> "\\u001b\[36m\\u001b\[1m │\\u001b\[22m\\u001b\[39m linear in the length of \\u001b\[36ms\\u001b\[39m, unless an optimized method with\\n",
> "\\u001b\[36m\\u001b\[1m │\\u001b\[22m\\u001b\[39m constant complexity is available, which is the case for \\u001b\[36mDict\\u001b\[39m, \\u001b\[36mSet\\u001b\[39m\\n",
> "\\u001b\[36m\\u001b\[1m │\\u001b\[22m\\u001b\[39m and \\u001b\[36mBitSet\\u001b\[39m. For more than a few calls, use \\u001b\[36mrand(rng, collect(s))\\u001b\[39m\\n",
> "\\u001b\[36m\\u001b\[1m │\\u001b\[22m\\u001b\[39m instead, or either \\u001b\[36mrand(rng, Dict(s))\\u001b\[39m or \\u001b\[36mrand(rng, Set(s))\\u001b\[39m as\\n",
> "\\u001b\[36m\\u001b\[1m │\\u001b\[22m\\u001b\[39m appropriate."
> \]
> },
> "execution\_count": 2,
> "metadata": {},
> "output\_type": "execute\_result"
> }
> \],
> "source": \[
> "?rand"
> \]
> },
> {
> "cell\_type": "code",
> "execution\_count": null,
> "metadata": {},
> "outputs": \[\],
> "source": \[\]
> }
> \],
> "metadata": {
> "interpreter": {
> "hash": "826320bbfe537aae42eeb362ae5fce76caa1fa66aa5993e91d7cbda9ea11c7b8"
> },
> "kernelspec": {
> "display\_name": "Julia 1.6.4",
> "language": "julia",
> "name": "julia-1.6.4"
> },
> "language\_info": {
> "file\_extension": ".jl",
> "mimetype": "application/julia",
> "name": "julia",
> "version": "1.6.3"
> }
> },
> "nbformat": 4,
> "nbformat\_minor": 2
> }
> \`\`\`
> 
> \</details\>
> 
> !\[image\](https://user-images.githubusercontent.com/1948812/155388592-9f2cdaa8-1be3-4f47-8e87-a51f61b49e6b.png)

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [December 14, 2023, 8:40pm UTC](https://discourse.julialang.org/t/displaying-docstrings-in-notebook-in-vscode-errors/107627/3 "2023-12-14T20:40:02Z")

</div>

This post solves it. Not obvious at first but it now works.

> <https://github.com/microsoft/vscode-jupyter/issues/13493>
>
> I use VS Code Jupyter for Julia. \`?sum\` show below,
> 
> search: sum sum! summary …cumsum cumsum! isnumeric VersionNumber issubnormal
> 
> ParseError: KaTeX parse error: No such environment: verbatim at position 7: \\begin{̲v̲e̲r̲b̲a̲t̲i̲m̲}̲ sum(f, itr; \[i…
> 
> Sum the results of calling function \\texttt{f} on each element of \\texttt{itr}.
> 
> The return type is \\texttt{Int} for signed integers of less than system word size, and \\texttt{UInt} for unsigned integers of less than system word size. For all other arguments, a common return type is found to which all arguments are promoted.
> 
> The value returned for empty \\texttt{itr} can be specified by \\texttt{init}. It must be the additive identity (i.e. zero) as it is unspecified whether \\texttt{init} is used for non-empty collections.
> 
> ParseError: KaTeX parse error: No such environment: quote at position 7: \\begin{̲q̲u̲o̲t̲e̲}̲ \\textbf{compat…
> 
> \\section{Examples}
> 
> ParseError: KaTeX parse error: No such environment: verbatim at position 7: \\begin{̲v̲e̲r̲b̲a̲t̲i̲m̲}̲ julia\> sum(abs…
> 
> Note the important difference between \\texttt{sum(A)} and \\texttt{reduce(+, A)} for arrays with small integer eltype:
> ParseError: KaTeX parse error: No such environment: verbatim at position 7: \\begin{̲v̲e̲r̲b̲a̲t̲i̲m̲}̲ julia\> sum(Int…
> 
> In the former case, the integers are widened to system word size and therefore the result is 128. In the latter case, no such widening happens and integer overflow results in -128.
> 
> \\rule{\\textwidth}{1pt}
> 
> ParseError: KaTeX parse error: No such environment: verbatim at position 7: \\begin{̲v̲e̲r̲b̲a̲t̲i̲m̲}̲ sum(itr; \[init…
> 
> Returns the sum of all elements in a collection.
> The return type is \\texttt{Int} for signed integers of less than system word size, and \\texttt{UInt} for unsigned integers of less than system word size. For all other arguments, a common return type is found to which all arguments are promoted.
> 
> The value returned for empty \\texttt{itr} can be specified by \\texttt{init}. It must be the additive identity (i.e. zero) as it is unspecified whether \\texttt{init} is used for non-empty collections.
> 
> ParseError: KaTeX parse error: No such environment: quote at position 7: \\begin{̲q̲u̲o̲t̲e̲}̲ \\textbf{compat…
> 
> See also: \\href{@ref}{\\texttt{reduce}}, \\href{@ref}{\\texttt{mapreduce}}, \\href{@ref}{\\texttt{count}}, \\href{@ref}{\\texttt{union}}.
> 
> \\section{Examples}\\begin{verbatim} julia\> sum(1:20) 210
> 
> julia\> sum(1:20; init = 0.0) 210.0 \\end{verbatim} \\rule{\\textwidth}{1pt}
> 
> ParseError: KaTeX parse error: No such environment: verbatim at position 7: \\begin{̲v̲e̲r̲b̲a̲t̲i̲m̲}̲ sum(A::Abstrac…
> 
> Sum elements of an array over the given dimensions.
> \\section{Examples}\\begin{verbatim} julia\> A = \[1 2; 3 4\] 2×2 Matrix{Int64}: 1 2 3 4
> 
> julia\> sum(A, dims=1) 1×2 Matrix{Int64}: 4 6
> 
> julia\> sum(A, dims=2) 2×1 Matrix{Int64}: 3 7 \\end{verbatim} \\rule{\\textwidth}{1pt}
> 
> ParseError: KaTeX parse error: No such environment: verbatim at position 7: \\begin{̲v̲e̲r̲b̲a̲t̲i̲m̲}̲ sum(f, A::Abst…
> 
> Sum the results of calling function \\texttt{f} on each element of an array over the given dimensions.
> \\section{Examples}\\begin{verbatim} julia\> A = \[1 2; 3 4\] 2×2 Matrix{Int64}: 1 2 3 4
> 
> julia\> sum(abs2, A, dims=1) 1×2 Matrix{Int64}: 10 20
> 
> julia\> sum(abs2, A, dims=2) 2×1 Matrix{Int64}: 5 25 \\end{verbatim}
> 
> It's not rendered correctly.

---

<div class="post-metadata">

### Author: ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)
#### Post date: [February 23, 2024, 4:18pm UTC](https://discourse.julialang.org/t/displaying-docstrings-in-notebook-in-vscode-errors/107627/4 "2024-02-23T16:18:40Z")

</div>

I currently do `display("text/markdown",@doc sin)`, but maybe a simple macro

```julia
macro docVSC(fn)
  return :( display("text/markdown",Base.doc($fn)))
end

```

used as `@docVSC sin` would be a temporary solution. Any ideas?

---

<div class="post-metadata">

### Author: ![younes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/younes/32/208506_2.png) [@younes](https://discourse.julialang.org/u/younes)
#### Post date: [April 15, 2024, 7:56pm UTC](https://discourse.julialang.org/t/displaying-docstrings-in-notebook-in-vscode-errors/107627/5 "2024-04-15T19:56:59Z")

</div>

Hello,

Has this been solved, or do we still to use the workaround? =)

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [April 15, 2024, 8:53pm UTC](https://discourse.julialang.org/t/displaying-docstrings-in-notebook-in-vscode-errors/107627/6 "2024-04-15T20:53:42Z")

</div>

See [How to get help on a Julia command on a Jupyter notebook? - #6 by stevengj](https://discourse.julialang.org/t/how-to-get-help-on-a-julia-command-on-a-jupyter-notebook/112976/6) for other workarounds, but this really needs to be solved in VSCode.

(Or just use the `jupyter notebook` or the `jupyterlab` front end, which is more full-featured.)
