管理Inkscape图形的脚本
inkscape-figures的Python项目详细描述
Inkscape图形管理器。
我用来管理乳胶文档的图形的脚本。 更多信息请参见blog post。
安装
您可以使用pip安装它:
pip install inkscape-figures
你还需要rofi。
此脚本仅适用于Linux。如果您对将其移植到windows/osx感兴趣,请随时提出请求。
设置
在LaTex文档的前言中添加以下代码。
\usepackage{import}\usepackage{pdfpages}\usepackage{transparent}\usepackage{xcolor}\newcommand{\incfig}[1]{%\def\svgwidth{\columnwidth}\import{./figures/}{#1.pdf_tex}}\pdfsuppresswarningpagegroup=1
这假定以下目录结构:
master.tex
figures/
figure1.pdf_tex
figure1.svg
figure1.pdf
figure2.pdf_tex
figure2.svg
figure2.pdf
用法
- 注意数字:
inkscape-figures watch
。 - 创建图形:
inkscape-figures create 'title'
。它使用~/.config/inkscape-figures/template.svg
作为模板。 - 在特定目录中创建图形:
inkscape-figures create 'title' path/to/figures/
。 - 选择图并编辑它:
inkscape-figures edit
。 - 在特定目录中选择图并编辑它:
inkscape-figures edit path/to/figures/
。
VIM映射
这假设您使用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>
现在,要添加图形,请在新行键入标题,然后在插入模式下按ctrl+f。 执行以下操作:
- 使用
b:vimtex.root
查找保存图形的目录,具体取决于要编辑的文件和主乳胶文件的位置。 - 将地物模板复制到包含地物的目录中。
- 在vim中:用包含图形的乳胶代码替换当前行(包含图形标题的行)。
- 在Inkscape中打开新创建的图形。
- 设置一个文件观察程序,这样每当通过按ctrl+s将图形保存为svg文件时,它也将保存为pdf+latex。
要编辑图形,请在命令模式下按ctrl+f,将弹出一个模糊搜索选择对话框,允许您选择要编辑的图形。
配置
您可以通过创建~/.config/inkscape-figures/config.py
并在以下行中添加一些内容来更改默认乳胶模板:
deflatex_template(name,title):return'\n'.join((r"\begin{figure}[ht]",r" This is a custom LaTeX template!",r" \centering",rf" \incfig{{{name}}}",rf" \caption{{{title}}}",rf" \label{{fig:{name}}}",r"\end{figure}"))