HTML Generation

JSXGraph.jl generates self-contained HTML output that renders interactive JSXGraph boards in any modern browser. The HTML generation engine supports both inline asset embedding and CDN-based asset loading.

Creating a Board

Use the keyword constructor to create a board with common options:

using JSXGraph

# Basic board with default settings
board = Board("myboard")

# Board with custom axis ranges
board = Board("myboard", xlim=(-10, 10), ylim=(-5, 5))

# Board with grid and custom dimensions
board = Board("myboard", grid=true, width=600, height=400)

If you pass an empty string as the id, a unique identifier is auto-generated:

board = Board("")  # id is auto-generated

Generating HTML

Full Page

Generate a complete HTML document that can be opened directly in a browser:

html = html_string(board)
# or equivalently:
html = html_page(board)

Fragment

Generate an embeddable HTML fragment (div + script, no DOCTYPE/head/body):

html = html_string(board; full_page=false)
# or equivalently:
html = html_fragment(board)

CDN Mode

Generate smaller output by referencing JSXGraph from a CDN instead of inlining the full library:

html = html_string(board; asset_mode=:cdn)

CDN mode produces output that is at least 80% smaller than inline mode, but requires an internet connection when viewing.

Saving to File

Save a board as a self-contained HTML file:

board = Board("myboard", xlim=(-5, 5), ylim=(-5, 5))
push!(board, point(1, 2; color="red"))

# Save with inlined assets (default — works offline)
save("plot.html", board)

# Save with CDN references (smaller file, needs internet)
save("plot_cdn.html", board; asset_mode=:cdn)

Version Information

The bundled JSXGraph library version is available as:

JSXGRAPH_VERSION  # "1.12.2"

API Reference

JSXGraph.html_stringFunction
html_string(board; full_page, asset_mode)

Generate an HTML string for a board.

Arguments

  • board::Board: The board to render
  • full_page::Bool=true: Generate a complete HTML document (true) or embeddable fragment (false)
  • asset_mode::Symbol=:inline: :inline embeds JS/CSS; :cdn references CDN URLs

Examples

board = Board("myboard", xlim=(-5,5), ylim=(-5,5))
html = html_string(board)                          # full page, inline assets
html = html_string(board; full_page=false)          # fragment
html = html_string(board; asset_mode=:cdn)          # CDN references
source
JSXGraph.html_pageFunction
html_page(board; kwargs...)

Generate a complete HTML page for a board.

Equivalent to html_string(board; full_page=true, kwargs...).

source
JSXGraph.html_fragmentFunction
html_fragment(board; kwargs...)

Generate an HTML fragment for a board (no DOCTYPE/head/body).

Equivalent to html_string(board; full_page=false, kwargs...).

source
JSXGraph.saveFunction
save(filename, board; asset_mode, scale)

Save a board to a file.

Dispatches on the file extension:

  • .html (default): writes a self-contained HTML document
  • .svg: exports a static SVG image (requires NodeJS22jll)
  • .png: exports a PNG image (requires NodeJS22jll)
  • .pdf: exports a PDF document (requires NodeJS22jll)

Arguments

  • filename::String: Output file path (.html, .svg, .png, .pdf)
  • board::Board: The board to save
  • asset_mode::Symbol=:inline: for HTML output — :inline embeds JS/CSS; :cdn references CDN URLs
  • scale::Int=1: for PNG output — resolution multiplier (1 = native, 2 = Retina)

Examples

board = Board("myboard", xlim=(-5,5), ylim=(-5,5))
push!(board, point(1, 2))
save("plot.html", board)
save("plot_cdn.html", board; asset_mode=:cdn)
save("plot.svg", board)
save("plot.png", board)           # PNG export
save("plot_hd.png", board; scale=2) # 2× resolution PNG
save("plot.pdf", board)           # PDF export
source