Skip to content

Global Defaults

SummaryTables provides a global defaults system that allows you to set default values for commonly used formatting parameters across all table functions. This feature is particularly useful when you want to maintain consistent formatting throughout a document or application without having to specify the same parameters repeatedly.

The system provides two public functions: SummaryTables.defaults! for setting global defaults and SummaryTables.with_defaults for temporary scoped changes.

SummaryTables.defaults! Function
julia
defaults!(; kwargs...)

Changes the default settings (implemented via ScopedValues) in the current dynamic scope. A new scope is created with with_defaults, otherwise you are modifying the global scope. This could be done, e.g., at the start of a script or notebook.

Mutation of the settings happens under lock and is therefore threadsafe. However, you should use with_defaults instead if you intend to change defaults only for some task without affecting other tasks.

The available settings are:

round_mode: Rounding mode for floats, can be :auto, :digits or :sigdigits. Default = :auto MarkdownAST.LineBreak()

round_digits: Number of digits to target when rounding floats. Default = 3 MarkdownAST.LineBreak()

trailing_zeros: If false, removes trailing zeros when formatting floats. Default = false MarkdownAST.LineBreak()

linebreak_footnotes: If true, each footnote is displayed on a separate line. Default = true MarkdownAST.LineBreak()

annotation_labels: An indexable collection or a Symbol that specifies a predefined collection which contains annotation labels. Predefined variants are :numbers, :lowercase, :uppercase, :roman_lower and :roman_upper. Default = :numbers

source

Persistent Defaults

Use SummaryTables.defaults! to change the global default settings that will apply to all subsequently created tables:

julia
using SummaryTables

SummaryTables.defaults!(round_mode = :digits, round_digits = 4, trailing_zeros = true)

numbers = [1.23456 2.3456; 34.56789 4.5000]
Table(Cell.(numbers))
1.2346 2.3456
34.5679 4.5000

Note that explicit settings override the defaults:

julia
Table(Cell.(numbers), trailing_zeros = false)
1.2346 2.3456
34.5679 4.5

The defaults! function does not selectively update but it applies the keywords on top of SummaryTables's own defaults. To reset to the package defaults, you therefore specify no keywords.

julia
SummaryTables.defaults!()

Table(Cell.(numbers))
1.23 2.35
34.6 4.5

Temporary Scoped Defaults

Use SummaryTables.with_defaults to temporarily change default settings for a specific block of code without affecting the global settings. This is implemented via ScopedValues.jl, so you can use with_defaults in multiple separate tasks without interference between them. Within a with_defaults block you can again modify settings using defaults! and these changes will persist until the scope ends.

julia
# Use different defaults temporarily
SummaryTables.with_defaults(round_mode = :sigdigits, round_digits = 4, trailing_zeros = false) do
    numbers = [1.23456 2.3456; 34.56789 4.5000]
    Table(Cell.(numbers))
end
1.235 2.346
34.57 4.5