A script I use to manage figures for my LaTeX documents. More information in this blog post.
You need Python >= 3.7, as well as a picker. Current supported pickers are:
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.
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
inkscape-figures watch
.inkscape-figures create 'title'
. This uses ~/.config/inkscape-figures/template.svg
as a template.inkscape-figures create 'title' path/to/figures/
.inkscape-figures edit
.inkscape-figures edit path/to/figures/
.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:
b:vimtex.root
.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.
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}"))