API

Desmos.DesmosDisplayConfigType
DesmosDisplayConfig

Configuration for Desmos graph display in plot panes.

Fields

  • width::Int: Width of the Desmos container in pixels (default: 600)
  • height::Int: Height of the Desmos container in pixels (default: 400)
  • clipboard::Bool: Enable clipboard export button (default: false)
  • api_version::Int: Desmos API v1 minor version (default: 10 for v1.10)
  • api_key::String: Desmos API key (default: "dcb31709b452b1cf9dc26972add0fda6". See https://www.desmos.com/api/v1.10/docs/index.html)
source
Desmos.DesmosStateType
DesmosState

Represents the complete state of a Desmos graph, including all expressions, viewport settings, and configuration options.

DesmosState is typically created using the @desmos macro rather than constructed directly. The state object can be serialized to JSON format compatible with the Desmos API, and can be displayed directly in Jupyter notebooks or VSCode.

Fields

  • version::Int: Desmos API version (default: 11)
  • random_seed::String: Random seed for reproducibility (default: "00000000000000000000000000000000")
  • graph::DesmosGraph: Graph configuration including viewport settings
  • expressions::DesmosExpressions: Collection of all expressions, text, images, etc.

Examples

using Desmos

# Create using @desmos macro (recommended)
state = @desmos begin
    @text "Example graph"
    sin(x)
    cos(x)
end

# Serialize to JSON
using JSON
json_string = JSON.json(state)

# Display in Jupyter/VSCode
display(state)  # Shows interactive Desmos graph

JSON I/O

DesmosState can be parsed from JSON files exported from Desmos:

using JSON

# Read from file
json_data = read("graph.json", String)
state = JSON.parse(json_data, DesmosState)

# Write to file
write("graph.json", JSON.json(state, 4))

See also

  • @desmos: Macro for creating DesmosState objects
source
Desmos._latexifyFunction
_latexify(ex) -> String

Convert a Julia expression to LaTeX string. Main dispatcher for different expression types.

source
Desmos.clipboard_desmos_stateMethod
clipboard_desmos_state()

Import a Desmos graph state from clipboard.

This function reads JSON data from the system clipboard and parses it into a DesmosState object. Useful for importing graphs that were edited in the Desmos calculator and exported using the "Export State to Clipboard" button (available when clipboard=true).

Examples

# Enable clipboard mode
Desmos.set_display_options(clipboard=true)

# Display a graph
state = @desmos begin
    y = x^2
end

# Edit the graph in the plot pane and click "Export State to Clipboard"
# Then import the modified state
modified_state = Desmos.clipboard_desmos_state()

Notes

  • Requires clipboard access (uses clipboard() function)
  • The clipboard must contain valid Desmos state JSON
  • Throws an error if the JSON is invalid or cannot be parsed
source
Desmos.desmos_latexifyMethod
desmos_latexify(ex) -> LaTeXString

Convert Julia expressions to LaTeX strings suitable for Desmos. This is a simpler, Desmos-focused alternative to Latexify.latexify.

source
Desmos.set_desmos_display_configMethod
set_desmos_display_config(; width=nothing, height=nothing, clipboard=nothing, api_version=nothing, api_key=nothing)

Set display options for Desmos graphs.

Arguments

  • width::Int: Width of the Desmos container in pixels
  • height::Int: Height of the Desmos container in pixels
  • clipboard::Bool: Enable clipboard export button
  • api_version::Int: Desmos API v1 minor version (e.g., 10 for v1.10)
  • api_key::String: Desmos API key

Examples

# Set clipboard mode with custom size
Desmos.set_desmos_display_config(width=800, height=600, clipboard=true)

# Enable only clipboard mode
Desmos.set_desmos_display_config(clipboard=true)

# Set custom API version and key (e.g., v1.11)
Desmos.set_desmos_display_config(api_version=11, api_key="your-api-key-here")
source
Desmos.@desmosMacro
@desmos begin ... end

Create a DesmosState object from a block of mathematical expressions.

The @desmos macro provides a convenient DSL for creating Desmos graphs programmatically. Each line in the block is converted to a Desmos expression, and the macro returns a DesmosState object that can be serialized to JSON or displayed in Jupyter/VSCode.

Supported syntax

  • Mathematical expressions: sin(x), x^2 + y^2, etc.
  • Text annotations: @text "Description"
  • Styled expressions: @expression cos(x) color=RGB(1,0,0)
  • Parametric curves: @expression (cos(t), sin(t)) parametric_domain=0..2π
  • Variable assignments: a = 5
  • Sliders: @expression b = 3 slider=1..10
  • Domain restrictions: @expression f(x) domain=-5..5
  • Images: @image image_url="..." width=10 height=10
  • Dollar interpolation: Use $(expr) to evaluate Julia expressions at macro expansion time

Examples

# Basic trigonometric functions
state = @desmos begin
    @text "Trigonometric functions"
    sin(x)
    cos(x)
    tan(x)
end

# With colors and styling
state = @desmos begin
    @expression sin(x) color=RGB(1, 0, 0)
    @expression cos(x) color="#0000ff"
end

# Parametric curve
state = @desmos begin
    @expression (cosh(t), sinh(t)) parametric_domain=-2..3
end

# Variables and sliders
b = 3
state = @desmos begin
    a = 4
    @expression c = 5 slider=2..6
    sin($(2b) * a - c * x)
end

# With domain restrictions
state = @desmos begin
    @expression x^2 domain=-5..5
end

See also

  • DesmosState: The state object returned by this macro
  • @expression: Macro for creating expressions with options
  • @text: Macro for adding text annotations
  • @image: Macro for adding images
source
Desmos.@expressionMacro
@expression expr [options...]

Create a DesmosExpression with additional styling and behavior options.

This macro is used within a @desmos block to create expressions with customization options such as color, sliders, domains, and visibility settings.

Options

  • color: Set the color using RGB(r,g,b) or hex string like "#ff0000"
  • slider: Create a slider from a range (e.g., 1..10 or 1:2:10)
  • domain: Restrict the domain using an interval (e.g., -5..5)
  • parametric_domain: Set domain for parametric curves (e.g., 0..2π)
  • lines: Boolean to show/hide connecting lines
  • hidden: Boolean to hide the expression initially
  • id: Custom ID string for the expression

Examples

julia> Desmos.@expression sin(x) color=RGB(1, 0, 0)
Desmos.DesmosExpression("expression", "0", "#FF0000", nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, L"\sin\left(x\right)", nothing, nothing, nothing, nothing, nothing, nothing)

julia> Desmos.@expression cos(x) color="#0000ff"
Desmos.DesmosExpression("expression", "0", "#0000ff", nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, L"\cos\left(x\right)", nothing, nothing, nothing, nothing, nothing, nothing)

julia> Desmos.@expression a = 3 slider=1..10
Desmos.DesmosExpression("expression", "0", "#000000", nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, L"a=3", Desmos.DesmosSlider(true, true, nothing, nothing, nothing, "1", "10", nothing), nothing, nothing, nothing, nothing, nothing)

julia> Desmos.@expression b = 5 slider=1:0.5:10
Desmos.DesmosExpression("expression", "0", "#000000", nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, L"b=5", Desmos.DesmosSlider(true, true, nothing, nothing, nothing, "1.0", "10.0", "0.5"), nothing, nothing, nothing, nothing, nothing)

julia> Desmos.@expression (cos(t), sin(t)) parametric_domain=0..2π
Desmos.DesmosExpression("expression", "0", "#000000", nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, L"\left(\cos\left(t\right),\sin\left(t\right)\right)", nothing, nothing, Desmos.DesmosParametricDomain("0.0", "6.283185307179586"), nothing, nothing, nothing)

julia> Desmos.@expression x^2 domain=-5..5
Desmos.DesmosExpression("expression", "0", "#000000", nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, L"x^{2}", nothing, Desmos.DesmosDomain(L"-5", L"5"), nothing, nothing, nothing, nothing)

julia> Desmos.@expression f(x) = x^3 hidden=true
Desmos.DesmosExpression("expression", "0", "#000000", nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, true, L"f\left(x\right)=x^{3}", nothing, nothing, nothing, nothing, nothing, nothing)

julia> Desmos.@expression L"\\frac{x^2}{4} + \\frac{y^2}{9} = 1" color=RGB(0, 0.5, 1)
Desmos.DesmosExpression("expression", "0", "#0080FF", nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, L"\\frac{x^2}{4} + \\frac{y^2}{9} = 1", nothing, nothing, nothing, nothing, nothing, nothing)

See also

  • @desmos: Main macro for creating Desmos graphs
  • @text: Add text annotations
  • @image: Add images to the graph
source
Desmos.@imageMacro
@image options...

Add an image to the Desmos graph.

This macro creates a DesmosImage object that can be positioned and sized on the graph. Images are specified via URL and can be customized with various display options.

Options

  • image_url: URL of the image (required)
  • width: Width of the image in graph units
  • height: Height of the image in graph units
  • name: Display name for the image
  • hidden: Boolean to hide the image initially
  • id: Custom ID string for the image

Examples

julia> Desmos.@image image_url="https://example.com/plot.png" name="Background" width=20 height=15
Desmos.DesmosImage("image", "0", "https://example.com/plot.png", nothing, "Background", "20", "15", nothing, nothing, nothing, nothing, nothing)

See also

source
Desmos.@textMacro
@text "text" [options...]

Add a text annotation to the Desmos graph.

This macro creates a DesmosText object for displaying textual information on the graph, such as titles, labels, or descriptions.

Options

  • id: Custom ID string for the text element

Examples

julia> Desmos.@text "Sample text"
Desmos.DesmosText("text", "0", "Sample text", nothing)

See also

source