# For authors

tomes reads the HTML that Quarto makes for books and websites, so most books work as they are. A few things make them work better.


# What tomes understands

- Books and websites, with the outline from Quarto's sidebar (parts too)
- Headings with their numbers, callouts (also collapsed ones), block quotes, lists, definition lists, figures with captions, tables, tabsets
- Cross-references, footnotes, citations (as footnotes), links
- Code with Pandoc's syntax highlighting, mapped to the 16 terminal colors
- Terminal sessions made with [quarto-term](https://quarto-term.jeroenjanssens.com), with their colors, prompts, and callouts, and its palettes
- Images: PNG, JPEG, GIF, WebP, and SVG

Math is shown as its TeX source. Interactive widgets, videos, and Mermaid diagrams that are drawn in the browser are replaced by a note.


# Tips

- **Set `site-url`** in `_quarto.yml`: `gx` then opens the section on your website.
- **Give figures alt text and captions**: tomes shows the caption under the image, and the alt text when it can't show the image.
- **Keep code within 80 columns**: wider code scrolls sideways.
- **Use quarto-term for terminal sessions**: they keep their colors, and `yc` copies just the commands.


# Your book in a program of its own

tomes is also a Rust library. A program of a few lines builds your book in, opens it right away (also offline), and can bring the book's data and Docker image. [dsatcl](https://github.com/jeroenjanssens/data-science-at-the-command-line/tree/main/dsatcl) does that for *Data Science at the Command Line*:

``` rust
fn files(path: &str) -> Option<std::borrow::Cow<'static, [u8]>> {
    Book::get(path).map(|f| f.data) // rust-embed
}

fn main() {
    tomes::main(tomes::Profile {
        name: "mybook",
        version: env!("CARGO_PKG_VERSION"),
        about: "Read My Book in your terminal",
        examples: "",
        companion: Some(tomes::Companion {
            key: "mybook",
            url: "https://mybook.example.com/",
            files,
            data_url: None,
            docker_image: None,
            toolbox_env: None,
        }),
    });
}
```

Build it with maturin's `bindings = "bin"` to put it on PyPI, so readers can run `uvx mybook`.
