The tabelline book

tabelline makes display tables in Nim: tables meant to be read by people, with a header, a stub, row groups, spanners over columns, formatted numbers, colours and notes. It follows R's gt and Python's Great Tables. This book takes their guides and examples and ports them to tabelline, one page at a time, with the original next to the port.

Every example comes in three tabs: 👑 Nim, the tabelline version, run when the book is built, 🐍 Python, the original Great Tables code with the table it makes, and 🏴‍☠️ R, the same table made with gt, written for this book. Pick a tab once and every example follows. The text of the original is kept as it is; what the book has to say about tabelline (how it differs, what it lacks yet) is in boxes marked × tabelline.

Hello, tables

The times table, la tavola pitagorica, the first table every Italian pupil learns:

import tabelline, tabelline/datasets

let tavola = tabella(tavolaPitagorica(5), rownameCol = "×"):
  tabHeader "Le tabelline"
  tabStubhead "×"
nbTable tavola
Le tabelline
×12345
112345
2246810
33691215
448121620
5510152025

What is here

  • Great Tables: Get Started: the first section of the Great Tables user guide, page by page, from the parts of a table to formats, nanoplots, styles, themes and selections.
  • Great Tables: the blog: the posts of the Great Tables blog that show what a release brought: the introduction, data colouring, column widths, options and images, nanoplots.
  • gt: articles: the longer articles of gt's documentation, in R first: summary rows, and the case studies that build one table from start to finish.
  • What the book will port: every source planned, page by page, with what each page needs and the release of tabelline that can port it.
  • Find an example by feature: for every feature of tabelline, the pages of the sources that show it, the help pages of gt and Great Tables first.
  • What the port found: everything tabelline still lacks to do what the guide, the posts and the articles do, in one list, for the next releases, and what 0.2 closed. What 0.1 gained from it is told in the devlog, What the book found for 0.1.

What the book will port

The Get Started guide is the first source; these are the others, from the simplest to the most complex. For each, how many of its pages tabelline can port now and how many wait for a release, by the gt functions their code calls; What the book will port has every page and what it waits for. The last two are not read in order: they are the help pages of every function of Great Tables and gt, each with its examples, found by feature in Find an example by feature. The entries of the Posit Table Contest, with what each waits for, are in The Table Contest.

SourcePagesCan be ported
Great Tables: Get Started
MIT licence
18ported
gt: Introduction to Creating gt Tables
MIT licence
11 now
Great Tables blog
MIT licence
2312 ported
9 now
1 with a new gap
1 later
Great Tables examples
MIT licence
32 now
1 later
gt: case studies and articles
MIT licence
63 ported
1 now
1 later
gt-extras
MIT licence
51 now
2 later
gtExtras
MIT licence
11 later
Posit Table Contest entries
per entry licence
1941 ported
37 now
48 later
108 not with gt
Great Tables API reference examples
MIT licence
104102 now
2 later
gt reference examples
MIT licence
173153 now
20 later

Sources still to be mapped, once their pages are listed:

SourceWhat it has
pandas Styler user guide
BSD-3-Clause licence
Styling a data frame in pandas: the same tables seen from the data frame
gtsummary
MIT licence
Summary and regression tables on top of gt: needs statistics, not only tables
reactable
MIT licence
Interactive tables: for tabellone, the grid idea

Sources and licences

Each ported page starts with a box that names its source, its authors and its licence, and says what the port changed. The sources and their licences are listed in Sources and licences. The book's own text and code are MIT licensed, as tabelline.

How the book is built

From the simplest piece to the whole book.

A page. Every page is a nimib notebook, a Nim program in book/: bookInit() starts it, nbText writes text, nbCode runs Nim and shows the code with what it prints, nbTable (from tabelline/nimib) shows a table, and bookSave() writes the page. nimibook adds what makes pages a book: the table of contents (book/nbook.nim), the sidebar, the previous and next buttons, the search.

A box. tabelline "..." puts the book's own remarks in a box of their own, so the text of the original stays as it was; attribution is the box at the top of a ported page.

Tabs. tabs py, r: body runs the Nim blocks of body and puts them, rendered, in the 👑 Nim tab, next to two empty tabs for the Python and the R. A small script (book/theme/book.js) shows the tab you pick, in every example, and remembers it. sideBySide puts a few small examples next to each other.

Python and R. When a page is saved, its Python cells, all of them in order, go to book/gt/run.py, which runs them with Great Tables in one namespace, like the cells of a notebook, and gives back what each printed and the HTML of its last value; the R cells go to book/gt/run.R, which does the same with gt. The answers are kept with the cells in book/gt/outputs/ and book/gt/outputs-r/, which are committed: when the cells have not changed, they are read from there, and neither Python nor R runs. The tables' random ids are seeded with the page's name, so the same cells give the same HTML. The code of the three languages is highlighted when the page is built, so a page loads no highlighter.

A page as data. bookSave() also writes the page as JSON (docs/book/<page>.json): its blocks, already rendered, and its source.

Only what changed. nim r book/bookbuild.nim adds to each page's JSON a record of every file the page depended on, with its hash: what Nim compiled for it (its own list, with -d:nimBetterRun: the page, the helpers, tabelline, nimib, nimibook and the data it reads while compiling), its Python and R outputs, and the Nim version. A page whose record still matches is not run again. The pages that changed are compiled as one program, so tabelline and nimib are compiled once; if that fails, they are built one by one, and a failing page gets its own log.

Then every page. One last pass renders every page from its JSON with the current theme and table of contents: adding a page or changing the look runs no page again. The look is nimibook's, with book/theme/edo.css (the Munari look in the Edo palette) added to it.

In CI. The workflow that publishes tabelline's pages starts from the JSON of the published book (BOOK_FROM), so a pull request runs only the pages it changed; it never runs Python or R (BOOK_NO_PYTHON, BOOK_NO_R: a page whose outputs are out of date fails, and says how to update them). Every change to tabelline reruns every page, so a page that no longer works shows up in the pull request that broke it. The Great Tables side ran with the version pinned in book/gt/uv.lock (Great Tables 1.1.0), the R side with gt 1.4.0 (R 4.3).

import tabbook, sources
bookInit()

nbText: """
# The tabelline book

[tabelline](https://github.com/pietroppeter/tabelline) makes display tables in Nim: tables meant
to be read by people, with a header, a stub, row groups, spanners over columns, formatted
numbers, colours and notes. It follows R's [gt](https://gt.rstudio.com) and Python's
[Great Tables](https://posit-dev.github.io/great-tables/). This book takes their guides and
examples and ports them to tabelline, one page at a time, with the original next to the port.

Every example comes in three tabs: **👑 Nim**, the tabelline version, run when the book is
built, **🐍 Python**, the original Great Tables code with the table it makes, and **🏴‍☠️ R**, the
same table made with gt, written for this book. Pick a tab once and every example follows. The text of the original is kept as it is; what the book has to say
about tabelline (how it differs, what it lacks yet) is in boxes marked **× tabelline**.

## Hello, tables

The times table, *la tavola pitagorica*, the first table every Italian pupil learns:
"""

tabs """
import polars as pl
from great_tables import GT

tavola = pl.DataFrame(
    {"×": list(range(1, 6))} | {str(j): [i * j for i in range(1, 6)] for j in range(1, 6)}
)
GT(tavola, rowname_col="×").tab_header("Le tabelline").tab_stubhead("×")
""", """
library(gt)

tavola <- data.frame(`×` = 1:5, outer(1:5, 1:5), check.names = FALSE)
names(tavola)[-1] <- 1:5

gt(tavola, rowname_col = "×") |> tab_header("Le tabelline") |> tab_stubhead("×")
""":
  nbCode:
    import tabelline, tabelline/datasets

    let tavola = tabella(tavolaPitagorica(5), rownameCol = "×"):
      tabHeader "Le tabelline"
      tabStubhead "×"
    nbTable tavola

tabelline """
`tavolaPitagorica(n)` is one of tabelline's datasets, with `planets`, `isole`, `citta` and
gt's `exibble`.
"""

nbText: """
## What is here

- **Great Tables: Get Started**: the first section of the
  [Great Tables user guide](https://posit-dev.github.io/great-tables/user-guide/introduction.html), page by
  page, from the parts of a table to formats, nanoplots, styles, themes and selections.
- **Great Tables: the blog**: the posts of the Great Tables blog that show what a release
  brought: the introduction, data colouring, column widths, options and images, nanoplots.
- **gt: articles**: the longer articles of gt's documentation, in R first: summary rows, and
  the case studies that build one table from start to finish.
- **What the book will port**: every source planned, page by page, with what each page needs
  and the release of tabelline that can port it.
- **Find an example by feature**: for every feature of tabelline, the pages of the sources that
  show it, the help pages of gt and Great Tables first.
- **What the port found**: everything tabelline still lacks to do what the guide, the posts and the articles do, in one
  list, for the next releases, and what 0.2 closed. What 0.1 gained from it is told in the devlog,
  [What the book found for 0.1](https://pietroppeter.github.io/tabelline/devlog/book-found/).

## What the book will port

The Get Started guide is the first source; these are the others, from the simplest to the most
complex. For each, how many of its pages tabelline can port now and how many wait for a
release, by the gt functions their code calls; [What the book will port](next.html) has every
page and what it waits for. The last two are not read in order: they are the help pages of every
function of Great Tables and gt, each with its examples, found by feature in
[Find an example by feature](features.html). The entries of the Posit Table Contest, with what
each waits for, are in [The Table Contest](contest.html).
"""

nbTable sourcesTable()

nbText: """
Sources still to be mapped, once their pages are listed:
"""

nbTable candidatesTable()

nbText: """
## Sources and licences

Each ported page starts with a box that names its source, its authors and its licence, and says
what the port changed. The sources and their licences are listed in
[Sources and licences](licences.html). The book's own text and code are MIT licensed, as
tabelline.

## How the book is built

From the simplest piece to the whole book.

**A page.** Every page is a [nimib](https://github.com/pietroppeter/nimib) notebook, a Nim
program in `book/`: `bookInit()` starts it, `nbText` writes text, `nbCode` runs Nim and shows
the code with what it prints, `nbTable` (from `tabelline/nimib`) shows a table, and
`bookSave()` writes the page. [nimibook](https://github.com/pietroppeter/nimibook) adds what
makes pages a book: the table of contents (`book/nbook.nim`), the sidebar, the previous and
next buttons, the search.

**A box.** `tabelline "..."` puts the book's own remarks in a box of their own, so the text of
the original stays as it was; `attribution` is the box at the top of a ported page.

**Tabs.** `tabs py, r: body` runs the Nim blocks of `body` and puts them, rendered, in the 👑 Nim
tab, next to two empty tabs for the Python and the R. A small script (`book/theme/book.js`)
shows the tab you pick, in every example, and remembers it. `sideBySide` puts a few small
examples next to each other.

**Python and R.** When a page is saved, its Python cells, all of them in order, go to
`book/gt/run.py`, which runs them with Great Tables in one namespace, like the cells of a
notebook, and gives back what each printed and the HTML of its last value; the R cells go to
`book/gt/run.R`, which does the same with gt. The answers are kept with the cells in
`book/gt/outputs/` and `book/gt/outputs-r/`, which are committed: when the cells have not
changed, they are read from there, and neither Python nor R runs. The tables' random ids are
seeded with the page's name, so the same cells give the same HTML. The code of the three
languages is highlighted when the page is built, so a page loads no highlighter.

**A page as data.** `bookSave()` also writes the page as JSON (`docs/book/<page>.json`): its
blocks, already rendered, and its source.

**Only what changed.** `nim r book/bookbuild.nim` adds to each page's JSON a record of every
file the page depended on, with its hash: what Nim compiled for it (its own list, with
`-d:nimBetterRun`: the page, the helpers, tabelline, nimib, nimibook and the data it reads
while compiling), its Python and R outputs, and the Nim version. A page whose record still
matches is not run again. The pages that changed are compiled as one program, so tabelline and
nimib are compiled once; if that fails, they are built one by one, and a failing page gets its
own log.

**Then every page.** One last pass renders every page from its JSON with the current theme and
table of contents: adding a page or changing the look runs no page again. The look is
nimibook's, with `book/theme/edo.css` (the Munari look in the Edo palette) added to it.

**In CI.** The workflow that publishes tabelline's pages starts from the JSON of the published
book (`BOOK_FROM`), so a pull request runs only the pages it changed; it never runs Python or R
(`BOOK_NO_PYTHON`, `BOOK_NO_R`: a page whose outputs are out of date fails, and says how to
update them). Every change to tabelline reruns every page, so a page that no longer works shows
up in the pull request that broke it. The Great Tables side ran with the version pinned in
`book/gt/uv.lock` (Great Tables 1.1.0), the R side with gt 1.4.0 (R 4.3).
"""

bookSave()
Made with tabelline, nimib and nimibook. The Nim code ran when this page was built; the Python ran with Great Tables 1.1.0 and the R with gt 1.4.0.