Jump to content

Quarto

From NixOS Wiki

Quarto is an open-source technical publishing system that allows you to render markdown and code chunks into technical documents. It supports several kinds of formats including HTML, PDF, and word documents.

The quarto package from nixpkgs by itself will render "qmd" markdown without any extra dependencies. However in order to render R, Python, or other code chunks, you will need to include those tools in your path. For example, consider the following "default.nix" file:

let
  pkgs = import <nixpkgs> { };
in
pkgs.mkShell {
  packages = with pkgs; [

    # The core tool can render markdown without any additional dependencies.
    quarto
    
    # Render python code chunks.
    python3
    rPackages.reticulate

    # Add Python packages as needed.
    # python3Packages.matplotlib
    
    # Render R Code chunks
    R

    # Add R Package as needed.
    # rPackages.httr
    
    # A LaTex distribution is needed to render PDF documents.
    # You may be able to use a smaller distribution or customize depending on your needs.
    texliveFull
  ];
}

This nix shell gives you the tools render markdown documents with different kinds of code chunks. The following snippet can be placed in a "main.qmd" file.

---
title: Quarto Document
---

## Section Title

A quarto document with bash, R and python code.

```{sh}
which R
which python
```

```{r}
plot(mpg ~ cyl, mtcars)
```

```{python}
import os
os.listdir()
```

You can render this document into various formats:

quarto render main.qmd --to html
quarto render main.qmd --to docx
quarto render main.qmd --to pdf

See more examples on the official quarto website. (https://quarto.org/)

Issue Rendering PDF Documents

No TeX installation was detected.

Please run 'quarto install tinytex' to install TinyTex.
If you prefer, you may install TexLive or another TeX distribution.

If you encounter this message while generating PDF documents, you need to add a LaTex distribution to your path (e.g. texLiveFull). If you use "quarto install tinytex", quarto will download a dynamically linked binary that is incompatible with nix. If you've previously run this command, you may need to remove it before rendering PDF documents works as intended.