Script for managing inkscape figures
Project description
Inkscape figure manager.
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:
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:
- 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
. - Check if there exists a figure with the same name. If there exists one, do nothing; if not, go on.
- Copy the figure template to the directory containing the figures.
- In Vim: replace the current line – the line containing figure title – with the LaTeX code for including the figure.
- Open the newly created figure in Inkscape.
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file inkscape-1.3-figures-1.0.8.tar.gz
.
File metadata
- Download URL: inkscape-1.3-figures-1.0.8.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79f8d6a302e51067999f6b77368a0d5206680611a5d1923e31bb9035078530ef |
|
MD5 | 8e4e9859086524e4078e278ff044f3c1 |
|
BLAKE2b-256 | 77fdab253086e78dc57ebfb751cc7b4c12e06c7cefc08ce8766f40242a8bc384 |
File details
Details for the file inkscape_1.3_figures-1.0.8-py3-none-any.whl
.
File metadata
- Download URL: inkscape_1.3_figures-1.0.8-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da161460f5187cabe4f05b798101c39031ee870555064b7c51b00704b68cee35 |
|
MD5 | be1160382d60860921e8924181458d83 |
|
BLAKE2b-256 | c0ff4b8486e28dda9d38cdb1c5fe5808c786d71f90524a994b33aa0756172443 |