Skip to main content

Script for managing inkscape figures using fuzzel on Wayland

Project description

Inkscape figure manager.

NOTE: This is a fork of inkscape-figures by Gilles Castel, which simply seeks to replace the picker app rofi with fuzzel. This is for my own personal use and while you're welcome to use it freely, there is no guarantee of it functioning properly and in the same way as the original version. I'll seek to update the documentation of changes from the base tool when possible. Changes have been made to the get_picker_cmd() within the inkscape-figures/picker.py file. The following is from the original repository's README.md:

A script I use to manage figures for my LaTeX documents. More information in this blog post.

Requirements

You need Python >= 3.7, as well as a picker. Current supported pickers are:

  • rofi on Linux systems (replace this with fuzzel)
  • choose on MacOS

Installation

You can install it using pip:

pip3 install inkscape-figures

This package currently works on Linux and MacOS. If you're interested in porting it to Windows, feel free to make a pull request.

Setup

Add the following code to the preamble of your LateX document.

\usepackage{import}
\usepackage{pdfpages}
\usepackage{transparent}
\usepackage{xcolor}

\newcommand{\incfig}[2][1]{%
    \def\svgwidth{#1\columnwidth}
    \import{./figures/}{#2.pdf_tex}
}

\pdfsuppresswarningpagegroup=1

This defines a command \incfig which can be used to include Inkscape figures. By default, \incfig{figure-name} make the figure as wide as the page, but it's also possible to change the width by providing an optional argument: \incfig[0.3]{figure-name}.

The settings above assume the following directory structure:

master.tex
figures/
    figure1.pdf_tex
    figure1.svg
    figure1.pdf
    figure2.pdf_tex
    figure2.svg
    figure2.pdf

Usage

  • Watch for figures: inkscape-figures watch.
  • Creating a figure: inkscape-figures create 'title'. This uses ~/.config/inkscape-figures/template.svg as a template.
  • Creating a figure in a specific directory: inkscape-figures create 'title' path/to/figures/.
  • Select figure and edit it: inkscape-figures edit.
  • Select figure in a specific directory and edit it: inkscape-figures edit path/to/figures/.

Vim mappings

This assumes that you use VimTeX.

inoremap <C-f> <Esc>: silent exec '.!inkscape-figures create "'.getline('.').'" "'.b:vimtex.root.'/figures/"'<CR><CR>:w<CR>
nnoremap <C-f> : silent exec '!inkscape-figures edit "'.b:vimtex.root.'/figures/" > /dev/null 2>&1 &'<CR><CR>:redraw!<CR>

First, run inkscape-figures watch in a terminal to setup the file watcher. Now, to add a figure, type the title on a new line, and press Ctrl+F in insert mode. This does the following:

  1. Find the directory where figures should be saved depending on which file you're editing and where the main LaTeX file is located, using b:vimtex.root.
  2. Check if there exists a figure with the same name. If there exists one, do nothing; if not, go on.
  3. Copy the figure template to the directory containing the figures.
  4. In Vim: replace the current line – the line containing figure title – with the LaTeX code for including the figure.
  5. Open the newly created figure in Inkscape.
  6. Set up a file watcher such that whenever the figure is saved as an svg file by pressing Ctrl + S, it also gets saved as pdf+LaTeX.

To edit figures, press Ctrl+F in command mode, and a fuzzy search selection dialog will popup allowing you to select the figure you want to edit.

Configuration

You can change the default LaTeX template by creating ~/.config/inkscape-figures/config.py and adding something along the lines of the following:

def latex_template(name, title):
    return '\n'.join((r"\begin{figure}[ht]",
                      r"    This is a custom LaTeX template!",
                      r"    \centering",
                      rf"    \incfig[1]{{{name}}}",
                      rf"    \caption{{{title}}}",
                      rf"    \label{{fig:{name}}}",
                      r"\end{figure}"))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inkscape_figures_fuzzel-1.0.7.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

inkscape_figures_fuzzel-1.0.7.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file inkscape_figures_fuzzel-1.0.7.1.tar.gz.

File metadata

File hashes

Hashes for inkscape_figures_fuzzel-1.0.7.1.tar.gz
Algorithm Hash digest
SHA256 ad70007290c7bcc3e56c428ceca699fd0fb45d94db0dc9b0a2fe0085c9f5a468
MD5 4893bb6f046b25de204283012d98dfbd
BLAKE2b-256 df20f1f6d005d3d148f19dfff6a3e4dc9cf5f0172673bbd7c57cabb50947a0bb

See more details on using hashes here.

File details

Details for the file inkscape_figures_fuzzel-1.0.7.1-py3-none-any.whl.

File metadata

File hashes

Hashes for inkscape_figures_fuzzel-1.0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 793f36466f2b06a648607c9a213636e4e42a8666b4cb38214111a59e6a053bc6
MD5 03361ceb8f2705603346c7576ffc885c
BLAKE2b-256 c183b028ee5c81554f136fee926026b0431da47a7c608419deaba312b7723e21

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page