JMM’s notes on

Inkscape

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.

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:

  1. Select (F1 mouse-1) the text block whose style you want to use then copy (Ctrl+C) it.
  2. Start a new block of text (T)
  3. 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:

  1. duplicate text (Ctrl+D)
  2. cut the new object (Ctrl+X)
  3. paste it under my mouse (Ctrl+V)
  4. edit as text (T)
  5. highlight all text (Ctrl+A)
  6. 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="&lt;Hyper&gt;t" />
  <bind
     gaction="app.object-set-attribute('style,')"
     keys="&lt;Hyper&gt;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:

Questions/Wishlist

Questions I have or features I’d like or might want to implement

Cool or fun features of Inkscape

Extensions

I haven’t really messed around too much with extensions, but here are some links for future reference:

Inkex is in Python, but extension can be written in any language (even shell script).