[ANN] Typst back end for PrettyTables.jl

Hi everyone!

After an amazing work of @gustavohtc23, PrettyTables.jl now has a Typst back end!

If you load it together with Typstry.jl, you can have a very nice experience in VS Code where all tables shown to stdout using the new back end are rendered in the screen.

For example, if you run the following code in Julia REPL inside VS Code:

using PrettyTables, Typstry

# == Creating the Table ====================================================================

v1_t = 0:5:20

v1_a = ones(length(v1_t)) * 1.0

v1_v = @. 0 + v1_a * v1_t

v1_d = @. 0 + v1_a * v1_t^2 / 2

v2_t = 0:5:20

v2_a = ones(length(v2_t)) * 0.75

v2_v = @. 0 + v2_a * v2_t

v2_d = @. 0 + v2_a * v2_t^2 / 2

table = [
  v1_t v1_a v1_v v1_d
  v2_t v2_a v2_v v2_d
]

# == Configuring the Table =================================================================

title = "Table 1. Data obtained from the test procedure."

subtitle = "Comparison between two vehicles"

column_labels = [
    [EmptyCells(2), MultiColumn(2, "Estimated Data")],
    ["Time (s)", "Acceleration", "Velocity", "Position"],
]

units = [
  typst"#text(fill: gray)[\[s\]]",
  typst"#text(fill: gray)[\[m / s²\]]",
  typst"#text(fill: gray)[\[m / s\]]",
  typst"#text(fill: gray)[\[m\]]",
]

push!(column_labels, units)

merge_column_label_cells = :auto

row_group_labels = [
    1 => "Vehicle #1",
    6 => "Vehicle #2"
]

summary_rows = [
    (data, j) -> maximum(@views data[ 1:5, j]),
    (data, j) -> maximum(@views data[6:10, j]),
]

summary_row_labels = [
    "Max. for Vehicle #1",
    "Max. for Vehicle #2",
]

footnotes = [
    (:column_label, 1, 3) => "Estimated data based on the acceleration measurement."
]

highlighters = [
    TypstHighlighter((data, i, j) -> (j == 3) && (data[i, j] > 10), ["text-fill" => "red", "text-weight" => "bold"])
    TypstHighlighter((data, i, j) -> (j == 4) && (data[i, j] > 10), ["text-fill" => "blue", "text-weight" => "bold"])
]

# == Printing the Table ====================================================================

pretty_table(
    table;
    backend = :typst,
    column_labels,
    footnotes,
    highlighters,
    merge_column_label_cells,
    row_group_labels,
    subtitle,
    summary_row_labels,
    summary_rows,
    title,
)

You get:

Currently, we do not have a table format option where you can configure the vertical and horizontal lines. However, I am planning to add this new feature next week.

8 Likes