#figures #figure #operating-system #svg #command-line-tool #cli #inkscape

app inkscape-figures-manager

A tool to manage figures in Inkscape, and create technical figures fast with shortcuts

2 unstable releases

0.2.0 Sep 16, 2024
0.1.0 Feb 26, 2024

#941 in Command line utilities

Download history 160/week @ 2024-09-12 32/week @ 2024-09-19 9/week @ 2024-09-26 1/week @ 2024-10-03

66 downloads per month

MIT license

28KB
483 lines

Inkscape Figures Manager

A simple CLI tool to manage figures in created with Inkscape. It also provides shortcuts for common operations when creating technical figures that have the style of TikZ figures. This crate is heavily inspired by Gilles Castel's Inkscape figures manager and Inkscape shortcut manager. The reason for creating this crate is that his tools only support Linux. This crate is written to be used in macOS (but could easily be extended to work for other operating systems).

Installation

cargo install inkscape-figures-manager

Then, create a template SVG file $HOME/.config/ifm/template.svg. This file will be used as a template when creating new figures. I recommend pinning commonly used colors and setting the dimensions. The dimensions should be set to be equal to the dimensions of your LaTeX document, which can be set using the geometry package. An example template is template.svg in this repository.

Usage

inkscape-figures-manager start
inkscape-figures-manager list
inkscape-figures-manager new <path>
inkscape-figures-manager edit <path>

list lists all SVG files in all subdirectories from where the command is run. This can be used by a picker to select a figure to edit. I recommend using a picker to quickly open figures from within a project. You can use a picker tool such as choose. I use telescope.nvim in my Neovim setup; see my config for the extension I made for telescope (copy the lua/telescope/ and lua/telescope_inkscape_figures/ directories).

new creates a new figure with the specified path, and opens it. This command requires a template SVG file in $HOME/.config/ifm/template.svg, so make sure to create one. In a Neovim setup, you can use the following keymap to create new figures with Ctrl+F,

vim.keymap.set(
    "i",
    "<C-f>",
    "<Esc><cmd>exec 'r!inkscape-figures-manager new -f -d figures -l \"'.getline('.').'\"'<CR>kkkkkkddjjjf{a"
)

edit opens the inkscape for a specified path. This command will error if the path does not exist, or if the file is not an SVG.

File watcher

You can start the file watcher and the shortcut listener by executing the following command,

inkscape-figures-manager start

This command does two things:

  1. Whenever an SVG is saved in any subdirectory where the command was executed, it will compile it as a PDF to be used in LaTeX;
  2. It listens for keyboard shortcuts, as defined in the next section.

Keyboard shortcuts

To apply a style to an Inkscape object, select the object and hold Alt/Option. While holding Alt, press the keys as defined below. It will remove all the current styles of the object and put the style as specified.

Style (KEY)
Stroke width: Normal (1) Thick (2) Very thick (3)
Stroke: Solid (Q) Dashed (W) Dotted (E)
Fill White (A) Gray (S) Black (D)
Arrow Start (Z) End (X) --

[!IMPORTANT] On macOS, the shortcuts require you to give accessibility permissions to the terminal that you are running the command in.

[!WARNING] The program grabs all keyboard interactions while Alt/Option is held. So, no other shortcuts involving Alt/Option will be triggered while it is running.

![NOTE] The defined keyboard shortcuts have no semantic meaning, but are defined to be easily reachable with only the left hand on a US keyboard.

Creating Figures

For an example of the figures that can be created, see my university notes repository. Alternatively, see Gilles Castel's master thesis, which contains over 100 figures.

For colors, you can use one of the qualitative color sets defined by colorbrewer.

For advice on how to create good figures, see the TikZ guidelines.

Operating System Support

At the moment, this crate only supports macOS. It can easily be extended to support other operating systems by providing a clipboard implementation for the specific operating system (see src/clipboard). If this is something you are interested in, open an issue or create a pull request.

Alternatively, if you want to use a crate like this one on Linux, see Gilles Castel's Inkscape figures manager.

Dependencies

~3–14MB
~125K SLoC