Universe

A Typst package to use gnuplot in Typst.

#import "@preview/neoplot:0.0.2" as gp

Execute gnuplot commands:

#gp.exec(
    kind: "command",
    ```gnuplot
    reset;
    set samples 1000;
    plot sin(x),
         cos(x)
    ```
)

Execute a gnuplot script:

#gp.exec(
    ```gnuplot
    reset
    # Can add comments since it is a script
    set samples 1000
    # Use a backslash to extend commands
    plot sin(x), \
         cos(x)
    ```
)

To read a data file:

# datafile.dat
# x  y
  0  0
  2  4
  4  0
#gp.exec(
    ```gnuplot
    $data <<EOD
    0  0
    2  4
    4  0
    EOD
    plot $data with linespoints
    ```
)

or

#gp.exec(
    // Use a datablock since Typst doesn't support WASI
    "$data <<EOD\n" +
    // Load "datafile.dat" using Typst
    read("datafile.dat") +
    "EOD\n" +
    "plot $data with linespoints"
)

To print $data:

#gp.exec("print $data")