Skip to content

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:

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

@example

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

Input

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

Output

julia
using Pkg
Pkg.status()
Status `~/work/DocumenterVitepress.jl/DocumenterVitepress.jl/docs/Project.toml`
  [e30172f5] Documenter v1.4.1
  [daee34ce] DocumenterCitations v1.3.3
  [4710194d] DocumenterVitepress v0.0.21 `~/work/DocumenterVitepress.jl/DocumenterVitepress.jl`

And a simple sum:

Input

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

Output

julia
2 + 2
4

@ansi

Input

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

Output

julia
julia> printstyled("this is my color"; color = :red)
this is my color

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

julia
julia> for color in 0:15
           print("\e[38;5;$color;48;5;$(color)m  ")
           print("\e[49m", lpad(color, 3), " ")
           color % 8 == 7 && println() 
       end
    0     1     2     3     4     5     6     7 
    8     9    10    11    12    13    14    15

@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
julia> a = 1;

julia> b = 2;

julia> a + b
3

Input

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

Output

julia
julia> a = 1;

julia> a + b
3

@doctest

Input

```@doctest
julia> 1 + 1
2

```

Output

julia
julia> 1 + 1
2