Just some personal notes, or a cheatsheet, on using Inkscape.
Note for other people: I usually use Inkscape and Emacs in conjunction, and I’ve made my own (as-of-yet undocumented) library called jmm-inkscape.el
for using them together.
It basically relies on D-Bus communication, though Inkscape’s D-Bus interface recently was updated.
Some of the org.gtk.Actions
for Inkscape are located in src/actions/
.
Like here’s an example of actions defined in actions-selection.cpp
.
Links
- Inkscape’s official website is inkscape.org.
- Issues are tracked at gitlab.com/inkscape/inkscape/.
- A keyboard and mouse reference is at inkscape.org/doc/keys.html.
Some unofficial links I find useful.
- Logos by Nick has pretty good Inkscape tutorials. See Logos by Nick’s YouTube channel or his website, logosbynick.com.
- Learning how SVG works under the hood really helps with using Inkscape. Check out MDN’s reference on SVG for more about that.
- Tavmjong Bah has some good (but sometimes outdated) references on his site at http://tavmjong.free.fr/blog/.
Keyboard tips
Keyboard | Description. |
---|---|
Shift+Tab | Can be used to quickly select the last-created object (assuming it’s on top). More generally it cycles backward an object (compared to Tab). |
drag object+Control+C | Creates clones while dragging (in Inkscape 1.3) |
Control+Alt+D | Duplicate and transform (in Inkscape 1.3) |
You can see some of my saved keyboard shortcuts at /inkscape-keys.
Command line
See https://wiki.inkscape.org/wiki/Using_the_Command_Line.
Exporting a PNG
Here’s how you’d export a PNG with a white background and a width of 500px.
inkscape yourfile.svg --export-type=png --export-width=500 --export-background=white
It’ll make a file named yourfile.png by default.
SVG to PDF
Here’s how you’d export an SVG to a PDF:
inkscape --export-type=pdf --export-filename=output.pdf input.svg
Note the --export-type=pdf
isn’t actually necessary, but I think it ensures that the export-filename
has the right extension.
Tips
Editing defs or markers
Editing markers or symbols (which are in the <defs>
section) can be slightly annoying.
One tip is to replace a def’d ID with a <use>
element pointing to some group (e.g. <g>
), which you can then edit.
You may also be able to have the <use>
point to an external SVG.
(TODO: Show an example of this.)
Maintaining text style
I kind of don’t like Inkscape resets to some default style for entering text.
Though I think you can set it to remember a previous style (which is sometimes worse for me).
Edit from 2024-05-13: Actually, just set it to remember the previous style.
This is easier.
If you want to maintain a style, you might edit your ~/.config/inkscape/preferences.xml
(only edit when Inkscape is closed, otherwise it’ll overwrite it) and look for
<eventcontext id="text"and edit the
style
attribute.
Here’s the old workarounds:
If you want to start a new block of text, but have that block use another’s style, here’s what you can do:
- Select (F1 mouse-1) the text block whose style you want to use then copy (Ctrl+C) it.
- Start a new block of text (T)
- Paste the style (Ctrl+Shift+V)
However, this doesn’t seem to maintain the text alignment (e.g. if you wanted to make text centered) (tested on 2024-02-01 with Inkscape 1.3.2 (091e20ef0f, 2023-11-25)).
A second workaround which I use pretty often is to:
- duplicate text (Ctrl+D)
- cut the new object (Ctrl+X)
- paste it under my mouse (Ctrl+V)
- edit as text (T)
- highlight all text (Ctrl+A)
- and delete the highlighted selection (Backspace)
This does maintain text alignment, but it’s a hassle as well.
Another possibility would be to save your style into a class and then just set classes on objects.
Converting styles to classes is possible with the “Merge styles into CSS” builtin extension, but setting classes on objects is still a bit rough for me.
You can set classes with the “Selectors and CSS” toolbar (Shift+Ctrl+Q), but occasionally this has crashed.
Ideally I’d have several different hotkeys to toggle different classes.
To work around this, my jmm-inkscape-svg-mode
has a command to send some DBus commands to erase a style and set a class.
Hotkeys for setting classes and clearing styles
Okay, I’ve kind of figured out a way of clearing styles and setting a class using hotkeys.
You can use the gaction
app.object-set-attribute('attribute,value')
to set (but not seemingly completely remove) XML attributes.
So you can set style
to an empty string and class to some class you want.
You can then bind these to hotkeys like:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<keys name="User Shortcuts">
<bind
gaction="app.object-set-attribute('class,test')"
keys="<Hyper>t" />
<bind
gaction="app.object-set-attribute('style,')"
keys="<Hyper>s" />
</keys>
In this example, Hyper+t sets the class
to “test
” and Hyper+s sets the style
attribute to be an empty string.
You’d import this file in your keyboard preferences.
Take note that this doesn’t seem to survive being re-exported.
Command palette
You can pop up the command palette by pressing ?. Say you selected two objects and then hit ? then searched for align. Select the “Align Objects” option. You’ll see the search icon at the left of the text input turns to a keyboard icon. This is where you can enter in arguments. Like you can put “vcenter last” to vertically align the center to the last selected object.
Also, I’m not sure where the documentation for the command palette is, so here’s what I’ve discovered from command-palette.cpp
:
- Press the up key to use history (not sure how to use parameter history, though it seems saved).
- Hitting Escape or ? (not configurable) will exit the command palette.
Issues
Some issues I’ve run into with Inkscape:
-
In the “Selectors and CSS” toolbar, unchecking a checkbox of a class’s rule can cause Inkscape to crash. This occurred on 2024-02-01 with Inkscape 1.3.2 (091e20ef0f, 2023-11-25) on NixOS.
-
In some situations, when Inkscape parses CSS but doesn’t understand newer CSS rules or syntax, it can overwrite inline stylesheets. (TODO: I need to show an example of this.) One way I’ve worked around this is to use an
@import
rule to point to a separate file that contains more complicated CSS. This isn’t ideal, though, since such imported styles aren’t allowed in SVG-as-image-elements in HTML (since no external resources are fetched for security reasons). It’s been a few months since I’ve tested this, though. -
For some reason, trying to export SVGs in Inkscape 1.2.1 with NixOS 22.11 in GNOME causes Inkscape to crash. What’s weirder is that it actually does successfully export a PNG, but seemingly crashes after that. This seems to happen with GNOME specifically, and not when I’m running under Sway.
The error looks like the following:
Emergency save activated! Emergency save completed. Inkscape will close now. If you can reproduce this crash, please file a bug at https://inkscape.org/report with a detailed description of the steps leading to the crash, so we can fix it. ** Message: 12:00:00.000: Error: Inkscape encountered an internal error and will close now.
(This error was seen on 2023-09-18)
-
Inkscape can take sometimes hang on startup for me. I think this was caused by Inkscape trying to load previews of all installed fonts. This issue is tracked at https://gitlab.com/inkscape/inkscape/-/issues/841.
I think the workaround I used for it was to close a fonts dialog, or maybe there was another preference I set so it doesn’t try to preview fonts.
Questions/Wishlist
Questions I have or features I’d like or might want to implement
-
I’d like to be able to easily erase styles and set CSS classes for objects, ideally with a keybinding or toolbar.
The “Selectors and CSS” (Shift+Ctrl+Q) does most of this, but you need to individually trash styles and apply classes by clicking.
- Is it possible to bind a key to just run a command? That way I could make a keybinding running a script that uses D-Bus to both clear the selection’s style and then set the object’s class to some value. This may be possible with Extensions, but I’m not yet super familiar with them.
Cool or fun features of Inkscape
-
Inkscape supports mesh gradients, which are a feature proposed for SVG 2 (though unclear if SVG 2 will ever happen now).
Extensions
I haven’t really messed around too much with extensions, but here are some links for future reference:
- Inkex and other extensions are located at https://gitlab.com/inkscape/extensions/
- Documentation for inkex is at https://inkscape.gitlab.io/extensions/documentation/
Inkex is in Python, but extension can be written in any language (even shell script).