Quarto: Difference between revisions
mNo edit summary |
add necessary patch, add flake and configuration.nix examples, verified they work. |
||
| Line 1: | Line 1: | ||
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. | 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 | The quarto package from nixpkgs by itself will render <code>qmd</code> markdown without any extra requirements. However in order to render R, Python, or other code chunks, you will need to include those tools. | ||
You can use the following in your system's <code>configuration.nix</code> file:<syntaxhighlight lang="nix">environment.systemPackages = let | |||
myPythonPackages = ps: with ps; [ | |||
pandas | |||
statsmodels | |||
scikit-learn | |||
sympy | |||
]; | |||
myRPackages = with pkgs.rPackages; [ | |||
reticulate # wanted by quarto to execute Python when using R. | |||
# any other RPackages - you can reuse this list for R and RStudio | |||
] | |||
patchedQuarto = (pkgs.quarto.override { | |||
extraPythonPackages = myPythonPackages; | |||
extraRPackages = myRPackages; | |||
}).overrideAttrs (oldAttrs: { # Remove this overrideAttrs patch when fixed. See https://github.com/NixOS/nixpkgs/issues/519484#issuecomment-4667477454 | |||
postPatch = (oldAttrs.postPatch or "") + '' | |||
substituteInPlace bin/quarto.js \ | |||
--replace-fail "syntax-highlighting" "highlight-style" | |||
''; | |||
}); | |||
in with pkgs; [ | |||
#### next generation of Rmarkdown for Python, Julia, R, and JS: | |||
patchedQuarto | |||
#### Your command-line Python: | |||
(python3.withPackages (myPythonPackages)) | |||
#### R and RStudio: | |||
(rWrapper.override {packages = myRPackages; }) | |||
(rstudioWrapper.override { packages = myRPackages; }) | |||
];</syntaxhighlight>similarly a `flake.nix` file with `nix develop`:<syntaxhighlight lang="nix"> | |||
{ | |||
description = "Minimal Quarto and SymPy environment"; | |||
inputs = { | |||
nixpkgs.url = "github:Nixos/nixpkgs/nixos-unstable"; | |||
}; | |||
outputs = { self, nixpkgs }: | |||
let | |||
system = "x86_64-linux"; | |||
pkgs = nixpkgs.legacyPackages.${system}; | |||
myPythonPackages = ps: with ps; [ sympy ]; | |||
myRPackages = with pkgs.rPackages; [ reticulate ]; | |||
pythonEnv = pkgs.python3.withPackages (myPythonPackages); | |||
in | |||
{ | |||
devShells.${system}.default = pkgs.mkShell { | |||
packages = [ | |||
((pkgs.quarto.override { | |||
extraPythonPackages = myPythonPackages; | |||
extraRPackages = myRPackages; | |||
}).overrideAttrs (oldAttrs: { | |||
# Remove this overrideAttrs patch when fixed. | |||
# See https://github.com/NixOS/nixpkgs/issues/519484#issuecomment-4667477454 | |||
postPatch = (oldAttrs.postPatch or "") + '' | |||
substituteInPlace bin/quarto.js \ | |||
--replace-fail "syntax-highlighting" "highlight-style" | |||
''; | |||
})) | |||
pythonEnv | |||
(pkgs.rWrapper.override {packages = myRPackages; }) | |||
]; | |||
shellHook = '' | |||
echo "Quarto Environment Active (Pure Flake)" | |||
echo "Quickstart: run 'quarto render document.qmd'" | |||
''; | |||
}; | |||
}; | |||
} | |||
</syntaxhighlight>Or you can use the following <code>default.nix</code> or <code>shell.nix</code> file with <code>nix-shell</code> (and you don't have to pass in your Python packages via <code>override</code>): | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
| Line 10: | Line 78: | ||
packages = with pkgs; [ | packages = with pkgs; [ | ||
# The core tool can render markdown without any additional | #### The core tool can render markdown without any additional requirements: | ||
quarto | # quarto # commenting until this is fixed in nixpkgs - until then use below patch, | ||
#### see https://github.com/NixOS/nixpkgs/issues/519484#issuecomment-4667477454 | |||
(quarto.overrideAttrs (oldAttrs: { | |||
postPatch = (oldAttrs.postPatch or "") + '' | |||
substituteInPlace bin/quarto.js \ | |||
--replace-fail "syntax-highlighting" "highlight-style" | |||
''; | |||
})) | |||
# Render python code chunks. | # Render python code chunks. | ||
| Line 34: | Line 109: | ||
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. | 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. | ||
<syntaxhighlight> | <syntaxhighlight>--- | ||
--- | |||
title: Quarto Document | title: Quarto Document | ||
--- | --- | ||
| Line 55: | Line 129: | ||
import os | import os | ||
os.listdir() | os.listdir() | ||
``` | ```</syntaxhighlight> | ||
</syntaxhighlight> | |||
You can render this document into various formats: | You can render this document into various formats: | ||