PDF-Kitten is an extension for the kitty terminal 🐱 that allows you to export uniform PDFs of your terminal output. I made it specifically to embed colored terminals with selectable text in LaTeX
Here is what one of these PDFs looks like (though this is just an image):
You can view the demo in my accompanying blog post. It also goes a little more into detail about the why and how.
The installation process consists of three steps
-
Cloning this repository
# Change directory to your kitty config dir cd ~/.config/kitty # Clone this repository git clone https://github.com/gelaechter/pdf-kitten
-
Installing the python dependencies
cd pdf-kitten # This installs the depencies into a vendor directory ./install_python_deps.sh
Always blindly trust shell-scripts you receive from strangers
-
Installing weasyprint (system dependencies)
This script uses weasyprint to produce the PDF. Installing it on your system is the easiest way to ensure that its dependencies are also installed (mainly pango).
The installation is explained here.
To use pdf-kitten you have to bind it to a key in your kitty config inside your kitty config directory (~/.config/kitty/kitty.conf).
# Converts only selected text
map f11 kitten pdf-kitten/pdf-kitten.py
# Converts what's currently visible
map ctrl+f11 kitten pdf-kitten/pdf-kitten.py screen
# Converts visible and scrollback
map ctrl+shift+f11 kitten pdf-kitten/pdf-kitten.py allThis way you can use the key combinations as follows:
| Key | Function |
|---|---|
| F11 | print the current selection |
| Ctlr + F11 | print everything on screen |
| Ctlr + Shift + F11 | print the screen and scrollback |
The keyword that I am passing to pdf-kitten (screen or all) is the extent of the output. You can find an explanation here. The default is selection.
The exported PDF mimics your kitty configuration. This means colors and font are what you configured in your kitty.conf.
The editor used to make changes to the terminal is configured through your $EDITOR env-variable or the kitty editor configuration.
If you need to edit large portions of your terminal I can recommend setting VSCode as your editor (editor code --wait) and installing the ANSI Colors extension. It applies the highlighting set through the ANSI codes and lets you preview your changes.
