inkscape-figures

Inkscape figure manager
授权协议 MIT License
开发语言
所属分类 企业应用、 LaTeX排版系统
软件类型 开源软件
地区 不详
投 递 者 公孙国兴
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

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:

  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}"))
 相关资料
  • Inkscape 是开源的矢量图形编辑软件,与 Illustrator、Freehand、CorelDraw、Xara X 等软件很相似,它使用 W3C 标准的 Scalable Vector Graphics (SVG) 文件格式,支持包括形状、路径、文本、标记、克隆、alpha 混合、变换、渐变、图案、组合等 SVG 特性。它也支持创作共用的元数据、节点编辑、图层、复杂的路径运算、位图描摹、文

  • Inkscape shortcut manager A shortcut manager that speeds up drawing (mathematical) figures in Inkscape. Problem I write my lecture notes in LaTeX and I want to draw figures in real time, i.e. while th

相关阅读

相关文章

相关问答

相关文档