Julia code examples

Fonts

This package uses the JuliaMono font by default, but you can override this in CSS.

This is what some common symbols look like:

] [ = $ ; ( @ { " ) ? . } ⊽ ⊼ ⊻ ⊋ ⊊ ⊉ ⊈ ⊇ ⊆ ≥ ≤ ≢ ≡ ≠ ≉ ≈ ∪ ∩ ∜ ∛ √ ∘ ∌
|> /> ^ % ` ∈ 

@example

The Julia code used here is done using the following packages versions:

Input

```@example version
using Pkg
Pkg.status()
```

Output

using Pkg
Pkg.status()
Status `~/.julia/packages/DocumenterVitepress/AH5XK/docs/Project.toml`
  [e30172f5] Documenter v1.3.0
  [4710194d] DocumenterVitepress v0.0.18 `~/.julia/packages/DocumenterVitepress/AH5XK`

And a simple sum:

Input

```@example simple_sum
2 + 2
```

Output

2 + 2
4

@ansi

Input

```@ansi
printstyled("this is my color"; color = :red)
```

Output

A more colorful example from documenter:

Input

```@ansi
for color in 0:15
    print("\e[38;5;$color;48;5;$(color)m  ")
    print("\e[49m", lpad(color, 3), " ")
    color % 8 == 7 && println() # ‎[!code highlight]
end
```

Output

@eval

From Julia's documentation landing page.

Input

```@eval
io = IOBuffer()
release = isempty(VERSION.prerelease)
v = "$(VERSION.major).$(VERSION.minor)"
!release && (v = v*"-$(first(VERSION.prerelease))")
print(io, """
    # Julia $(v) Documentation

    Welcome to the documentation for Julia $(v).

    """)
if true # !release
    print(io,"""
        !!! warning "Work in progress!"
            This documentation is for an unreleased, in-development, version of Julia.
        """)
end
import Markdown
Markdown.parse(String(take!(io)))
```

```@eval
file = "julia-1.10.2.pdf"
url = "https://raw.githubusercontent.com/JuliaLang/docs.julialang.org/assets/$(file)"
import Markdown
Markdown.parse("""
!!! note
    The documentation is also available in PDF format: [$file]($url).
""")
```

Output

Julia 1.10 Documentation

Welcome to the documentation for Julia 1.10.

Work in progress!

This documentation is for an unreleased, in-development, version of Julia.

Note

The documentation is also available in PDF format: julia-1.10.2.pdf.

@repl

Input

```@repl
a = 1;
b = 2;
a + b
```

Output

julia> a = 1;
julia> b = 2;
julia> a + b3

Input

```@repl
a = 1;
b = 2; # [!code focus] # hide
a + b
```

Output

julia> a = 1;
julia> a + b3

@doctest

Input

```@doctest
julia> 1 + 1
2

```

Output

julia> 1 + 1
2