Typst Backend
The Typst backend can be selected by passing the keyword backend = :typst to the function pretty_table. In this case, we have the following additional keywords to configure the output:
Keywords
annotate::Bool: Boolean indicating whether Typst code should be annotated.caption::Union{Nothing, String, TypstCaption}: Table caption to be used by the Typst#figurefunction. The user can provide additional configuration to the caption by using theTypstCaptionstructure.data_column_widths::Union{Nothing, String, Vector{String}, Vector{Pair{Int, String}}}: Column widths for the data columns. The information must be a valid length information in Typst, such as "10fr" or "30pt". If a single string is provided, it will be repeated for all columns. If a vector of strings is provided, its length must be equal to or larger than the number of printed columns. Alternatively, a vector of pairs can be provided, where the first element of the pair is the column index and the second element is the width for that column. In this case, columns that are not specified will have widthauto. (Default =nothing)highlighters::Vector{<:AbstractHighlighter}: Highlighters to apply to the table. For more information, see the section Typst Highlighters. (Default =AbstractHighlighter[])line_breaks::Bool: Iftrue, line breaks in the content of the cells (\n) are rendered as Typst line breaks. Otherwise, they are escaped. (Default =false)minify::Bool: Iftrue, the generated Typst code will be minified by ignoringwrap_columnand printing the table columns in the same line. (Default =false)style::Union{TableStyle, TypstTableStyle}: Style of the table. The fields of the backend-agnosticTableStyleoverride the ones of the default Typst table style. For more information, see the section Typst Table Style. (Default =TypstTableStyle())table_format::Union{TableFormat, TypstTableFormat}: Typst table format used to render the table. The backend-agnosticTableFormatis fully supported: its line presence fields override the ones of the default Typst table format, and the line design is converted to strokes bytypst_line_style. For more information, see the section Typst Table Format.wrap_column::Integer: Indicates the column where the output will be wrapped. (Default =92)
The content in the cells is always escaped. If you want to use a raw Typst component as cell, load the package Typstry.jl and pass the cell content as a TypstString. In this case, the content will not be escaped and will be treated as a raw Typst component.
Typst Highlighters
A set of highlighters can be passed as a vector of AbstractHighlighter to the highlighters keyword. A highlighter can be an instance of the general Highlighter, which is defined by a Face and works with every back end (see Highlighters), or of the structure TypstHighlighter, specific to this back end. The face of a general highlighter is converted with typst_decoration. The structure TypstHighlighter contains the following two public fields:
f::Function: Function with the signaturef(data, i, j), which should returntrueif the element(i, j)indatamust be highlighted, orfalseotherwise.fd::Function: Function with the signaturefd(h, data, i, j), wherehis the highlighter. This function must return aVector{Pair{String, String}}with properties compatible with thestylefield that will be applied to the highlighted cell.
A Typst highlighter can be constructed using the following helpers:
TypstHighlighter(f::Function, decoration::TypstPair)
TypstHighlighter(f::Function, decoration::Vector{TypstPair})
TypstHighlighter(f::Function, fd::Function)The first two apply a fixed decoration to the highlighted cell, whereas the third lets the user select the desired decoration by specifying the function fd. The decoration can also be created from a Face, which is converted with typst_decoration, or from the keywords of Face:
TypstHighlighter(f::Function, face::Face)
TypstHighlighter(f::Function; kwargs...)If multiple highlighters are valid for element (i, j), the applied style is the first match according to the order in the vector highlighters.
If highlighters are used together with Formatters, formatting changes will not affect the parameter data passed to the highlighter function f. It will always receive the original, unformatted value.
For example, if we want to highlight the cells with values greater than 5 in red, and all the cells with values less than 5 in blue, we can define:
hl_gt5 = TypstHighlighter(
(data, i, j) -> data[i, j] > 5,
["text-fill" => "red"]
)
hl_lt5 = TypstHighlighter(
(data, i, j) -> data[i, j] < 5,
["text-fill" => "blue"]
)
highlighters = [hl_gt5, hl_lt5]Each cell with properties is rendered with one call to #text inside a table.cell function, as shown below:
table.cell()[#text()[Cell Content]]Since table.cell and #text() share some attribute names, attributes used by the #text function must be defined with the text- prefix. For example, to create a table style (or highlighter) that sets a blue background and white font color:
["fill" => "blue", "text-fill" => "white"]Typst Table Format
The Typst table format is defined using an object of type TypstTableFormat that contains the following fields:
borders::TypstTableBorders: Format of the borders.horizontal_line_at_beginning::Bool: Iftrue, a horizontal line will be drawn at the beginning of the table.horizontal_line_at_merged_column_labels::Bool: Iftrue, a horizontal line will be drawn at the bottom of the merged column labels usingtable.hline.horizontal_line_after_column_labels::Bool: Iftrue, a horizontal line will be drawn after the column labels.horizontal_lines_at_data_rows::Union{Symbol, Vector{Int}}: A horizontal line will be drawn after each data row index listed in this vector. If the symbol:allis passed, a horizontal line will be drawn after every data row. If the symbol:noneis passed, no horizontal lines will be drawn after the data rows. The line after the last data row is only drawn ifhorizontal_line_after_data_rowsistrue.horizontal_line_before_row_group_label::Bool: Iftrue, a horizontal line will be drawn before the row group label.horizontal_line_after_row_group_label::Bool: Iftrue, a horizontal line will be drawn after the row group label.horizontal_line_after_data_rows::Bool: Iftrue, a horizontal line will be drawn after the data rows.horizontal_line_before_summary_rows::Bool: Iftrue, a horizontal line will be drawn before the summary rows. Notice that this line is the same as the one drawn ifhorizontal_line_after_data_rowsistrue. However, in this case, the line is omitted if there are no summary rows.horizontal_line_after_summary_rows::Bool: Iftrue, a horizontal line will be drawn after the summary rows.vertical_line_at_beginning::Bool: Iftrue, a vertical line will be drawn at the beginning of the table.vertical_line_after_row_number_column::Bool: Iftrue, a vertical line will be drawn after the row number column.vertical_line_after_row_label_column::Bool: Iftrue, a vertical line will be drawn after the row label column.vertical_lines_at_data_columns::Union{Symbol, Vector{Int}}: A vertical line will be drawn after each data column index listed in this vector. If the symbol:allis passed, a vertical line will be drawn after every data column. If the symbol:noneis passed, no vertical lines will be drawn after the data columns.vertical_line_after_data_columns::Bool: Iftrue, a vertical line will be drawn after the data columns.vertical_line_after_continuation_column::Bool: Iftrue, a vertical line will be drawn after the continuation column.
We provide a few helpers to configure the table format. For more information, see the documentation of the following macros:
@typst__all_horizontal_lines.@typst__all_vertical_lines.@typst__no_horizontal_lines.@typst__no_vertical_lines.
Typst Table Style
The Typst table style is defined using an object of type TypstTableStyle that contains the following fields:
table::Vector{TypstPair}: Style for the table.title::Vector{TypstPair}: Style for the title.subtitle::Vector{TypstPair}: Style for the subtitle.row_number_label::Vector{TypstPair}: Style for the row number label.row_number::Vector{TypstPair}: Style for the row number.stubhead_label::Vector{TypstPair}: Style for the stubhead label.row_label::Vector{TypstPair}: Style for the row label.row_group_label::Vector{TypstPair}: Style for the row group label.first_line_column_label::Union{Vector{TypstPair}, Vector{Vector{TypstPair}}}: Style for the first line of the column labels. If a vector ofVector{TypstPair}is provided, each column label in the first line will use the corresponding style.column_label::Union{Vector{TypstPair}, Vector{Vector{TypstPair}}}: Style for the rest of the column labels. If a vector ofVector{TypstPair}is provided, each column label will use the corresponding style.first_line_merged_column_label::Vector{TypstPair}: Style for the merged cells at the first column label line.merged_column_label::Vector{TypstPair}: Style for the merged cells at the rest of the column labels.summary_row_cell::Vector{TypstPair}: Style for the summary row cell.summary_row_label::Vector{TypstPair}: Style for the summary row label.footnote::Vector{TypstPair}: Style for the footnote.omitted_cell_summary::Vector{TypstPair}: Style for the omitted cell summary.source_note::Vector{TypstPair}: Style for the source notes.
Each field is a vector of TypstPair, i.e. Pair{String, String}, describing properties and values compatible with the Typst style attribute.
For example, if we want the stubhead label to be bold and red, we must define:
style = TypstTableStyle(
stubhead_label = ["text-weight" => "bold", "text-fill" => "red"]
)The user can pass any property compatible with the Typst style attribute. If the prefix text- is used, the property will be applied to the text of the cell. Otherwise, it will be applied to the cell itself.
Every keyword of the constructor of TypstTableStyle also accepts a Face, which is converted to Typst properties with typst_decoration (see Faces). Hence, the previous style can also be defined as:
style = TypstTableStyle(
stubhead_label = Face(; weight = :bold, foreground = :red)
)If only the fields shared by all the back ends are needed, the backend-agnostic TableStyle can be used instead (see Table Format and Style).