# Image in julia code comments or doc

**URL:** <https://discourse.julialang.org/t/image-in-julia-code-comments-or-doc/74090>\
**Category:** VS Code\
**Tags:** vscode\
**Created:** [January 5, 2022, 3:33pm UTC](https://discourse.julialang.org/t/image-in-julia-code-comments-or-doc/74090 "2022-01-05T15:33:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [January 5, 2022, 3:33pm UTC](https://discourse.julialang.org/t/image-in-julia-code-comments-or-doc/74090/1 "2022-01-05T15:33:54Z")

</div>

hi,

I guess it is a silly idea but I often wish to insert small images (typically scan of manually drawn sketches) to better explain part of my codes. Ideally these images could be displayed by the editor (VSCode) or even displayed in the docstrings of a function.

Does anyone knows about a VSCode extension or other ways to do this ?

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [January 5, 2022, 6:06pm UTC](https://discourse.julialang.org/t/image-in-julia-code-comments-or-doc/74090/2 "2022-01-05T18:06:42Z")

</div>

Perhaps not in the code itself, but have you considered

- literate programming, Weave.jl and Literate.jl
- notebooks, Pluto.jl
- using Documenter.jl etc. to generate documentation for your code.

All of these alternatives allow you to associate images with your code in one way or another

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 5, 2022, 6:42pm UTC](https://discourse.julialang.org/t/image-in-julia-code-comments-or-doc/74090/3 "2022-01-05T18:42:32Z")

</div>

Not the same thing, but FWIW:

By adding a comment to your Julia code with a link to the image file, when hovering over it VS Code will propose to `ctrl + click` it:

```julia
# file:///C:\Users\jrafa\Desktop\Coordinate_descent.png

function coordinate_descent(A::AbstractArray, index)
...

```

This opens instantaneously in a new VS Code tab:

 ![Coordinate_descent.svg](https://global.discourse-cdn.com/julialang/original/3X/8/0/80b38746b7a164dab2aa6e1086612e2164edeee0.png)

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [January 5, 2022, 7:52pm UTC](https://discourse.julialang.org/t/image-in-julia-code-comments-or-doc/74090/4 "2022-01-05T19:52:29Z")

</div>

It might be this issue:

[https://github.com/microsoft/vscode/issues/85682](https://github.com/microsoft/vscode/issues/85682)

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [January 6, 2022, 6:54am UTC](https://discourse.julialang.org/t/image-in-julia-code-comments-or-doc/74090/5 "2022-01-06T06:54:21Z")

</div>

Thank you for these directions !  
@baggepinnen : I knew about Documenter.jl and Pluto.jl but the idea was to make this information in the code itself via vscode… In the same spirit, the latex formulas in docstrings are not directly rendered in vscode.  
@rafael.guerra : This is closer to my wish. It just lacks to be open without a Ctrl-click and a size options .  
@jzr : I did not understood all the thread but some quotes look close to what I am looking for. @davidanthoff contributes to this thread and maybe he could explain how it is related to Julia vscode extension.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 6, 2022, 9:19am UTC](https://discourse.julialang.org/t/image-in-julia-code-comments-or-doc/74090/6 "2022-01-06T09:19:26Z")

</div>

> [@LaurentPlagne](#):
>
> This is closer to my wish. It just lacks to be open without a Ctrl-click and a size options

As per your wishes:

```julia
# file:///C:\Users\jrafa\Desktop\Rosenbrock_image.png
using Plots; plotly()
rosenbrock(x,y) = (1 - x)^2 + 100(y - x^2)^2
...

```

It shows like this in VS Code when hovering cursor over the commented line:

 ![VS_Code_Hovering_over_image](https://global.discourse-cdn.com/julialang/original/3X/c/5/c504ea2fcefce18d8f266c17b979a0ce6226da6b.png)

and it proposes also to follow a link with a single click to open the image in a dedicated VS Code tab.

_ **NB:** _  
_Cerise sur le gâteau_: an automatic icon is displayed next to the code line number

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [January 6, 2022, 11:43am UTC](https://discourse.julialang.org/t/image-in-julia-code-comments-or-doc/74090/7 "2022-01-06T11:43:34Z")

</div>

This is exactly what I meant but… it does not work on my computer:

 ![Capture d’écran 2022-01-06 à 12.42.11](https://global.discourse-cdn.com/julialang/original/3X/d/c/dc04bc6a2b89ab3fd2060600d654b1cdf585d080.png)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 6, 2022, 12:03pm UTC](https://discourse.julialang.org/t/image-in-julia-code-comments-or-doc/74090/8 "2022-01-06T12:03:04Z")

</div>

Please search the `hover` settings in VS Code and check that `Editor > Hover: Enabled`.  
I’m on Windows here and short of other ideas.

NB:  
as per @LaurentPlagne comment below, it requires `Image preview` VS Code extension

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [January 6, 2022, 12:15pm UTC](https://discourse.julialang.org/t/image-in-julia-code-comments-or-doc/74090/9 "2022-01-06T12:15:37Z")

</div>

This option is already enabled. This is VSCode 1.63.2 and macOS.

```julia
julia> versioninfo()
Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin19.5.0)
  CPU: Apple M1 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, westmere)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 4

```

I will try with another OS. Thank you anyway !

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [January 6, 2022, 12:23pm UTC](https://discourse.julialang.org/t/image-in-julia-code-comments-or-doc/74090/10 "2022-01-06T12:23:22Z")

</div>

OK, it works with Image preview extension (maybe you also have it installed).  
Thanks !

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 6, 2022, 12:29pm UTC](https://discourse.julialang.org/t/image-in-julia-code-comments-or-doc/74090/11 "2022-01-06T12:29:18Z")

</div>

> [@LaurentPlagne](#):
>
> it works with Image preview extension (maybe you also have it installed)

Yes, that’s right! And I had completely forgotten…

---

<div class="post-metadata">

**Author:** ![arik](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@arik](https://discourse.julialang.org/u/arik)\
**Post date:** [January 17, 2022, 1:10pm UTC](https://discourse.julialang.org/t/image-in-julia-code-comments-or-doc/74090/12 "2022-01-17T13:10:07Z")

</div>

Btw, regarding pictures in a docstring, since julias docstrings are rendered as Markdown by most sensible IDEs, one can insert pictures into docstrings via the regular Markdown syntax `![pic description](picture link)`, as in

```julia
"""
heres a smiley!
![smiley](https://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Smiley.svg/640px-Smiley.svg.png)
"""
 smile!() = "😃"

```
